· 6 years ago · Mar 11, 2019, 09:26 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 buttbot(
10 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
11 term TEXT NOT NULL,
12 value TEXT NOT NULL
13 )")
14 super
15 end
16
17 match(/r (.+)/, method: :remember)
18 def remember(m, term, val)
19 @db.execute("INSERT OR REPLACE INTO buttbot (term, value) VALUES (?, ?)", term, val)
20 m.reply("#{term} -> #{val}")
21 rescue => e
22 exception(e)
23 m.reply("Data corrupted, '#{term}' not found (lol fuckin rekt)")
24 end
25
26 # !<keyword>
27 match(/([^ ]+)$/, method: :lookup)
28 def lookup(m, term)
29 res = @db.get_first_value("SELECT value FROM buttbot WHERE term = ?", term)
30 m.reply(res) if res
31 end
32end