add an admin "interface" to delete quotes

This commit is contained in:
fzorb 2024-10-04 20:59:56 +03:00
parent 22a226402c
commit 40f121541c
3 changed files with 21 additions and 2 deletions

View File

@ -1,5 +1,6 @@
TOKEN= TOKEN=
CLIENT_ID= CLIENT_ID=
PREFIX=; PREFIX=;
ADMIN=
FORBIDDEN_WORDS=word1,word2 FORBIDDEN_WORDS=word1,word2

6
bot.rb
View File

@ -23,8 +23,10 @@ bot.command :help do |event, *message|
nil nil
end end
require_relative 'systems/quote' # stolen from https://github.com/Suylo/Discord-Bot/blob/master/index.rb
require_relative 'systems/network' systems = Dir["systems/*.rb"]
systems.each { |i| require_relative "#{i}" }
bot.include! QuoteSystem bot.include! QuoteSystem
bot.include! NetworkModule bot.include! NetworkModule
bot.run bot.run

View File

@ -1,5 +1,9 @@
require 'dotenv'
require 'sqlite3' require 'sqlite3'
require 'discordrb' require 'discordrb'
Dotenv.load("#{__dir__}/../.env")
module QuoteSystem module QuoteSystem
extend Discordrb::Commands::CommandContainer extend Discordrb::Commands::CommandContainer
db = SQLite3::Database.new("jon.sqlite") 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]}") event.channel.send_message("##{quote[0][0]} <#{quote[0][2]}>: #{quote[0][3]}")
nil nil
end 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 end