-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInternDB.rb
69 lines (58 loc) · 2.04 KB
/
InternDB.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'rubygems'
require 'sqlite3'
class InternDB
@@db = nil
class << self
def connect(db)
@@db = SQLite3::Database.new(db)
end
# OPS TABLE
def add_op(nick, host)
nick.gsub(/'/, "\\'")
host.gsub(/'/, "\\'")
if @@db.execute("select * from ops where nick='#{nick}' and host='#{host}'").length == 0
@@db.execute("insert into ops (nick, host) values ('#{nick}', '#{host}')")
end
end
def remove_op(user)
user.gsub(/'/, "\\'")
@@db.execute("delete from ops where nick='#{user}'")
end
def is_op?(nick, host)
return @@db.execute("select * from ops where nick='#{nick}' and host='#{host}'").length > 0
end
# VOICES TABLE
def add_voice(nick, host)
nick.gsub(/'/, "\\'")
host.gsub(/'/, "\\'")
if @@db.execute("select * from voices where nick='#{nick}' and host='#{host}'").length == 0
@@db.execute("insert into voices (nick, host) values ('#{nick}', '#{host}')")
end
end
def remove_voice(user)
user.gsub(/'/, "\\'")
@@db.execute("delete from voices where nick='#{nick}'")
end
def is_voice?(nick, host)
return @@db.execute("select * from voices where nick='#{nick}' and host='#{host}'").length > 0
end
# BROS TABLE
def add_bro(bro)
bro = bro.gsub(/'/, "''")
if @@db.execute("select * from bros where bro='#{bro}'").length == 0
@@db.execute("insert into bros (bro) values ('#{bro}')")
end
end
def remove_bro(bro)
bro = bro.gsub(/'/, "''")
@@db.execute("delete from bros where bro='#{bro}'")
end
def random_bro
bros = @@db.execute("select bro from bros")
return bros.choice[0]
end
def list_bros
return @@db.execute("select bro from bros")
end
end
end