jon/systems/trigger.rb
2024-10-04 22:17:09 +03:00

36 lines
1.0 KiB
Ruby

# frozen_string_literal: true
require 'discordrb'
require 'sqlite3'
require 'dotenv'
Dotenv.load("#{__dir__}/../.env")
module TriggerSystem
db = SQLite3::Database.new("jon.sqlite")
extend Discordrb::EventContainer
message do |event|
if event.message.author.id == ENV["BOT_ID"]
return
end
triggers = db.execute("SELECT * FROM triggers WHERE server=?", [event.message.channel.server.id])
for trigger in triggers do
if event.message.content.include? trigger[1]
event.channel.send_message(trigger[2])
end
end
nil
end
extend Discordrb::Commands::CommandContainer
command :addtrigger do |event, *message|
if event.author.id != event.channel.server.owner.id
event.channel.send_message("Only the owner can setup triggers.")
return
end
input = message[0..].join(' ').split("#")
db.execute('INSERT INTO "triggers" ("trigger", "response", "server") VALUES (?,?,?);', [input[0], input[1], event.channel.server.id])
event.channel.send_message("Trigger added")
nil
end
end