add trigger stuff
This commit is contained in:
parent
40f121541c
commit
a1d25336b7
@ -2,5 +2,5 @@ TOKEN=
|
|||||||
CLIENT_ID=
|
CLIENT_ID=
|
||||||
PREFIX=;
|
PREFIX=;
|
||||||
ADMIN=
|
ADMIN=
|
||||||
|
BOT_ID=
|
||||||
FORBIDDEN_WORDS=word1,word2
|
FORBIDDEN_WORDS=word1,word2
|
||||||
|
1
bot.rb
1
bot.rb
@ -29,4 +29,5 @@ systems.each { |i| require_relative "#{i}" }
|
|||||||
|
|
||||||
bot.include! QuoteSystem
|
bot.include! QuoteSystem
|
||||||
bot.include! NetworkModule
|
bot.include! NetworkModule
|
||||||
|
bot.include! TriggerSystem
|
||||||
bot.run
|
bot.run
|
||||||
|
13
sample.sql
13
sample.sql
@ -13,8 +13,6 @@
|
|||||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Dumping structure for table jon.quotes
|
-- Dumping structure for table jon.quotes
|
||||||
CREATE TABLE IF NOT EXISTS "quotes" (
|
CREATE TABLE IF NOT EXISTS "quotes" (
|
||||||
"id" INTEGER NOT NULL,
|
"id" INTEGER NOT NULL,
|
||||||
@ -26,6 +24,17 @@ CREATE TABLE IF NOT EXISTS "quotes" (
|
|||||||
|
|
||||||
-- Data exporting was unselected.
|
-- Data exporting was unselected.
|
||||||
|
|
||||||
|
-- Dumping structure for table jon.triggers
|
||||||
|
CREATE TABLE IF NOT EXISTS "triggers" (
|
||||||
|
"id" INTEGER NOT NULL,
|
||||||
|
"trigger" TEXT NOT NULL DEFAULT '',
|
||||||
|
"response" TEXT NOT NULL DEFAULT '',
|
||||||
|
"server" INTEGER NOT NULL DEFAULT 0,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Data exporting was unselected.
|
||||||
|
|
||||||
/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
|
/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
|
||||||
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
|
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
|
||||||
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
|
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
|
||||||
|
36
systems/trigger.rb
Normal file
36
systems/trigger.rb
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# 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
|
Loading…
Reference in New Issue
Block a user