kag-gather 1.0.0 → 1.0.1

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.
Files changed (3) hide show
  1. data/lib/kag/gather.rb +85 -41
  2. data/lib/kag/version.rb +1 -1
  3. metadata +1 -1
data/lib/kag/gather.rb CHANGED
@@ -19,20 +19,18 @@ module KAG
19
19
  @matches = {}
20
20
  end
21
21
 
22
- listen_to :channel, method: :channel_listen
23
- def channel_listen(m)
22
+ #listen_to :channel, method: :channel_listen
23
+ #def channel_listen(m)
24
+ #end
24
25
 
26
+ listen_to :leaving, method: :on_leaving
27
+ def on_leaving(m,user)
28
+ remove_user_from_queue(user) if @queue.key?(user)
29
+ remove_user_from_match(user) if in_match(user)
25
30
  end
26
31
 
27
- listen_to :leaving, method: :leaving
28
- def leaving(m)
29
- if @queue.key?(m.user.nick)
30
- remove_from_queue(m)
31
- end
32
- end
33
-
34
- listen_to :nick, method: :handle_nick_change
35
- def handle_nick_change(m)
32
+ listen_to :nick, method: :on_nick
33
+ def on_nick(m)
36
34
  if @queue.key?(m.user.last_nick)
37
35
  @queue[m.user.nick] = @queue[m.user.last_nick]
38
36
  @queue.delete(m.user.last_nick)
@@ -52,8 +50,8 @@ module KAG
52
50
  end
53
51
  end
54
52
 
55
- match "add", method: :add_to_queue
56
- def add_to_queue(m)
53
+ match "add", method: :evt_add
54
+ def evt_add(m)
57
55
  unless @queue.key?(m.user.nick) or in_match(m.user.nick)
58
56
  @queue[m.user.nick] = SymbolTable.new({
59
57
  :user => m.user,
@@ -61,55 +59,81 @@ module KAG
61
59
  :message => m.message,
62
60
  :joined_at => Time.now
63
61
  })
64
- send_channels_msg "Added #{m.user.nick} to queue (5v5 CTF) [#{@queue.length}]"
62
+ send_channels_msg "Added #{m.user.nick} to queue (#{get_match_type_as_string}) [#{@queue.length}]"
65
63
  check_for_new_match(m)
66
64
  end
67
65
  end
68
66
 
69
- match "rem", method: :remove_from_queue
70
- def remove_from_queue(m)
71
- if @queue.key?(m.user.nick)
72
- @queue.delete(m.user.nick)
73
- send_channels_msg "Removed #{m.user.nick} from queue (5v5 CTF) [#{@queue.length}]"
74
- end
67
+ match "rem", method: :evt_rem
68
+ def evt_rem(m)
69
+ remove_user_from_match(m.user.nick)
70
+ remove_user_from_queue(m.user.nick)
75
71
  end
76
72
 
77
- match "list", method: :list_queue
78
- def list_queue(m)
73
+ match "list", method: :evt_list
74
+ def evt_list(m)
79
75
  users = []
80
76
  @queue.each do |n,u|
81
77
  users << n
82
78
  end
83
- m.user.send "Queue (5v5 CTF) [#{@queue.length}] #{users.join(", ")}"
79
+ m.user.send "Queue (#{get_match_type_as_string}) [#{@queue.length}] #{users.join(", ")}"
84
80
  end
85
81
 
86
- match "status", method: :status
87
- def status(m)
82
+ match "status", method: :evt_status
83
+ def evt_status(m)
88
84
  m.reply "Matches in progress: #{@matches.length.to_s}"
89
85
  end
90
86
 
91
- match "end", method: :end_match
92
- def end_match(m)
87
+ match "end", method: :evt_end
88
+ def evt_end(m)
93
89
  @matches.each do |k,match|
94
90
  info = match[:server].info
95
91
  if info
96
92
  players_on = info[:serverStatus][:playerList].length
97
93
  if players_on > 0
98
- m.reply "Cannot end a match for #{match[:server][:ip]} in progress, there are #{players_on.to_s} players still playing!"
94
+ m.reply "Cannot end a match for #{match[:server][:key]} in progress, there are #{players_on.to_s} players still playing!"
99
95
  else
100
- @matches.shift
101
- send_channels_msg("Match at #{match[:server][:ip]} finished!")
96
+ @matches.delete(k)
97
+ send_channels_msg("Match at #{match[:server][:key]} finished!")
102
98
  end
103
99
  end
104
100
  end
105
101
  end
106
102
 
