From 40f121541c3a37725cb59cc0331b2953c228980c Mon Sep 17 00:00:00 2001 From: fzorb Date: Fri, 4 Oct 2024 20:59:56 +0300 Subject: [PATCH] add an admin "interface" to delete quotes --- .env.example | 1 + bot.rb | 6 ++++-- systems/quote.rb | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 5e584ae..03baf6c 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ TOKEN= CLIENT_ID= PREFIX=; +ADMIN= FORBIDDEN_WORDS=word1,word2 diff --git a/bot.rb b/bot.rb index b1d6be0..452bbe0 100644 --- a/bot.rb +++ b/bot.rb @@ -23,8 +23,10 @@ bot.command :help do |event, *message| nil end -require_relative 'systems/quote' -require_relative 'systems/network' +# stolen from https://github.com/Suylo/Discord-Bot/blob/master/index.rb +systems = Dir["systems/*.rb"] +systems.each { |i| require_relative "#{i}" } + bot.include! QuoteSystem bot.include! NetworkModule bot.run diff --git a/systems/quote.rb b/systems/quote.rb index b9095ed..950226a 100644 --- a/systems/quote.rb +++ b/systems/quote.rb @@ -1,5 +1,9 @@ +require 'dotenv' require 'sqlite3' require 'discordrb' + +Dotenv.load("#{__dir__}/../.env") + module QuoteSystem extend Discordrb::Commands::CommandContainer db = SQLite3::Database.new("jon.sqlite") @@ -46,4 +50,16 @@ module QuoteSystem event.channel.send_message("##{quote[0][0]} <#{quote[0][2]}>: #{quote[0][3]}") nil end + + command :delquote do |event, *message| + if event.author.id != ENV['ADMIN'].to_i + event.channel.send_message("You really thought you could do this?") + return + end + for quote in message do + db.execute('DELETE FROM quotes WHERE "id"=?;', [quote]) + end + event.channel.send_message("Job complete.") + nil + end end \ No newline at end of file