kag-gather 1.3.5 → 1.4.0

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.
@@ -143,10 +143,20 @@ module KAG
143
143
 
144
144
  def self.is_banned?(user)
145
145
  KAG::Config.data[:ignored] = {} unless KAG::Config.data[:ignored]
146
- begin
147
- KAG::Config.data[:ignored].key?(user.authname.to_sym)
148
- rescue Exception => e
149
- puts e.message
146
+ if KAG::Config.data.flooding?(user)
147
+ return true
148
+ end
149
+
150
+ if user.authname and user.authname != ""
151
+ begin
152
+ KAG::Config.data[:ignored].key?(user.authname.to_sym)
153
+ rescue Exception => e
154
+ puts e.message
155
+ puts e.backtrace
156
+ end
157
+ else
158
+ user.send "You must first AUTH on the IRC server before you can use this bot."
159
+ KAG::Config.data.add_action(user)
150
160
  end
151
161
  end
152
162
 
data/lib/kag/bot/bot.rb CHANGED
@@ -6,6 +6,7 @@ require 'kag/gather/plugin'
6
6
  require 'kag/bans/plugin'
7
7
  require 'kag/irc/plugin'
8
8
  require 'kag/bot/plugin'
9
+ require 'kag/user/plugin'
9
10
  require 'commands/help'
10
11
 
11
12
  module KAG
@@ -23,7 +24,14 @@ module KAG
23
24
  c.realname = config[:realname].to_s != "" ? config[:realname] : "KAG Gatherer"
24
25
  c.messages_per_second = 1
25
26
  c.server_queue_size = 1
26
- c.plugins.plugins = [Cinch::Commands::Help,KAG::Bot::Plugin,KAG::Gather::Plugin,KAG::Bans::Plugin,KAG::IRC::Plugin]
27
+ c.plugins.plugins = [
28
+ Cinch::Commands::Help,
29
+ KAG::Bot::Plugin,
30
+ KAG::Gather::Plugin,
31
+ KAG::Bans::Plugin,
32
+ KAG::IRC::Plugin,
33
+ KAG::User::Plugin
34
+ ]
27
35
  if config[:sasl]
28
36
  c.sasl.username = config[:sasl][:username]
29
37
  c.sasl.password = config[:sasl][:password]
data/lib/kag/data.rb CHANGED
@@ -37,5 +37,20 @@ module KAG
37
37
  f.write(self.to_json)
38
38
  end
39
39
  end
40
+
41
+ def add_action(user)
42
+ self[:action_log] = [] unless self[:action_log]
43
+ self[:action_log] << user.nick
44
+ self[:action_log].shift if self[:action_log].length > 10
45
+ save
46
+ end
47
+
48
+ def flooding?(user)
49
+ flooding = false
50
+ if self[:action_log]
51
+ flooding = true if self[:action_log].count(user.nick) > 8
52
+ end
53
+ flooding
54
+ end
40
55
  end
41
56
  end
@@ -1,11 +1,15 @@
1
1
  require 'cinch'
2
+ require 'cinch/helpers'
2
3
  require 'symboltable'
3
4
  require 'kag/config'
4
5
  require 'kag/gather/team'
6
+ require 'kag/user/user'
5
7
 
6
8
  module KAG
7
9
  module Gather
8
10
  class Match < SymbolTable
11
+ include Cinch::Helpers
12
+
9
13
  def self.type_as_string
10
14
  ms = KAG::Config.instance[:match_size].to_i
11
15
  ts = (ms / 2).ceil
@@ -24,6 +28,13 @@ module KAG
24
28
  debug "LOWER BOUND: #{lb.to_s}"
25
29
  debug "PLAYERS: #{self[:players].join(",")}"
26
30
 
31
+ self[:players].each do |player|
32
+ u = User(player.to_s)
33
+ if u
34
+ KAG::User::User.add_match(u)
35
+ end
36
+ end
37
+
27
38
  self[:teams] = []
