forked from mcginty/InternBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternbot.rb
319 lines (298 loc) · 9.96 KB
/
internbot.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
require 'socket'
require 'uri'
require 'InternDB'
require 'IRCHole'
require 'rubygems'
require 'sqlite3'
class InternBot
@@irc = nil
@@admin_prefix = "sudo "
@@server = "irc.amazon.com"
@@port = "6667"
@@nick = "internbot" # TODO make "#{@@nick}[stfu]" when on STFU mode
@@channel = "#intern-chatter"
@@commands = {
"face" => {
:auth => :normal, # does this require an op to give the command?
:exact_args => 1, # an exact arg is an argument without a space
:excess => false, # whether other "excess" args are wanted
:func => lambda { |nick, arg|
@@irc.putraw "WHOIS #{arg}"
whois = @@irc.getraw
whois = whois.split(" ")[4]
if arg == @@nick
return "Do I look like a bitch to you?"
end
if whois != ":No"
return "#{arg}'s face: https://internal.amazon.com/phone/phone-image.cgi?uid=#{whois}"
else
return "This IRC user is faceless. Find nearest shelter."
end
},
},
"whois" => {
:auth => :normal,
:exact_args => 1,
:excess => false,
:func => lambda { |nick, arg|
@@irc.putraw "WHOIS #{arg}"
whois = @@irc.getraw
whois = whois.split(" ")[4]
if arg == @@nick
return "Do I look like a bitch to you?"
end
if whois != ":No"
return "#{arg}'s lookup: https://contactstool.amazon.com/ac/can/people/find/#{whois}"
else
return "This IRC user is faceless. Find nearest shelter."
end
},
},
"bro me" => {
:auth => :normal,
:exact_args => 0,
:excess => false,
:func => lambda { |nick|
return "Sure thing, " + InternDB.random_bro + "."
},
},
"nyan me" => {
:auth => :normal,
:exact_args => 1,
:excess => false,
:func => lambda { |nick, nyans|
nyans = nyans.to_i
if nyans <= 0
return
end
nyans-=1
nyan_out="nyan"
nyans.times do
nyan_out << " nyan"
if nyan_out.length > 426
break
end
end
return nyan_out
},
},
"sudo nyan me" => {
:auth => :normal,
:exact_args => 1,
:excess => false,
:func => lambda { |nick, nyans|
if @@irc.op? nick
nyans = nyans.to_i
if nyans <= 0
return
end
nyans-=1
nyan_out="nyan"
nyans.times do
if nyan_out.length > 421
@@irc.speak nyan_out
nyan_out = "nyan"
else
nyan_out << " nyan"
end
end
@@irc.speak nyan_out
return
end
},
},
=begin
"come at me bro" => {
:auth => :normal,
:exact_args => 0,
:excess => false,
:func => lambda { |nick|
if @@irc.op? nick
@@irc.putraw "KICK #{@@channel} #{@@irc.list[rand @@irc.list.size]}"
elsif
@@irc.putraw "KICK #{@@channel} #{nick}"
end
},
},
=end
"nyan spam" => {
:auth => :op,
:exact_args => 1,
:excess => false,
:func => lambda { |nick, nyans|
nyans = nyans.to_i
nyans.times do
@@irc.speak "nyan"
end
return
},
},
"add bro" => {
:auth => :normal,
:exact_args => 0,
:excess => true,
:func => lambda { |nick, bro|
InternDB.add_bro(bro)
return "Bro added."
},
},
"ice bro" => {
:auth => :op,
:exact_args => 0,
:excess => true,
:func => lambda { |nick, bro|
InternDB.remove_bro(bro)
return "Iced. Smooth move, brah."
},
},
"op" => {
:auth => :op,
:exact_args => 1,
:excess => false,
:func => lambda { |nick, arg|
@@irc.putraw "WHOIS #{arg}"
whois = @@irc.getraw
whois = whois.split(" ")[4]
InternDB.add_op(arg, whois)
@@irc.op arg
return "#{arg} welcomed into the magical kingdom."
},
},
"deop" => {
:auth => :op,
:exact_args => 1,
:excess => false,
:func => lambda { |nick, arg|
InternDB.remove_op arg
@@irc.deop arg
return "#{arg} shunned from the magical forest of ents and things."
},
},
# TODO change punish to voice/devoice at max users per command
#"punish" => {
# :auth => :op,
# :exact_args => 1,
# :excess => false,
# :func => lambda { |nick, user|
# @@irc.punish user
# return "#{user} being whipped sexily."
# },
#},
#"neutralize" => {
# :auth => :op,
# :exact_args => 0,
# :excess => false,
# :func => lambda { |nick|
# @@irc.neutralize
# return "All is well again."
# },
#},
"make me a" => {
:auth => :op,
:exact_args => 0,
:excess => true,
:func => lambda { |nick, arg|
arg = arg.join(" ") if arg.kind_of? Array
if arg.empty?
return
end
return "Make your own damn #{arg}"
},
},
"say" => {
:auth => :op,
:exact_args => 0,
:excess => true,
:func => lambda { |nick, arg|
arg = arg.join(" ") if arg.kind_of? Array
if arg.empty?
return
end
@@irc.speak arg
return nil
}
},
"#{@@nick} stfu" => {
:auth => :op,
:exact_args => 0,
:excess => false,
:func => lambda { |nick|
# workaround because you can't speak after stfu
@@irc.speak "going stealth."
@@irc.stfu
},
},
"#{@@nick} wtfu" => {
:auth => :op,
:exact_args => 0,
:excess => false,
:func => lambda { |nick|
@@irc.wtfu
return "so now you need me."
},
},
"#{@@nick} gtfo" => {
:auth => :op,
:exact_args => 0,
:excess => false,
:func => lambda { |nick|
@@irc.speak "whateva."
@@irc.putraw "QUIT"
exit
},
},
}
class << self
def start(db)
InternDB.connect(db)
@@irc = IRCHole.new(@@server, @@port, @@nick, @@channel, method(:command_handler))
@@irc.start
end
def command_handler(priv, nick, amzn_user, msg)
# SPECIAL CASE: commands listings.
if msg.start_with? "#{@@nick} commands"
cmdlist = []
@@commands.each do |command, cmd_info|
if cmd_info[:auth] == :op and InternDB.is_op?(nick, amzn_user)
cmdlist << "sudo " + command
elsif cmd_info[:auth] != :op
cmdlist << command
end
end
@@irc.speak cmdlist.join(' ')
end
# check if the message is a given command
@@commands.each do |command, cmd_info|
# apply admin prefix
if cmd_info[:auth] == :op and not InternDB.is_op?(nick, amzn_user)
next
elsif cmd_info[:auth] == :op
command = @@admin_prefix + command
end
if (cmd_info[:exact_args] > 0 and msg.start_with?(command+" ")) or (cmd_info[:exact_args] == 0 and msg.start_with?(command))
msg = msg[(command.length+1)..-1].strip # cut off command from message
@@irc.debug "command: "+command
# put args in array, and the excess as a string
if cmd_info[:exact_args] > 0
args = msg.split(" ")[0..(cmd_info[:exact_args]-1)]
else
args = []
end
if cmd_info[:excess]
args << msg.split(" ")[cmd_info[:exact_args]..-1].join(" ")
end
if args.length < cmd_info[:exact_args]
break
end
response = cmd_info[:func].call(nick, *args)
if priv
@@irc.privmsg(response, nick) unless not response
else
@@irc.speak(response) unless not response
end
break # out of the command loop if we found on successfully
end
end
end
end
end