103
+ def remove_user_from_queue(nick)
104
+ if @queue.key?(nick)
105
+ @queue.delete(nick)
106
+ send_channels_msg "Removed #{nick} from queue (#{get_match_type_as_string}) [#{@queue.length}]"
107
+ end
108
+ end
109
+
110
+ def remove_user_from_match(nick)
111
+ match = get_match_in(nick)
112
+ if match
113
+ send_channels_msg "#{user} has left the match at #{match[:key]}! Find a sub!"
114
+ end
115
+ end
116
+
107
117
  def in_match(nick)
108
- playing = false
109
- @matches.each do |m|
110
- playing = true if (m[:team1].include?(nick) or m[:team2].include?(nick))
118
+ get_match_in(nick)
119
+ end
120
+
121
+ def get_match_in(nick)
122
+ m = false
123
+ @matches.each do |k,match|
124
+ if match[:team1] and match[:team1].include?(nick)
125
+ m = match
126
+ elsif match[:team2] and match[:team2].include?(nick)
127
+ m = match
128
+ end
111
129
  end
112
- playing
130
+ m
131
+ end
132
+
133
+ def get_match_type_as_string
134
+ ms = KAG::Config.instance[:match_size]
135
+ ts = (ms / 2).ceil
136
+ "#{ts.to_s}v#{ts.to_s} #{KAG::Config.instance[:match_type]}"
113
137
  end
114
138
 
115
139
  def check_for_new_match(m)
@@ -131,11 +155,9 @@ module KAG
131
155
  match_size = KAG::Config.instance[:match_size].to_i
132
156
  match_size = 2 if match_size < 2
133
157
 
134
- lb = (match_size / 2).ceil.to_i - 1
158
+ lb = (match_size / 2).ceil.to_i
135
159
  lb = 1 if lb < 1
136
160
 
137
- (match_size-1).times { |x| playing << "player#{(x+1).to_s}" } if KAG::Config.instance[:debug]
138
-
139
161
  debug "MATCH SIZE #{match_size.to_s}"
140
162
  debug "LOWER BOUND: #{lb.to_s}"
141
163
  debug "PLAYERS: #{playing.join(",")}"
@@ -143,8 +165,8 @@ module KAG
143
165
  team1 = playing.slice(0,lb)
144
166
  team2 = playing.slice(lb,match_size)
145
167
 
146
- send_channels_msg("MATCH: #{team1.join(", ")} (Blue) vs #{team2.join(", ")} (Red)")
147
- msg = "Join \x0307#{server[:ip]}:#{server[:port]} password #{server[:password]} \x0310| Visit \x0307kag://#{server[:ip]}/#{server[:password]} \x0310| "
168
+ send_channels_msg("MATCH: #{get_match_type_as_string} - #{team1.join(", ")} (Blue) vs #{team2.join(", ")} (Red)")
169
+ msg = "Join #{server[:key]} - #{server[:ip]}:#{server[:port]} password #{server[:password]} | Visit kag://#{server[:ip]}/#{server[:password]} | "
148
170
  team1.each do |p|
149
171
  User(p).send(msg+" Blue Team #{team1.join(", ")}") unless p.include?("player")
150
172
  end
@@ -181,6 +203,13 @@ module KAG
181
203
  false
182
204
  end
183
205
 
206
+ match "help", method: :evt_help
207
+ def evt_help(m)
208
+ msg = "Commands: !add, !rem, !list, !status, !help, !end"
209
+ msg = msg + ", !rem [nick], !clear, !quit" if is_admin(m.user)
210
+ User(m.user.nick).send(msg)
211
+ end
212
+
184
213
  # admin methods
185
214
 
186
215
  def debug(msg)
@@ -195,8 +224,23 @@ module KAG
195
224
  o.include?(user.authname)
196
225
  end
197
226
 
198
- match "quit", method: :quit
199
- def quit(m)
227
+ match "clear", method: :evt_clear
228
+ def evt_clear(m)
229
+ if is_admin(m.user)
230
+ send_channels_msg "Match queue cleared."
231
+ @queue = {}
232
+ end
233
+ end
234
+
235
+ match /rem (.+)/, method: :evt_rem_admin
236
+ def evt_rem_admin(m, arg)
237
+ if is_admin(m.user)
238
+ remove_user_from_queue(arg)
239
+ end
240
+ end
241
+
242
+ match "quit", method: :evt_quit
243
+ def evt_quit(m)
200
244
  if is_admin(m.user)
201
245
  m.bot.quit("Shutting down...")
202
246
  end
data/lib/kag/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module KAG
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  def self.version
4
4
  VERSION
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kag-gather
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Shaun McCormick