2024-10-04 20:59:56 +03:00
|
|
|
require 'dotenv'
|
2024-10-04 09:09:06 +03:00
|
|
|
require 'sqlite3'
|
|
|
|
require 'discordrb'
|
2024-10-04 20:59:56 +03:00
|
|
|
|
|
|
|
Dotenv.load("#{__dir__}/../.env")
|
|
|
|
|
2024-10-04 09:09:06 +03:00
|
|
|
module QuoteSystem
|
|
|
|
extend Discordrb::Commands::CommandContainer
|
|
|
|
db = SQLite3::Database.new("jon.sqlite")
|
2024-10-21 14:20:11 +03:00
|
|
|
command(:quoteadd, aliases: [:addquote, :qa]) do |event, *message|
|
2024-10-04 09:09:06 +03:00
|
|
|
if message[0] == nil
|
|
|
|
event.channel.send_message("You haven't specified a category for your quote.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if message[1] == nil
|
|
|
|
event.channel.send_message("I can't quote air!")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
category = message[0]
|
|
|
|
quote = message[1..].join(" ")
|
|
|
|
event.channel.send_message("I'm adding the quote '#{quote}' under the category #{category}")
|
2024-10-05 08:06:45 +03:00
|
|
|
db.execute("INSERT INTO quotes (author, category, quote) VALUES (?, ?, ?)", [event.author.id, category.downcase, quote])
|
2024-10-04 09:09:06 +03:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2024-10-21 14:20:11 +03:00
|
|
|
command(:quote, aliases: [:q]) do |event, *message|
|
2024-10-05 08:45:43 +03:00
|
|
|
category = message[0]
|
2024-10-04 09:09:06 +03:00
|
|
|
if category == nil
|
2024-10-05 07:51:20 +03:00
|
|
|
quotes = db.execute("SELECT * FROM quotes")
|
|
|
|
quote = quotes.sample
|
|
|
|
event.channel.send_message("##{quote[0]} <#{quote[2]}>: #{quote[3]}")
|
|
|
|
else
|
2024-10-05 08:45:43 +03:00
|
|
|
category = category.downcase
|
2024-10-05 07:51:20 +03:00
|
|
|
quotes = db.execute("SELECT * FROM quotes WHERE category = ?", [category])
|
2024-10-05 08:16:11 +03:00
|
|
|
if quotes == []
|
2024-10-05 08:14:26 +03:00
|
|
|
event.channel.send_message("Uh, this is awkward. The category you're trying to get a quote from doesn't exist.")
|
2024-10-05 08:16:11 +03:00
|
|
|
else
|
|
|
|
quote = quotes.sample
|
|
|
|
event.channel.send_message("##{quote[0]}: #{quote[3]}")
|
2024-10-05 08:14:26 +03:00
|
|
|
end
|
2024-10-04 09:09:06 +03:00
|
|
|
end
|
2024-10-05 08:14:26 +03:00
|
|
|
nil
|
2024-10-04 09:09:06 +03:00
|
|
|
end
|
|
|
|
|
2024-10-21 14:20:11 +03:00
|
|
|
command(:quotecategories, aliases: [:qc]) do |event, *message|
|
2024-10-22 11:11:42 +03:00
|
|
|
categories = db.execute("SELECT category FROM quotes GROUP BY category ORDER BY COUNT(*) DESC;")
|
2024-10-04 09:09:06 +03:00
|
|
|
event.channel.send_message("**Categories**: #{categories[0..].join(' ')}")
|
|
|
|
nil
|
|
|
|
end
|
2024-10-04 09:59:00 +03:00
|
|
|
|
2024-10-21 14:20:11 +03:00
|
|
|
command(:showquote, aliases: [:sq, :quoteshow]) do |event, *message|
|
2024-10-04 09:59:00 +03:00
|
|
|
quote = db.execute("SELECT * FROM quotes WHERE id = ?", [message[0]])
|
|
|
|
if quote == nil
|
|
|
|
event.channel.send_message("Quote doesn't exist")
|
|
|
|
return
|
|
|
|
end
|
2024-10-04 11:35:37 +03:00
|
|
|
event.channel.send_message("##{quote[0][0]} <#{quote[0][2]}>: #{quote[0][3]}")
|
2024-10-04 09:59:00 +03:00
|
|
|
nil
|
|
|
|
end
|
2024-10-04 20:59:56 +03:00
|
|
|
|
|
|
|
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
|
2024-10-21 14:20:11 +03:00
|
|
|
end
|