kag-gather 1.4.13 → 1.5.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjI5MjRkMGYwMjkwYWZlMjBiMjUyNGYwZTEwYTQ3OTY1NDVmZjQ5OA==
4
+ MmIxMGZmM2M3M2FmNjRjOTMyODQ4ZDFlMzRiYjEzZTZkYjQwM2NhMQ==
5
5
  data.tar.gz: !binary |-
6
- NzZmMjRkZTNkYzY1NmJiYmRiMDEzMDk1ZTIxOGU4ZTNiNmM2YTAwMA==
6
+ NmRjYWFhMzM2NTY3ZTI3ZmQ0MjZkOGMxM2VhN2E4M2Y0MjY3YTkxNg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWQ3ZDQzNTc2Y2U1ZmVjZjAyZjNiZTc5YzllNjI3MmZiODZlNDdhMzc3ZTc2
10
- NWMyM2JhZjg1Nzk1ZTA1N2VkZWNmNTJmZWRlZjJiMTFmZDA1ZWJkNDIwNjll
11
- NDI0Nzk3NzJiZWZkNDE3YzJkYTcyMGUyNDE2YWJjZWMyNDU3Zjc=
9
+ YTdmZmY3ZGUzZTc0Mzg4MjMyM2M4Y2RmYjcwNjgyOThlNWIwMmRhOTZlOGU0
10
+ NWNhZGVhN2E0OWJjNWQ1MDRiYTk2MWQ2YjkxOTRjNjFhYTgzMTk2OWRlNjY0
11
+ MjYxMGJhN2ZhNjk1N2Q1YWQ1YWIyYjBhOTJjYmI5NWIxNDJmY2U=
12
12
  data.tar.gz: !binary |-
13
- ZjM3NDEwYmNiMGI1ODMwYjNlZDQyNzJkZThiYjgzMzhhOWM0YmVjOWM2OWQw
14
- Y2EzZWFmZjljMjM2MmExMjMyYWFkMTBmOGNhMWE4MjczNGEwNTcwMmNjMWM2
15
- MGQzY2M2NzEzYjU2ZWUxMmE3OTI3Y2VlNWY4ZTRlOTgzYTBmMDM=
13
+ MDVlOWU3NDA0YTRhYWNhOTFhYWZhZTViYThhMjEzYWQxZjBkOGQxM2JmZWY1
14
+ Mzk4YmZkZjc2MGYwZDhjMzg0MzdmZTJjYTk2ZTFkODUxYmQwYjU5ZmRkNDI0
15
+ Nzc4NDY3MjQwNDA1ODA0ZDU5Y2VlODI0YjliMWE0NDZiN2I2ZWY=
@@ -8,6 +8,7 @@ require 'kag/irc/plugin'
8
8
  require 'kag/bot/plugin'
9
9
  require 'kag/user/plugin'
10
10
  require 'kag/help/plugin'
11
+ require 'kag/stats/plugin'
11
12
  require 'commands/help'
12
13
 
13
14
  module KAG
@@ -32,7 +33,8 @@ module KAG
32
33
  KAG::Bans::Plugin,
33
34
  KAG::IRC::Plugin,
34
35
  KAG::User::Plugin,
35
- KAG::Help::Plugin
36
+ KAG::Help::Plugin,
37
+ KAG::Stats::Plugin
36
38
  ]
37
39
  if config[:sasl]
38
40
  c.sasl.username = config[:sasl][:username]
@@ -4,6 +4,7 @@ require 'symboltable'
4
4
  require 'kag/config'
5
5
  require 'kag/gather/team'
6
6
  require 'kag/user/user'
7
+ require 'kag/stats/main'
7
8
 
8
9
  module KAG
9
10
  module Gather
@@ -65,6 +66,7 @@ module KAG
65
66
  self[:subs_needed] = []
66
67
  setup_teams
67
68
  restart_map
69
+ KAG::Stats::Main.add_stat(:matches_started)
68
70
  end
69
71
 
70
72
  def text_for_match_start
@@ -109,6 +111,8 @@ module KAG
109
111
 
110
112
  def cease
111
113
  if self.server
114
+ self.archive
115
+ KAG::Stats::Main.add_stat(:matches_completed)
112
116
  if self.server.has_rcon?
113
117
  self.teams.each do |team|
114
118
  team.kick_all
@@ -155,6 +159,7 @@ module KAG
155
159
  if needs_sub?
156
160
  placement = self[:subs_needed].shift
157
161
  KAG::User::User.add_stat(user,:substitutions)
162
+ KAG::Stats::Main.add_stat(:substitutions_done)
158
163
  end
159
164
  placement
160
165
  end
@@ -164,6 +169,35 @@ module KAG
164
169
  puts msg
165
170
  end
166
171
  end
172
+
173
+ def archive
174
+ match = self.dup
175
+ match[:server] = self.server[:key]
176
+ ts = []
177
+ match.teams.each do |team|
178
+ ts << {:players => team.teammates,:color => team[:color],:name => team[:name]}
179
+ end
180
+ match[:teams] = ts
181
+ match.delete(:players)
182
+ match.delete(:bot) if match.key?(:bot)
183
+
184
+ unless File.exists?("data/matches.json")
185
+ File.open("data/matches.json","w") {|f| f.write("{}") }
186
+ end
187
+
188
+ data = Hash.new
189
+ d = ::IO.read("data/matches.json")
190
+ if d and !d.empty?
191
+ data = Hash.new
192
+ data.merge!(JSON.parse(d))
193
+ end
194
+
195
+ data[Time.now.to_s] = match
196
+ File.open("data/matches.json","w") do |f|
197
+ f.write(data.to_json)
198
+ end
199
+ true
200
+ end
167
201
  end
