jon/systems/quote.rb

49 lines
1.6 KiB
Ruby
Raw Normal View History

2024-10-04 09:09:06 +03:00
require 'sqlite3'
require 'discordrb'
module QuoteSystem
extend Discordrb::Commands::CommandContainer
db = SQLite3::Database.new("jon.sqlite")
command :addquote do |event, *message|
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}")
db.execute("INSERT INTO quotes (author, category, quote) VALUES (?, ?, ?)", [event.author.id, category, quote])
nil
end
command :quote do |event, *message|
category = message[0]
if category == nil
event.channel.send_message("You haven't specified a category from where to fetch a random quote!")
return
end
quotes = db.execute("SELECT * FROM quotes WHERE category = ?", [category])
quote = quotes.sample
event.channel.send_message("##{quote[0]}: #{quote[3]}")
nil
end
command :quotecategories do |event, *message|
2024-10-04 09:09:06 +03:00
categories = db.execute("SELECT DISTINCT category FROM quotes")
event.channel.send_message("**Categories**: #{categories[0..].join(' ')}")
nil
end
command :showquote do |event, *message|
quote = db.execute("SELECT * FROM quotes WHERE id = ?", [message[0]])
if quote == nil
event.channel.send_message("Quote doesn't exist")
return
end
event.channel.send_message("##{quote[0][0]}: #{quote[0][3]}")
nil
end
2024-10-04 09:09:06 +03:00
end