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 :categories do |event, *message| categories = db.execute("SELECT DISTINCT category FROM quotes") event.channel.send_message("**Categories**: #{categories[0..].join(' ')}") nil end end