168
202
  end
169
203
  end
@@ -75,6 +75,7 @@ module KAG
75
75
  def add(m)
76
76
  unless is_banned?(m.user)
77
77
  KAG::User::User.add_stat(m.user,:adds)
78
+ KAG::Stats::Main.add_stat(:adds)
78
79
  add_user_to_queue(m,m.user)
79
80
  end
80
81
  end
@@ -89,6 +90,7 @@ module KAG
89
90
  send_channels_msg "#{m.user.authname} has left the match at #{match.server[:key]}! You can sub in by typing !sub"
90
91
  elsif @queue.has_player?(m.user)
91
92
  KAG::User::User.add_stat(m.user,:rems)
93
+ KAG::Stats::Main.add_stat(:rems)
92
94
  unless remove_user_from_queue(m.user)
93
95
  debug "#{m.user.authname} is not in the queue."
94
96
  end
@@ -0,0 +1,60 @@
1
+ module KAG
2
+ module Stats
3
+ class Main < Hash
4
+ include Singleton
5
+
6
+ def initialize(hash=nil)
7
+ super
8
+ self.merge!(self._load)
9
+ end
10
+
11
+ def _load
12
+ unless File.exists?("data/index.json")
13
+ return {}
14
+ end
15
+ f = ::IO.read("data/index.json")
16
+ if f and !f.empty?
17
+ SymbolTable.new(JSON.parse(f))
18
+ else
19
+ SymbolTable.new
20
+ end
21
+ end
22
+
23
+ def reload
24
+ puts "Reloading stats.main file..."
25
+ self.merge!(self._load)
26
+ end
27
+
28
+ # Sets the value of the given +key+ to +val+.
29
+ def store(key, val)
30
+ super(key,val)
31
+ self.save
32
+ end
33
+
34
+ def save
35
+ File.open("data/index.json","w") do |f|
36
+ f.write(self.to_json)
37
+ end
38
+ end
39
+
40
+ def self.add_stat(stat,increment = 1)
41
+ stat = stat.to_sym
42
+ s = KAG::Stats::Main.instance
43
+ s[stat] = 0 unless s[stat]
44
+ s[stat] = s[stat].to_i + increment.to_i
45
+ s.save
46
+ end
47
+
48
+ def self.subtract_stat(stat,decrement = 1)
49
+ stat = stat.to_sym
50
+ s = KAG::Stats::Main.instance
51
+ if s[stat]
52
+ s[stat] = s[stat].to_i - decrement.to_i
53
+ else
54
+ s[stat] = 0
55
+ end
56
+ s.save
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,21 @@
1
+ require 'cinch'
2
+ require 'kag/common'
3
+ require 'commands/help'
4
+ require 'kag/user/user'
5
+ require 'kag/stats/main'
6
+
7
+ module KAG
8
+ module Stats
9
+ class Plugin
10
+ include Cinch::Plugin
11
+ include Cinch::Commands
12
+ include KAG::Common
13
+
14
+ command :stats,{},
15
+ summary: "Get the gather-wide stats"
16
+ def stats(m)
17
+ reply m,KAG::Stats::Main.instance.to_s
18
+ end
19
+ end
20
+ end
21
+ end
@@ -23,7 +23,7 @@ module KAG
23
23
  end
24
24
 
25
25
  def save
26
- File.open("data/#{self.authname}.json","w") do |f|
26
+ File.open("data/user/#{self.authname}.json","w") do |f|
27
27
  f.write(self.to_json)
28
28
  end
29
29
  end
@@ -57,11 +57,11 @@ module KAG
57
57
  def _load
58
58
  return {} unless self[:authname]
59
59
 
60
- unless File.exists?("data/#{self[:authname]}.json")
61
- File.open("data/#{self[:authname]}.json","w") {|f| f.write("{}") }
60
+ unless File.exists?("data/user/#{self[:authname]}.json")
61
+ File.open("data/user/#{self[:authname]}.json","w") {|f| f.write("{}") }
62
62
  end
63
63
 
64
- f = ::IO.read("data/#{self[:authname]}.json")
64
+ f = ::IO.read("data/user/#{self[:authname]}.json")
65
65
  if f and !f.empty?
66
66
  SymbolTable.new(JSON.parse(f))
67
67
  else
@@ -1,5 +1,5 @@
1
1
  module KAG
2
- VERSION = '1.4.13'
2
+ VERSION = '1.5.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.4.13
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
@@ -135,6 +135,8 @@ files:
135
135
  - lib/kag/help/plugin.rb
136
136
  - lib/kag/irc/plugin.rb
137
137
  - lib/kag/server.rb
138
+ - lib/kag/stats/main.rb
139
+ - lib/kag/stats/plugin.rb
138
140
  - lib/kag/user/plugin.rb
139
141
  - lib/kag/user/user.rb
140
142
  - lib/kag/version.rb