Updated user blacklist to a button. Added donation command.

This commit is contained in:
2026-01-12 17:11:03 -03:00
parent 29e6093714
commit 0e91353e37
5 changed files with 97 additions and 28 deletions

View File

@@ -17,17 +17,19 @@
require 'discordrb' require 'discordrb'
require 'securerandom' require 'securerandom'
require_relative 'events/message_check' require_relative 'events/message_check'
require_relative 'events/button_handler'
class CheeseBot class CheeseBot
def initialize def initialize
puts "Initializing bot..." puts "Initializing bot..."
@bot = Discordrb::Bot.new( @bot = Discordrb::Bot.new(
token: ENV['BOT_TOKEN'], 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) MessageCheck.register(@bot)
ButtonHandler.register(@bot)
puts "Initializing database..." puts "Initializing database..."
Database.setup Database.setup

View File

@@ -21,21 +21,6 @@ module Commands
extend self extend self
def register(bot) 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_key_server = :server_blacklist
cmd_desc_server = "Blacklist the server from the trigger DMs (using the command again will whitelist the server.)" cmd_desc_server = "Blacklist the server from the trigger DMs (using the command again will whitelist the server.)"

View 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

View 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

View File

@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
require 'securerandom'
require_relative '../modules/cheese_checker' require_relative '../modules/cheese_checker'
require_relative '../modules/database' require_relative '../modules/database'
@@ -27,21 +28,39 @@ module MessageCheck
event.message.react("🧀") event.message.react("🧀")
next if Database.server_blacklisted?(event.server.id) if Database.server_blacklisted?(event.server.id)
next if Database.user_blacklisted?(event.user.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 begin
event.user.pm.send_embed do |embed| view = Discordrb::Webhooks::View.new
embed.title = "Cheese Detected!" view.row do |r|
embed.description = cheese_content r.button(
label: "Toggle Blacklist",
embed.color = rand(0xFFFFFF) style: :secondary,
embed.timestamp = Time.now custom_id: "toggle_cheese_blacklist"
embed.footer = Discordrb::Webhooks::EmbedFooter.new(
text: "Use /blacklist to not receive DMs anymore"
) )
end 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 rescue Discordrb::Errors::NoPermission
puts "Could not DM user #{event.user.username} (#{event.user.id})" puts "Could not DM user #{event.user.username} (#{event.user.id})"
end end