diff --git a/.gitignore b/.gitignore index d49608e..d9b0090 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .env -jon.db +jon.sqlite Gemfile.lock diff --git a/bot.rb b/bot.rb index 337127d..adc7aa1 100644 --- a/bot.rb +++ b/bot.rb @@ -14,6 +14,14 @@ bot.message do |event| end bot.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}") @@ -23,8 +31,25 @@ end bot.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]) - event.channel.send_message(quotes.sample[3]) + quote = quotes.sample + event.channel.send_message("##{quote[0]}: #{quote[3]}") + nil +end + +bot.command :categories do |event, *message| + categories = db.execute("SELECT DISTINCT category FROM quotes") + event.channel.send_message("**Categories**: #{categories[0..].join(' ')}") + nil +end + +bot.command :help do |event, *message| + event.author.pm("You've asked for help. In order not to flood the channel where you sent the command, I have sent the list of commands here, in your PMs. Enjoy! \n\n**Quote system**\n```;quote - displays a quote from the category\n;addquote - adds a quote into a category\n;categories - shows all categories```") + event.message.delete nil end diff --git a/jon.sqlite b/jon.sqlite index 21d147a..a824513 100644 Binary files a/jon.sqlite and b/jon.sqlite differ