kag-gather 1.3.4 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kag-gather
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-24 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cinch
@@ -131,15 +131,22 @@ extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
133
  - readme.md
134
+ - lib/commands/command.rb
135
+ - lib/commands/commands.rb
136
+ - lib/commands/help.rb
134
137
  - lib/gather.rb
135
- - lib/kag/bot.rb
138
+ - lib/kag/bans/plugin.rb
139
+ - lib/kag/bans/report.rb
140
+ - lib/kag/bot/bot.rb
141
+ - lib/kag/bot/plugin.rb
142
+ - lib/kag/common.rb
136
143
  - lib/kag/config.rb
137
144
  - lib/kag/data.rb
138
- - lib/kag/gather.rb
139
- - lib/kag/match.rb
140
- - lib/kag/report.rb
145
+ - lib/kag/gather/match.rb
146
+ - lib/kag/gather/plugin.rb
147
+ - lib/kag/gather/team.rb
148
+ - lib/kag/irc/plugin.rb
141
149
  - lib/kag/server.rb
142
- - lib/kag/team.rb
143
150
  - lib/kag/version.rb
144
151
  - lib/patches.rb
145
152
  - config/config.sample.json
data/lib/kag/bot.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'cinch'
2
- require 'kag/config'
3
- require 'kag/gather'
4
-
5
- module KAG
6
- class Bot
7
- def initialize
8
- config = self.config
9
- bot = Cinch::Bot.new do
10
- configure do |c|
11
- c.server = config[:server]
12
- c.channels = config[:channels]
13
- c.port = config[:port].to_i > 0 ? config[:port] : 6667
14
- #c.ssl = config[:ssl]
15
- c.nick = config[:nick].to_s != "" ? config[:nick] : "KAGatherer"
16
- c.realname = config[:realname].to_s != "" ? config[:realname] : "KAG Gatherer"
17
- c.messages_per_second = 1
18
- c.server_queue_size = 1
19
- c.plugins.plugins = [KAG::Gather]
20
- if config[:sasl]
21
- c.sasl.username = config[:sasl][:username]
22
- c.sasl.password = config[:sasl][:password]
23
- end
24
- end
25
- end
26
-
27
- bot.start
28
- end
29
-
30
- def config
31
- KAG::Config.instance
32
- end
33
- end
34
- end
data/lib/kag/gather.rb DELETED
@@ -1,507 +0,0 @@
1
- require 'cinch'
2
- require 'kag/bot'
3
- require 'kag/config'
4
- require 'kag/data'
5
- require 'kag/report'
6
- require 'kag/server'
7
- require 'kag/match'
8
-
9
- module KAG
10
- class Gather
11
- include Cinch::Plugin
12
-
13
- attr_accessor :queue,:servers
14
-
15
- def initialize(*args)
16
- super
17
- @queue = {}
18
- @matches = {}
19
- _load_servers
20
- end
21
-
22
- def _load_servers
23
- @servers = {}
24
- KAG::Config.instance[:servers].each do |k,s|
25
- s[:key] = k
26
- @servers[k] = KAG::Server.new(s)
27
- end
28
- end
29
-
30
- #listen_to :channel, method: :channel_listen
31
- #def channel_listen(m)
32
- #end
33
-
34
- listen_to :leaving, :method => :on_leaving
35
- def on_leaving(m,nick)
36
- unless is_banned?(m.user)
37
- nick = nick.to_s
38
- match = get_match_in(nick)
39
- if match
40
- sub = match.remove_player(nick)
41
- if sub
42
- m.channel.msg sub[:msg]
43
- end
44
- elsif @queue.key?(nick)
45
- remove_user_from_queue(nick)
46
- end
47
- end
48
- end
49
-
50
- listen_to :nick, :method => :on_nick
51
- def on_nick(m)
52
- unless is_banned?(m.user)
53
- match = get_match_in(m.user.last_nick)
54
- if match
55
- match.rename_player(m.user.last_nick,m.user.nick)
56
- elsif @queue.key?(m.user.last_nick)
57
- @queue[m.user.nick] = @queue[m.user.last_nick]
58
- @queue.delete(m.user.last_nick)
59
- end
60
- end
61
- end
62
-
63
- match "sub", :method => :evt_sub
64
- def evt_sub(m)
65
- unless is_banned?(m.user)
66
- @matches.each do |k,match|
67
- if match.needs_sub?
68
- placement = match.sub_in(m.user.nick)
69
- if placement
70
- reply m,placement[:channel_msg]
71
- User(m.user.nick).send placement[:private_msg]
72
- end
73
- end
74
- end
75
- end
76
- end
77
-
78
- match "add", :method => :evt_add
79
- def evt_add(m)
80
- unless is_banned?(m.user)
81
- add_user_to_queue(m,m.user.nick)
82
- end
83
- end
84
-
85
- match "rem", method: :evt_rem
86
- def evt_rem(m)
87
- unless is_banned?(m.user)
88
- match = get_match_in(m.user.nick)
89
- if match
90
- match.remove_player(m.user.nick)
91
- send_channels_msg "#{m.user.nick} has left the match at #{match.server[:key]}! You can sub in by typing !sub"
92
- elsif @queue.key?(m.user.nick)
93
- unless remove_user_from_queue(m.user.nick)
94
- debug "#{nick} is not in the queue."
95
- end
96
- end
97
- end
98
- end
99
-
100
- match "list", :method => :evt_list
101
- def evt_list(m)
102
- unless is_banned?(m.user)
103
- users = []
104
- @queue.each do |n,u|
105
- users << n
106
- end
107
- m.user.send "Queue (#{KAG::Match.type_as_string}) [#{@queue.length}] #{users.join(", ")}"
108
- end
109
- end
110
-
111
- match "status", :method => :evt_status
112
- def evt_status(m)
113
- unless is_banned?(m.user)
114
- reply m,"Matches in progress: #{@matches.length.to_s}"
115
- end
116
- end
117
-
118
- match "end", :method => :evt_end
119
- def evt_end(m)
120
- unless is_banned?(m.user)
121
- match = get_match_in(m.user.nick)
122
- if match
123
- match.add_end_vote
124
- if match.voted_to_end?
125
- match.cease
126
- @matches.delete(match.server[:key])
127
- send_channels_msg("Match at #{match.server[:key]} finished!")
128
- else
129
- reply m,"End vote started, #{match.get_needed_end_votes_left} more votes to end match at #{match.server[:key]}"
130
- end
131
- else
132
- reply m,"You're not in a match, silly! Stop trying to hack me."
133
- end
134
- end
135
- end
136
-
137
- match "help", :method => :evt_help
138
- def evt_help(m)
139
- unless is_banned?(m.user)
140
- msg = "Commands: !add, !rem, !list, !status, !help, !end, !report"
141
- msg = msg + ", !rem [nick], !add [nick], !add_silent, !rem_silent, !unreport, !clear, !restart, !quit" if is_admin(m.user)
142
- User(m.user.nick).send(msg)
143
- end
144
- end
145
-
146
- match /report (.+)/,:method => :report
147
- def report(m,nick)
148
- unless is_banned?(m.user)
149
- u = User(nick)
150
- if u and !u.unknown
151
- KAG::Report.new(self,m,u)
152
- else
153
- reply m,"User #{nick} not found!"
154
- end
155
- end
156
- end
157
-
158
- def add_user_to_queue(m,nick,send_msg = true)
159
- if @queue.key?(nick)
160
- reply m,"#{nick} is already in the queue!"
161
- elsif get_match_in(nick)
162
- reply m,"#{nick} is already in a match!"
163
- else
164
- @queue[nick] = SymbolTable.new({
165
- :user => User(nick),
166
- :channel => m.channel,
167
- :message => m.message,
168
- :joined_at => Time.now
169
- })
170
- send_channels_msg "Added #{nick} to queue (#{KAG::Match.type_as_string}) [#{@queue.length}]" if send_msg
171
- check_for_new_match
172
- end
173
- end
174
-
175
- def remove_user_from_queue(nick,send_msg = true)
176
- if @queue.key?(nick)
177
- @queue.delete(nick)
178
- send_channels_msg "Removed #{nick} from queue (#{KAG::Match.type_as_string}) [#{@queue.length}]" if send_msg
179
- true
180
- else
181
- false
182
- end
183
- end
184
-
185
- def get_match_in(nick)
186
- m = false
187
- @matches.each do |k,match|
188
- if match.has_player?(nick)
189
- m = match
190
- end
191
- end
192
- m
193
- end
194
-
195
- def check_for_new_match
196
- if @queue.length >= KAG::Config.instance[:match_size]
197
- players = []
198
- @queue.each do |n,i|
199
- players << n
200
- end
201
-
202
- server = get_unused_server
203
- unless server
204
- send_channels_msg "Could not find any available servers!"
205
- debug "FAILED TO FIND UNUSED SERVER"
206
- return false
207
- end
208
-
209
- # reset queue first to prevent 11-player load
210
- @queue = {}
211
-
212
- match = KAG::Match.new(SymbolTable.new({
213
- :server => server,
214
- :players => players
215
- }))
216
- match.start # prepare match data
217
- messages = match.notify_teams_of_match_start # gather texts for private messages
218
- send_channels_msg(match.text_for_match_start,false) # send channel-wide first
219
- messages.each do |nick,msg|
220
- User(nick.to_s).send(msg) unless nick.to_s.include?("player")
221
- sleep(2) # prevent excess flood stuff
222
- end
223
- @matches[server[:key]] = match
224
- end
225
- end
226
-
227
- def send_channels_msg(msg,colorize = true)
228
- KAG::Config.instance[:channels].each do |c|
229
- msg = Format(:grey,msg) if colorize
230
- Channel(c).send(msg)
231
- end
232
- end
233
-
234
- def reply(m,msg,colorize = true)
235
- msg = Format(:grey,msg) if colorize
236
- m.reply msg
237
- end
238
-
239
- def get_unused_server
240
- server = false
241
- @servers.shuffle!
242
- @servers.each do |k,s|
243
- server = s unless s.in_use?
244
- end
245
- server
246
- end
247
-
248
- # admin methods
249
-
250
- def debug(msg)
251
- if KAG::Config.instance[:debug]
252
- puts msg
253
- end
254
- end
255
-
256
- def is_admin(user)
257
- user.refresh
258
- o = (KAG::Config.instance[:owners] or [])
259
- o.include?(user.authname)
260
- end
261
-
262
- match "clear", :method => :evt_clear
263
- def evt_clear(m)
264
- if is_admin(m.user)
265
- send_channels_msg "Match queue cleared."
266
- @queue = {}
267
- end
268
- end
269
-
270
- match /rem (.+)/, :method => :evt_rem_admin
271
- def evt_rem_admin(m, arg)
272
- if is_admin(m.user)
273
- arg = arg.split(" ")
274
- arg.each do |nick|
275
- remove_user_from_queue(nick)
276
- end
277
- end
278
- end
279
-
280
- match /rem_silent (.+)/, :method => :evt_rem_silent_admin
281
- def evt_rem_silent_admin(m, arg)
282
- if is_admin(m.user)
283
- arg = arg.split(" ")
284
- arg.each do |nick|
285
- remove_user_from_queue(nick,false)
286
- end
287
- end
288
- end
289
-
290
- match /add (.+)/, :method => :evt_add_admin
291
- def evt_add_admin(m, arg)
292
- if is_admin(m.user)
293
- arg = arg.split(" ")
294
- arg.each do |nick|
295
- add_user_to_queue(m,nick)
296
- end
297
- end
298
- end
299
-
300
- match /add_silent (.+)/, :method => :evt_add_silent_admin
301
- def evt_add_silent_admin(m, arg)
302
- if is_admin(m.user)
303
- arg = arg.split(" ")
304
- arg.each do |nick|
305
- add_user_to_queue(m,nick,false)
306
- end
307
- end
308
- end
309
-
310
- match /is_admin (.+)/, :method => :evt_am_i_admin
311
- def evt_am_i_admin(m,nick)
312
- u = User(nick)
313
- if is_admin(u)
314
- reply m,"Yes, #{nick} is an admin!"
315
- else
316
- reply m,"No, #{nick} is not an admin."
317
- end
318
- end
319
-
320
-
321
- match "quit", :method => :evt_quit
322
- def evt_quit(m)
323
- if is_admin(m.user)
324
- m.bot.quit("Shutting down...")
325
- end
326
- end
327
-
328
- match "restart", :method => :evt_restart
329
- def evt_restart(m)
330
- if is_admin(m.user)
331
- cmd = (KAG::Config.instance[:restart_method] or "nohup sh gather.sh &")
332
- debug cmd
333
- pid = spawn cmd
334
- debug "Restarting bot, new process ID is #{pid.to_s} ..."
335
- exit
336
- end
337
- end
338
-
339
- match "restart_map", :method => :evt_restart_map
340
- def evt_restart_map(m)
341
- if is_admin(m.user)
342
- match = get_match_in(m.user.nick)
343
- if match and match.server
344
- match.server.restart_map
345
- end
346
- end
347
- end
348
-
349
- match /restart_map (.+)/, :method => :evt_restart_map_specify
350
- def evt_restart_map_specify(m,arg)
351
- if is_admin(m.user)
352
- if @servers[key]
353
- @servers[key].restart_map
354
- else
355
- m.reply "No server found with key #{arg}"
356
- end
357
- end
358
- end
359
-
360
- match "next_map", :method => :evt_next_map
361
- def evt_next_map(m)
362
- if is_admin(m.user)
363
- match = get_match_in(m.user.nick)
364
- if match and match.server
365
- match.server.next_map
366
- end
367
- end
368
- end
369
-
370
- match /next_map (.+)/, :method => :evt_next_map_specify
371
- def evt_next_map_specify(m,arg)
372
- if is_admin(m.user)
373
- if @servers[key]
374
- @servers[key].next_map
375
- else
376
- m.reply "No server found with key #{arg}"
377
- end
378
- end
379
- end
380
-
381
- match /kick_from_match (.+)/, :method => :evt_kick_from_match
382
- def evt_kick_from_match(m,nick)
383
- if is_admin(m.user)
384
- match = get_match_in(nick)
385
- if match
386
- match.remove_player(nick)
387
- m.reply "#{nick} has been kicked from the match"
388
- else
389
- m.reply "#{nick} is not in a match!"
390
- end
391
- end
392
- end
393
-
394
- match /op (.+)/,:method => :evt_op
395
- def evt_op(m,nick)
396
- if is_admin(m.user)
397
- m.channel.op(nick)
398
- end
399
- end
400
-
401
- match /deop (.+)/,:method => :evt_deop
402
- def evt_deop(m,nick)
403
- if is_admin(m.user)
404
- m.channel.deop(nick)
405
- end
406
- end
407
-
408
- match /voice (.+)/,:method => :evt_voice
409
- def evt_voice(m,nick)
410
- if is_admin(m.user)
411
- m.channel.voice(nick)
412
- end
413
- end
414
-
415
- match /devoice (.+)/,:method => :evt_devoice
416
- def evt_devoice(m,nick,reason)
417
- if is_admin(m.user)
418
- m.channel.devoice(nick)
419
- end
420
- end
421
-
422
- match /kick (.+) (.+)/,:method => :evt_kick
423
- def evt_kick(m,nick,reason)
424
- if is_admin(m.user)
425
- m.channel.kick(nick,reason)
426
- end
427
- end
428
-
429
- match "reload_config", :method => :evt_reload_config
430
- def evt_reload_config(m)
431
- if is_admin(m.user)
432
- KAG::Config.instance.reload
433
- m.reply "Configuration reloaded."
434
- end
435
- end
436
-
437
- match /unreport (.+)/,:method => :unreport
438
- def unreport(m,nick)
439
- if is_admin(m.user)
440
- user = User(nick)
441
- if user and !user.unknown
442
- KAG::Report.remove(self,m,user)
443
- else
444
- reply m,"Could not find user #{nick}"
445
- end
446
- end
447
- end
448
-
449
- match /ignore (.+)/,:method => :ignore
450
- def ignore(m,nick)
451
- if is_admin(m.user)
452
- user = User(nick)
453
- if user and !user.unknown
454
- KAG::Report.ignore(self,m,user)
455
- else
456
- reply m,"Could not find user #{nick}"
457
- end
458
- end
459
- end
460
-
461
- match /unignore (.+)/,:method => :unignore
462
- def unignore(m,nick)
463
- if is_admin(m.user)
464
- user = User(nick)
465
- if user and !user.unknown
466
- KAG::Report.unignore(self,m,user)
467
- else
468
- reply m,"Could not find user #{nick}"
469
- end
470
- end
471
- end
472
-
473
- match /hostname (.+)/,:method => :hostname
474
- def hostname(m,nick)
475
- if is_admin(m.user)
476
- user = User(nick)
477
- if user and !user.unknown
478
- reply m,"Hostname for #{nick} is #{user.host}"
479
- else
480
- reply m,"Could not find user #{nick}"
481
- end
482
- end
483
- end
484
-
485
- match /authname (.+)/,:method => :authname
486
- def authname(m,nick)
487
- if is_admin(m.user)
488
- user = User(nick)
489
- if user and !user.unknown
490
- reply m,"Authname for #{nick} is #{user.authname}"
491
- else
492
- reply m,"Could not find user #{nick}"
493
- end
494
- end
495
- end
496
-
497
- def is_banned?(user)
498
- d = KAG::Config.data
499
- KAG::Config.data[:ignored] = {} unless KAG::Config.data[:ignored]
500
- if d
501
- d[:ignored].key?(user.host.to_sym)
502
- else
503
- false
504
- end
505
- end
506
- end
507
- end