· 6 years ago · Mar 11, 2019, 09:02 PM
1class Buttbot
2 include Cinch::Plugin
3
4 DB = ENV["HOME"] + "/buttbot.db"
5
6 def initialize(*args)
7 @db = SQLite3::Database.new(DB)
8 @db.execute(
9 "CREATE TABLE IF NOT EXISTS infobot(
10 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
11 term TEXT NOT NULL,
12 value TEXT NOT NULL
13 )")
14 super
15 end
16 # !rem keyword = information
17 set :prefix, /^\./
18
19 match(/r(?: (.+))?/, method: :remember)
20 def remember(m, term, val)
21 @db.execute("INSERT OR REPLACE INTO buttbot (term, value) VALUES (?, ?)", term, val)
22 m.reply("#{term} -> #{val}")
23 rescue => e
24 exception(e)
25 m.reply("Data corrupted, '#{term}' not found (lol fuckin rekt)")
26 end
27
28 # !<keyword>
29 match(/([^ ]+)$/, method: :lookup)
30 def lookup(m, term)
31 res = @db.get_first_value("SELECT value FROM buttbot WHERE term = ?", term)
32 if res
33 m.reply(res)
34 end
35 end
36end