Updated user blacklist to a button. Added donation command.
This commit is contained in:
@@ -17,17 +17,19 @@
|
||||
require 'discordrb'
|
||||
require 'securerandom'
|
||||
require_relative 'events/message_check'
|
||||
require_relative 'events/button_handler'
|
||||
|
||||
class CheeseBot
|
||||
def initialize
|
||||
puts "Initializing bot..."
|
||||
@bot = Discordrb::Bot.new(
|
||||
token: ENV['BOT_TOKEN'],
|
||||
intents: [:server_messages],
|
||||
intents: [:server_messages]
|
||||
)
|
||||
|
||||
puts "Registering the Message Checker..."
|
||||
puts "Registering the Message Checker and Button Handler..."
|
||||
MessageCheck.register(@bot)
|
||||
ButtonHandler.register(@bot)
|
||||
|
||||
puts "Initializing database..."
|
||||
Database.setup
|
||||
|
||||
@@ -21,21 +21,6 @@ module Commands
|
||||
extend self
|
||||
|
||||
def register(bot)
|
||||
cmd_key = :blacklist
|
||||
cmd_desc = "Blacklist yourself from the trigger DMs (using the command again will whitelist you.)"
|
||||
|
||||
bot.register_application_command(cmd_key, cmd_desc, server_id: ENV['SERVER_ID'])
|
||||
|
||||
bot.application_command(cmd_key) do |event|
|
||||
added = Database.toggle_user_blacklist(event.user.id)
|
||||
|
||||
if added
|
||||
event.respond(content: "You have been added to the blacklist. You will no longer receive DMs.")
|
||||
else
|
||||
event.respond(content: "You have been removed from the blacklist. You will now receive DMs.")
|
||||
end
|
||||
end
|
||||
|
||||
cmd_key_server = :server_blacklist
|
||||
cmd_desc_server = "Blacklist the server from the trigger DMs (using the command again will whitelist the server.)"
|
||||
|
||||
|
||||
32
src/commands/not_cheese_related/donation.rb
Normal file
32
src/commands/not_cheese_related/donation.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
# cheeseBot
|
||||
# Copyright (C) 2026 Eri (csxkdv/nxkdv) nxkdv@thenight.club
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
module Commands
|
||||
module Donation
|
||||
extend self
|
||||
|
||||
def register(bot)
|
||||
cmd_key = :donation
|
||||
cmd_desc = "Only if you can and want, of course."
|
||||
|
||||
bot.register_application_command(cmd_key, cmd_desc, server_id: ENV['SERVER_ID'])
|
||||
|
||||
bot.application_command(cmd_key) do |event|
|
||||
event.respond(content:"[Donate a ko-fi](https://ko-fi.com/reicore) to my creator if you can, and want.")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
31
src/events/button_handler.rb
Normal file
31
src/events/button_handler.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# cheeseBot
|
||||
# Copyright (C) 2026 Eri (csxkdv/nxkdv) nxkdv@thenight.club
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
require_relative '../modules/database'
|
||||
|
||||
module ButtonHandler
|
||||
def self.register(bot)
|
||||
bot.button(custom_id: 'toggle_cheese_blacklist') do |event|
|
||||
added = Database.toggle_user_blacklist(event.user.id)
|
||||
|
||||
if added
|
||||
event.respond(content: "You have been added to the blacklist. You will no longer receive DMs.\n(Click this button again anytime to re-enable them.)", ephemeral: true)
|
||||
else
|
||||
event.respond(content: "You have been removed from the blacklist. You will now receive DMs.", ephemeral: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -14,6 +14,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
require 'securerandom'
|
||||
require_relative '../modules/cheese_checker'
|
||||
require_relative '../modules/database'
|
||||
|
||||
@@ -27,21 +28,39 @@ module MessageCheck
|
||||
|
||||
event.message.react("🧀")
|
||||
|
||||
next if Database.server_blacklisted?(event.server.id)
|
||||
next if Database.user_blacklisted?(event.user.id)
|
||||
if Database.server_blacklisted?(event.server.id)
|
||||
puts "[DEBUG] Ignored: Server #{event.server.name} is blacklisted."
|
||||
next
|
||||
end
|
||||
|
||||
if Database.user_blacklisted?(event.user.id)
|
||||
puts "[DEBUG] Ignored: User #{event.user.id} is blacklisted."
|
||||
next
|
||||
end
|
||||
|
||||
begin
|
||||
event.user.pm.send_embed do |embed|
|
||||
embed.title = "Cheese Detected!"
|
||||
embed.description = cheese_content
|
||||
|
||||
embed.color = rand(0xFFFFFF)
|
||||
embed.timestamp = Time.now
|
||||
|
||||
embed.footer = Discordrb::Webhooks::EmbedFooter.new(
|
||||
text: "Use /blacklist to not receive DMs anymore"
|
||||
view = Discordrb::Webhooks::View.new
|
||||
view.row do |r|
|
||||
r.button(
|
||||
label: "Toggle Blacklist",
|
||||
style: :secondary,
|
||||
custom_id: "toggle_cheese_blacklist"
|
||||
)
|
||||
end
|
||||
|
||||
random_color = ("0x" + Random.bytes(3).unpack1('H*')).to_i(16)
|
||||
author = event.user
|
||||
|
||||
embed_generated = {
|
||||
title: "Cheese detected!",
|
||||
description: cheese_content,
|
||||
color: random_color,
|
||||
timestamp: Time.now.iso8601,
|
||||
footer: { text: "Click the button to stop these messages." }
|
||||
}
|
||||
|
||||
# send_message(content, tts, embed, attachments, allowed_mentions, message_reference, components)
|
||||
event.user.pm.send_message(nil, false, [embed_generated], nil, nil, nil, view)
|
||||
rescue Discordrb::Errors::NoPermission
|
||||
puts "Could not DM user #{event.user.username} (#{event.user.id})"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user