28
39
  self[:teams] << KAG::Gather::Team.new({
29
40
  :players => self[:players].slice(0,lb),
@@ -82,10 +93,10 @@ module KAG
82
93
  evt - self[:end_votes]
83
94
  end
84
95
 
85
- def has_player?(nick)
96
+ def has_player?(user)
86
97
  playing = false
87
98
  self[:teams].each do |team|
88
- playing = true if team.has_player?(nick)
99
+ playing = true if team.has_player?(user)
89
100
  end
90
101
  playing
91
102
  end
@@ -116,11 +127,11 @@ module KAG
116
127
  end
117
128
  end
118
129
 
119
- def remove_player(nick)
130
+ def remove_player(user)
120
131
  sub = false
121
132
  self[:teams].each do |team|
122
- if team.has_player?(nick)
123
- sub = team.remove_player(nick)
133
+ if team.has_player?(user)
134
+ sub = team.remove_player(user)
124
135
  end
125
136
  end
126
137
  if sub
@@ -141,10 +152,10 @@ module KAG
141
152
  placement
142
153
  end
143
154
 
144
- def rename_player(last_nick,new_nick)
155
+ def rename_player(user)
145
156
  self[:teams].each do |team|
146
- if team.has_player?(last_nick)
147
- team.rename_player(last_nick,new_nick)
157
+ if team.has_player?(user)
158
+ team.rename_player(user)
148
159
  end
149
160
  end
150
161
  end
@@ -37,34 +37,41 @@ module KAG
37
37
  listen_to :leaving, :method => :on_leaving
38
38
  def on_leaving(m,nick)
39
39
  unless is_banned?(m.user)
40
- nick = nick.to_s
41
- match = get_match_in(nick)
42
- if match
43
- sub = match.remove_player(nick)
44
- if sub
45
- m.channel.msg sub[:msg]
40
+ user = User(nick.to_s)
41
+ if user
42
+ match = get_match_in(user)
43
+ if match
44
+ sub = match.remove_player(user)
45
+ if sub
46
+ m.channel.msg sub[:msg]
47
+ end
48
+ elsif @queue.key?(nick)
49
+ remove_user_from_queue(nick)
46
50
  end
47
- elsif @queue.key?(nick)
48
- remove_user_from_queue(nick)
51
+ else
52
+ reply m,"User #{nick} not found"
49
53
  end
50
54
  end
51
55
  end
52
56
 
53
57
  listen_to :nick, :method => :on_nick
54
58
  def on_nick(m)
55
- unless is_banned?(m.user)
56
- match = get_match_in(m.user.last_nick)
57
- if match
58
- match.rename_player(m.user.last_nick,m.user.nick)
59
- elsif @queue.key?(m.user.last_nick)
60
- @queue[m.user.nick] = @queue[m.user.last_nick]
61
- @queue.delete(m.user.last_nick)
62
- end
63
- end
59
+
60
+ #unless is_banned?(m.user)
61
+ # match = get_match_in(m.user)
62
+ # if match
63
+ # match.rename_player(m.user)
64
+ # elsif @queue.key?(m.user.last_nick)
65
+ # @queue[m.user.nick] = @queue[m.user.last_nick]
66
+ # @queue.delete(m.user.last_nick)
67
+ # end
68
+ #end
64
69
  end
65
70
 
66
- match "sub", :method => :evt_sub
67
- def evt_sub(m)
71
+ command :sub,{},
72
+ summary: "Sub into a match",
73
+ description: "If a player leaves a match early, you can use this command to sub in and join the match"
74
+ def sub(m)
68
75
  unless is_banned?(m.user)
69
76
  @matches.each do |k,match|
70
77
  if match.needs_sub?
@@ -90,9 +97,9 @@ module KAG
90
97
  summary: "Remove yourself from the active queue for the next match"
91
98
  def rem(m)
92
99
  unless is_banned?(m.user)
93
- match = get_match_in(m.user.nick)
100
+ match = get_match_in(m.user)
94
101
  if match
95
- match.remove_player(m.user.nick)
102
+ match.remove_player(m.user)
96
103
  send_channels_msg "#{m.user.nick} has left the match at #{match.server[:key]}! You can sub in by typing !sub"
97
104
  elsif @queue.key?(m.user.nick)
98
105
  unless remove_user_from_queue(m.user.nick)
@@ -127,7 +134,7 @@ module KAG
127
134
  description: "End the current match. This will only work if you are in the match. After !end is called by 3 different players, the match will end."
128
135
  def end(m)
129
136
  unless is_banned?(m.user)
130
- match = get_match_in(m.user.nick)
137
+ match = get_match_in(m.user)
131
138
  if match
132
139
  match.add_end_vote
133
140
  if match.voted_to_end?
@@ -170,10 +177,10 @@ module KAG
170
177
  end
171
178
  end
172
179
 
173
- def get_match_in(nick)
180
+ def get_match_in(user)
174
181
  m = false
175
182
  @matches.each do |k,match|
176
- if match.has_player?(nick)
183
+ if match.has_player?(user)
177
184
  m = match
178
185
  end
179
186
  end
@@ -199,7 +206,8 @@ module KAG
199
206
 
200
207
  match = KAG::Gather::Match.new(SymbolTable.new({
201
208
  :server => server,
202
- :players => players
209
+ :players => players,
210
+ :bot => self.bot
203
211
  }))
204
212
  match.start # prepare match data
205
213
  messages = match.notify_teams_of_match_start # gather texts for private messages
@@ -288,7 +296,7 @@ module KAG
288
296
  admin: true
289
297
  def restart_map(m)
290
298
  if is_admin(m.user)
291
- match = get_match_in(m.user.nick)
299
+ match = get_match_in(m.user)
292
300
  if match and match.server
293
301
  match.server.restart_map
294
302
  end
@@ -314,7 +322,7 @@ module KAG
314
322
  admin: true
315
323
  def next_map(m)
316
324
  if is_admin(m.user)
317
- match = get_match_in(m.user.nick)
325
+ match = get_match_in(m.user)
318
326
  if match and match.server
319
327
  match.server.next_map
320
328
  end
@@ -340,12 +348,17 @@ module KAG
340
348
  admin: true
341
349
  def kick_from_match(m,nick)
342
350
  if is_admin(m.user)
343
- match = get_match_in(nick)
344
- if match
345
- match.remove_player(nick)
346
- m.reply "#{nick} has been kicked from the match"
351
+ user = User(nick.to_s)
352
+ if user
353
+ match = get_match_in(user)
354
+ if match
355
+ match.remove_player(user)
356
+ m.reply "#{user.nick} has been kicked from the match"
357
+ else
358
+ m.reply "#{user.nick} is not in a match!"
359
+ end
347
360
  else
348
- m.reply "#{nick} is not in a match!"
361
+ reply m,"User #{nick} not found"
349
362
  end
350
363
  end
351
364
  end
@@ -2,6 +2,7 @@ require 'cinch'
2
2
  require 'cinch/user'
3
3
  require 'symboltable'
4
4
  require 'kag/config'
5
+ require 'kag/user/user'
5
6
 
6
7
  module KAG
7
8
  module Gather
@@ -42,30 +43,32 @@ module KAG
42
43
  "#{self[:color]}#{self[:players].keys.join(", ")} (#{self[:name]})"
43
44
  end
44
45
 
45
- def has_player?(nick)
46
- self[:players].keys.include?(nick.to_sym)
46
+ def has_player?(user)
47
+ self[:players].keys.include?(user.nick.to_sym)
47
48
  end
48
49
 
49
- def rename_player(last_nick,new_nick)
50
- if has_player?(nick)
51
- cls = self[:players][last_nick.to_sym]
52
- self[:players].delete(last_nick.to_sym)
53
- self[:players][new_nick.to_sym] = cls
50
+ def rename_player(user)
51
+ if self[:players].keys.include?(user.last_nick.to_sym)
52
+ cls = self[:players][user.last_nick.to_sym]
53
+ self[:players].delete(user.last_nick.to_sym)
54
+ self[:players][user.nick.to_sym] = cls
54
55
  end
55
56
  end
56
57
 
57
- def remove_player(nick)
58
- if has_player?(nick)
58
+ def remove_player(user)
59
+ if has_player?(user)
59
60
  sub = {}
60
- sub[:cls] = self[:players][nick]
61
+ sub[:cls] = self[:players][user.nick]
61
62
  sub[:team] = self.clone
62
63
  sub[:msg] = "Sub needed at #{self.match.server[:ip]} for #{sub[:team][:name]}, #{sub[:cls]} Class! Type !sub to claim it!"
63
- sub[:channel_msg] = "#{nick} is now subbing in for #{self[:name]} at #{self.match.server[:key]}. Subs still needed: #{self.match[:subs_needed].length}"
64
+ sub[:channel_msg] = "#{user.nick} is now subbing in for #{self[:name]} at #{self.match.server[:key]}. Subs still needed: #{self.match[:subs_needed].length}"
64
65
  sub[:private_msg] = "Please #{self.match.server.text_join} | #{sub[:cls]} on the #{self[:name]} Team"
65
- self[:players].delete(nick)
66
+ self[:players].delete(user.nick)
67
+
68
+ KAG::User::User.subtract_match(user)
66
69
 
67
70
  if self.match and self.match.server
68
- self.match.server.kick(nick)
71
+ self.match.server.kick(user.nick)
69
72
  end
70
73
 
71
74
  sub
@@ -0,0 +1,32 @@
1
+ require 'cinch'
2
+ require 'kag/common'
3
+ require 'commands/help'
4
+ require 'kag/user/user'
5
+
6
+ module KAG
7
+ module User
8
+ class Plugin
9
+ include Cinch::Plugin
10
+ include Cinch::Commands
11
+ include KAG::Common
12
+
13
+ command :stats,{},
14
+ summary: "Get the stats for a user"
15
+ def stats(m)
16
+ reply m,KAG::User::User.stats(m.user)
17
+ end
18
+
19
+ command :stats,{nick: :string},
20
+ summary: "Get the stats for a user",
21
+ method: :stats_specific
22
+ def stats_specific(m,nick)
23
+ user = User(nick)
24
+ if user and !user.unknown
25
+ reply m,KAG::User::User.stats(user)
26
+ else
27
+ reply m,"Could not find user #{nick}"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,71 @@
1
+ require 'symboltable'
2
+ require 'json'
3
+
4
+ module KAG
5
+ module User
6
+ class User < SymbolTable
7
+
8
+ def initialize(user)
9
+ self[:authname] = user.authname
10
+ super({})
11
+ self.merge!(_load)
12
+ end
13
+
14
+ def reload
15
+ puts "Reloading data file..."
16
+ self.merge!(self._load)
17
+ end
18
+
19
+ # Sets the value of the given +key+ to +val+.
20
+ def store(key, val)
21
+ super(key,val)
22
+ self.save
23
+ end
24
+
25
+ def save
26
+ File.open("data/#{self.authname}.json","w") do |f|
27
+ f.write(self.to_json)
28
+ end
29
+ end
30
+
31
+ def self.add_match(user)
32
+ u = KAG::User::User.new(user)
33
+ u[:matches] = 0 unless u[:matches]
34
+ u[:matches] = u[:matches].to_i + 1
35
+ u.save
36
+ end
37
+
38
+ def self.subtract_match(user)
39
+ u = KAG::User::User.new(user)
40
+ if u[:matches]
41
+ u[:matches] = u[:matches].to_i + 1
42
+ else
43
+ u[:matches] = 0
44
+ end
45
+ u.save
46
+ end
47
+
48
+ def self.stats(user)
49
+ u = KAG::User::User.new(user)
50
+ "#{user.nick} has played in #{u.matches} matches."
51
+ end
52
+
53
+ protected
54
+
55
+ def _load
56
+ return {} unless self[:authname]
57
+
58
+ unless File.exists?("data/#{self[:authname]}.json")
59
+ File.open("data/#{self[:authname]}.json","w") {|f| f.write("{}") }
60
+ end
61
+
62
+ f = ::IO.read("data/#{self[:authname]}.json")
63
+ if f and !f.empty?
64
+ SymbolTable.new(JSON.parse(f))
65
+ else
66
+ SymbolTable.new
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
data/lib/kag/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module KAG
2
- VERSION = '1.3.5'
2
+ VERSION = '1.4.0'
3
3
  def self.version
4
4
  VERSION
5
5
  end
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.5
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -147,6 +147,8 @@ files:
147
147
  - lib/kag/gather/team.rb
148
148
  - lib/kag/irc/plugin.rb
149
149
  - lib/kag/server.rb
150
+ - lib/kag/user/plugin.rb
151
+ - lib/kag/user/user.rb
150
152
  - lib/kag/version.rb
151
153
  - lib/patches.rb
152
154
  - config/config.sample.json