add quotes and stuff

This commit is contained in:
fzorb 2024-10-03 08:17:41 +03:00
parent fa655f69bb
commit 93b88dfeb6
4 changed files with 36 additions and 0 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
.env
jon.db
Gemfile.lock

3
Gemfile Normal file
View File

@ -0,0 +1,3 @@
gem 'dotenv', groups: [:development, :test]
gem 'discordrb'
gem 'sqlite3'

31
bot.rb Normal file
View File

@ -0,0 +1,31 @@
require 'discordrb'
require 'dotenv'
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)}
event.author.pm("Garfield, watch your tone!")
end
end
bot.command :addquote do |event, *message|
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]
quotes = db.execute("SELECT * FROM quotes WHERE category = ?", [category])
event.channel.send_message(quotes.sample[3])
nil
end
bot.run

BIN
jon.sqlite Normal file

Binary file not shown.