split bot.rb into systems
This commit is contained in:
parent
e097ae3f5a
commit
06d78ee610
37
bot.rb
37
bot.rb
@ -5,7 +5,6 @@ require 'sqlite3'
|
||||
Dotenv.load
|
||||
|
||||
bot = Discordrb::Commands::CommandBot.new token: ENV['TOKEN'], client_id: ENV['CLIENT_ID'], prefix: ENV['PREFIX']
|
||||
db = SQLite3::Database.new("jon.sqlite")
|
||||
|
||||
bot.message do |event|
|
||||
if ENV['FORBIDDEN_WORDS'].split(",").any? { |word| event.message.content.downcase.include?(word.downcase)}
|
||||
@ -13,44 +12,12 @@ bot.message do |event|
|
||||
end
|
||||
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}")
|
||||
db.execute("INSERT INTO quotes (author, category, quote) VALUES (?, ?, ?)", [event.author.id, category, quote])
|
||||
nil
|
||||
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])
|
||||
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 <category> - displays a quote from the category\n;addquote <category> <quote> - adds a quote into a category\n;categories - shows all categories```")
|
||||
event.message.delete
|
||||
nil
|
||||
end
|
||||
|
||||
require_relative 'systems/quote'
|
||||
bot.include! QuoteSystem
|
||||
bot.run
|
||||
|
39
systems/quote.rb
Normal file
39
systems/quote.rb
Normal file
@ -0,0 +1,39 @@
|
||||
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
|
Loading…
Reference in New Issue
Block a user