sc2cli 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.gitlab-ci.yml +37 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +13 -0
- data/bin/console +16 -0
- data/bin/setup +18 -0
- data/exe/sc2 +44 -0
- data/lib/sc2cli.rb +7 -0
- data/lib/sc2cli/shared.rb +15 -0
- data/lib/sc2cli/shared/api.rb +79 -0
- data/lib/sc2cli/shared/cache.rb +112 -0
- data/lib/sc2cli/shared/configuration.rb +119 -0
- data/lib/sc2cli/shared/console.rb +69 -0
- data/lib/sc2cli/shared/names.rb +101 -0
- data/lib/sc2cli/shared/region.rb +112 -0
- data/lib/sc2cli/shared/season.rb +123 -0
- data/lib/sc2cli/shared/token.rb +139 -0
- data/lib/sc2cli/subcommands.rb +9 -0
- data/lib/sc2cli/subcommands/history.rb +114 -0
- data/lib/sc2cli/subcommands/history/historymatch.rb +118 -0
- data/lib/sc2cli/subcommands/history/historymatches.rb +72 -0
- data/lib/sc2cli/subcommands/ladder.rb +120 -0
- data/lib/sc2cli/subcommands/ladder/ladderdetails.rb +110 -0
- data/lib/sc2cli/subcommands/ladder/ladderdetailsmembership.rb +64 -0
- data/lib/sc2cli/subcommands/ladder/ladderdetailsrank.rb +101 -0
- data/lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb +114 -0
- data/lib/sc2cli/subcommands/ladder/ladderdetailsteammember.rb +110 -0
- data/lib/sc2cli/subcommands/ladder/ladderdetailsteammembers.rb +85 -0
- data/lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb +85 -0
- data/lib/sc2cli/subcommands/ladder/laddersummary.rb +82 -0
- data/lib/sc2cli/subcommands/league.rb +190 -0
- data/lib/sc2cli/subcommands/league/leaguetier.rb +112 -0
- data/lib/sc2cli/subcommands/league/leaguetiers.rb +79 -0
- data/lib/sc2cli/subcommands/raw.rb +89 -0
- data/lib/sc2cli/subcommands/season.rb +74 -0
- data/lib/sc2cli/version.rb +13 -0
- data/sc2cli.gemspec +36 -0
- metadata +85 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
|
|
3
|
+
module SC2Cli
|
|
4
|
+
|
|
5
|
+
###############################################################################
|
|
6
|
+
|
|
7
|
+
module Subcommands
|
|
8
|
+
|
|
9
|
+
###############################################################################
|
|
10
|
+
|
|
11
|
+
module LadderShared
|
|
12
|
+
|
|
13
|
+
###############################################################################
|
|
14
|
+
|
|
15
|
+
class LadderDetailsTeams
|
|
16
|
+
|
|
17
|
+
###############################################################################
|
|
18
|
+
|
|
19
|
+
@teams
|
|
20
|
+
|
|
21
|
+
###############################################################################
|
|
22
|
+
|
|
23
|
+
def initialize(json:)
|
|
24
|
+
@teams = Array.new
|
|
25
|
+
|
|
26
|
+
json.each do |team|
|
|
27
|
+
team = LadderDetailsTeam.new(json: team)
|
|
28
|
+
add(team: team)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
###############################################################################
|
|
33
|
+
|
|
34
|
+
def add(team:)
|
|
35
|
+
@teams << team if team.kind_of?(LadderDetailsTeam)
|
|
36
|
+
@teams.sort_by!{ |team| team.points }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
###############################################################################
|
|
40
|
+
|
|
41
|
+
def count
|
|
42
|
+
return @teams.length
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
###############################################################################
|
|
46
|
+
|
|
47
|
+
def to_s
|
|
48
|
+
result = String.new
|
|
49
|
+
|
|
50
|
+
@teams.each do |team|
|
|
51
|
+
result += team.to_s
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
return result
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
###############################################################################
|
|
58
|
+
|
|
59
|
+
def with_member(player:)
|
|
60
|
+
result = LadderDetailsTeams.new(json: Array.new)
|
|
61
|
+
|
|
62
|
+
@teams.each do |team|
|
|
63
|
+
result.add(team: team) if team.members.has_player(player: player)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
return result
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
###############################################################################
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
###############################################################################
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
###############################################################################
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
###############################################################################
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
###############################################################################
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
|
|
3
|
+
module SC2Cli
|
|
4
|
+
|
|
5
|
+
###############################################################################
|
|
6
|
+
|
|
7
|
+
module Subcommands
|
|
8
|
+
|
|
9
|
+
###############################################################################
|
|
10
|
+
|
|
11
|
+
module LadderShared
|
|
12
|
+
|
|
13
|
+
###############################################################################
|
|
14
|
+
|
|
15
|
+
class LadderSummary
|
|
16
|
+
|
|
17
|
+
###############################################################################
|
|
18
|
+
|
|
19
|
+
@ladders
|
|
20
|
+
|
|
21
|
+
###############################################################################
|
|
22
|
+
|
|
23
|
+
def initialize(json:, api:, player:)
|
|
24
|
+
@ladders = Array.new
|
|
25
|
+
|
|
26
|
+
if json.key?("allLadderMemberships") then
|
|
27
|
+
ladders = json["allLadderMemberships"]
|
|
28
|
+
@@console.fatal("Returned ladder summary list of all ladders is not an array!") unless ladders.kind_of?(Array)
|
|
29
|
+
|
|
30
|
+
ladders.each do |ladder|
|
|
31
|
+
@@console.fatal("Returned ladder summary list of all ladders contains a ladder without an ID!") unless ladder.key?("ladderId")
|
|
32
|
+
|
|
33
|
+
id = ladder["ladderId"]
|
|
34
|
+
|
|
35
|
+
id = id.to_i if id.kind_of?(String)
|
|
36
|
+
|
|
37
|
+
ladder = LadderDetails.new(id: id, api: api, player: player)
|
|
38
|
+
add(ladder: ladder)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
###############################################################################
|
|
44
|
+
|
|
45
|
+
def add(ladder:)
|
|
46
|
+
id = ladder.id
|
|
47
|
+
|
|
48
|
+
unless @ladders.any? {|ladder| ladder.id == id}
|
|
49
|
+
@ladders << ladder if ladder.kind_of?(LadderDetails)
|
|
50
|
+
@ladders.sort_by!{ |ladder| ladder.membership.type }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
###############################################################################
|
|
55
|
+
|
|
56
|
+
def to_s
|
|
57
|
+
result = String.new
|
|
58
|
+
|
|
59
|
+
@ladders.each do |ladder|
|
|
60
|
+
result += ladder.to_s
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
return result
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
###############################################################################
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
###############################################################################
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
###############################################################################
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
###############################################################################
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
###############################################################################
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
|
|
5
|
+
###############################################################################
|
|
6
|
+
|
|
7
|
+
require_relative 'league/leaguetier'
|
|
8
|
+
require_relative 'league/leaguetiers'
|
|
9
|
+
|
|
10
|
+
###############################################################################
|
|
11
|
+
|
|
12
|
+
module SC2Cli
|
|
13
|
+
|
|
14
|
+
###############################################################################
|
|
15
|
+
|
|
16
|
+
module Subcommands
|
|
17
|
+
|
|
18
|
+
###############################################################################
|
|
19
|
+
|
|
20
|
+
class League
|
|
21
|
+
|
|
22
|
+
###############################################################################
|
|
23
|
+
|
|
24
|
+
@@console = Shared::Console.instance
|
|
25
|
+
|
|
26
|
+
###############################################################################
|
|
27
|
+
|
|
28
|
+
@@prefix = "/data/sc2/league"
|
|
29
|
+
@@type = "1v1"
|
|
30
|
+
@@random = false
|
|
31
|
+
|
|
32
|
+
###############################################################################
|
|
33
|
+
|
|
34
|
+
@@valid_codes = {
|
|
35
|
+
"b" => "bronze",
|
|
36
|
+
"bronze" => "bronze",
|
|
37
|
+
"s" => "silver",
|
|
38
|
+
"silver" => "silver",
|
|
39
|
+
"g" => "gold",
|
|
40
|
+
"gold" => "gold",
|
|
41
|
+
"p" => "platinum",
|
|
42
|
+
"plat" => "platinum",
|
|
43
|
+
"platinum" => "platinum",
|
|
44
|
+
"d" => "diamond",
|
|
45
|
+
"diamond" => "diamond",
|
|
46
|
+
"m" => "master",
|
|
47
|
+
"master" => "master",
|
|
48
|
+
"gm" => "grandmaster",
|
|
49
|
+
"grandmaster" => "grandmaster"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@@valid_names = {
|
|
53
|
+
"bronze" => { "colour" => 172, "value" => 0 },
|
|
54
|
+
"silver" => { "colour" => 247, "value" => 1 },
|
|
55
|
+
"gold" => { "colour" => 220, "value" => 2 },
|
|
56
|
+
"platinum" => { "colour" => 75 , "value" => 3 },
|
|
57
|
+
"diamond" => { "colour" => 27 , "value" => 4 },
|
|
58
|
+
"master" => { "colour" => 45 , "value" => 5 },
|
|
59
|
+
"grandmaster" => { "colour" => 202, "value" => 6 }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@@valid_types = {
|
|
63
|
+
"1v1" => { "random" => false, "value" => 201 },
|
|
64
|
+
"2v2" => { "random" => true , "value" => 202 },
|
|
65
|
+
"3v3" => { "random" => true , "value" => 203 },
|
|
66
|
+
"4v4" => { "random" => true , "value" => 204 }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
###############################################################################
|
|
70
|
+
|
|
71
|
+
@configuration
|
|
72
|
+
|
|
73
|
+
###############################################################################
|
|
74
|
+
|
|
75
|
+
@name
|
|
76
|
+
@random
|
|
77
|
+
@region
|
|
78
|
+
@season
|
|
79
|
+
@type
|
|
80
|
+
|
|
81
|
+
###############################################################################
|
|
82
|
+
|
|
83
|
+
def initialize(configuration:, options:)
|
|
84
|
+
@configuration = configuration
|
|
85
|
+
|
|
86
|
+
name = nil
|
|
87
|
+
random = nil
|
|
88
|
+
region = nil
|
|
89
|
+
season = nil
|
|
90
|
+
type = nil
|
|
91
|
+
|
|
92
|
+
OptionParser.new do |opts|
|
|
93
|
+
opts.banner = "Usage: #{$0} #{self.class.name.split("::").last.downcase} [options]"
|
|
94
|
+
|
|
95
|
+
opts.on("-h", "--help", "Prints this help") do
|
|
96
|
+
@@console.info(opts)
|
|
97
|
+
exit
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
opts.on("-n", "--name NAME", String, "League name, such as 'gold' or 'silver'.") do |value|
|
|
101
|
+
name = value
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
opts.on("-r", "--region REGION", String, "Region name, such as 'eu' or 'us'. Use configuration region by default.") do |value|
|
|
105
|
+
region = Shared::Region.new(name: value)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
opts.on("-R", "--[no-]random", "Specify for randomly assigned teams. Default is arranged teams.") do |value|
|
|
109
|
+
random = value
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
opts.on("-s", "--season SEASON", Integer, "Season number.") do |value|
|
|
113
|
+
season = value
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
opts.on("-t", "--type TYPE", String, "League type, such as '1v1' or '2v2'. Default is '1v1'.") do |value|
|
|
117
|
+
type = value
|
|
118
|
+
end
|
|
119
|
+
end.parse!
|
|
120
|
+
|
|
121
|
+
random ||= @@random
|
|
122
|
+
region ||= @configuration.region
|
|
123
|
+
type ||= @@type
|
|
124
|
+
|
|
125
|
+
@@console.fatal("League name must be specified!") unless name.kind_of?(String)
|
|
126
|
+
|
|
127
|
+
@@console.fatal("Specified league name: #{name} is not valid!") unless @@valid_codes.key?(name)
|
|
128
|
+
@@console.fatal("Specified league type: #{type} is not valid!") unless @@valid_types.key?(type)
|
|
129
|
+
|
|
130
|
+
name = @@valid_codes[name]
|
|
131
|
+
|
|
132
|
+
@@console.fatal("Leagues name resolved from code: #{name} is not valid! This should never happen...") unless @@valid_names.key?(name)
|
|
133
|
+
|
|
134
|
+
if random then
|
|
135
|
+
@@console.fatal("There are no randomly assigned teams for leagues of type: #{type}!") unless @@valid_types[type]["random"]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
unless season.kind_of?(Integer) then
|
|
139
|
+
current_season = Shared::Season.new(configuration: @configuration, region: region)
|
|
140
|
+
season = current_season.id
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
@name = name
|
|
144
|
+
@random = random
|
|
145
|
+
@region = region
|
|
146
|
+
@season = season
|
|
147
|
+
@type = type
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
###############################################################################
|
|
151
|
+
|
|
152
|
+
def run
|
|
153
|
+
@@console.info("Finding league information:")
|
|
154
|
+
@@console.info(" - Name : #{@name}")
|
|
155
|
+
@@console.info(" - Random: #{@random.to_s}")
|
|
156
|
+
@@console.info(" - Region: #{@region.description}")
|
|
157
|
+
@@console.info(" - Season: #{@season.to_s}")
|
|
158
|
+
@@console.info(" - Type : #{@type}")
|
|
159
|
+
|
|
160
|
+
api_name = @@valid_names[@name]["value"].to_s
|
|
161
|
+
api_random = @random ? "1" : "0"
|
|
162
|
+
api_season = @season.to_s
|
|
163
|
+
api_type = @@valid_types[@type]["value"].to_s
|
|
164
|
+
|
|
165
|
+
colour = @@valid_names[@name]["colour"]
|
|
166
|
+
|
|
167
|
+
path = "#{@@prefix}/#{api_season}/#{api_type}/#{api_random}/#{api_name}"
|
|
168
|
+
|
|
169
|
+
api = Shared::Api.new(configuration: @configuration, region: @region)
|
|
170
|
+
|
|
171
|
+
result = api.get(path: path)
|
|
172
|
+
|
|
173
|
+
tiers = LeagueShared::LeagueTiers.new(name: @name, colour: colour, json: result)
|
|
174
|
+
|
|
175
|
+
@@console.info(tiers.to_s)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
###############################################################################
|
|
179
|
+
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
###############################################################################
|
|
183
|
+
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
###############################################################################
|
|
187
|
+
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
###############################################################################
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
|
|
3
|
+
module SC2Cli
|
|
4
|
+
|
|
5
|
+
###############################################################################
|
|
6
|
+
|
|
7
|
+
module Subcommands
|
|
8
|
+
|
|
9
|
+
###############################################################################
|
|
10
|
+
|
|
11
|
+
module LeagueShared
|
|
12
|
+
|
|
13
|
+
###############################################################################
|
|
14
|
+
|
|
15
|
+
class LeagueTier
|
|
16
|
+
|
|
17
|
+
###############################################################################
|
|
18
|
+
|
|
19
|
+
@@console = Shared::Console.instance
|
|
20
|
+
|
|
21
|
+
###############################################################################
|
|
22
|
+
|
|
23
|
+
@@mmr_min = 0
|
|
24
|
+
@@mmr_max = 0
|
|
25
|
+
|
|
26
|
+
###############################################################################
|
|
27
|
+
|
|
28
|
+
@mmr_min
|
|
29
|
+
@mmr_max
|
|
30
|
+
|
|
31
|
+
###############################################################################
|
|
32
|
+
|
|
33
|
+
attr_reader :colour
|
|
34
|
+
attr_reader :id
|
|
35
|
+
attr_reader :league
|
|
36
|
+
attr_reader :number
|
|
37
|
+
|
|
38
|
+
###############################################################################
|
|
39
|
+
|
|
40
|
+
def initialize(league:, colour:, json:)
|
|
41
|
+
@@console.fatal("Returned league information for: #{league} has a tier with a missing ID!") unless json.key?("id")
|
|
42
|
+
|
|
43
|
+
id = json["id"]
|
|
44
|
+
|
|
45
|
+
@@console.fatal("Returned league information for: #{league} has a tier with an ID that is not an integer!") unless id.kind_of?(Integer)
|
|
46
|
+
@@console.fatal("Returned league information for: #{league} has a tier with an ID that is invalid!") unless id >= 0
|
|
47
|
+
|
|
48
|
+
@id = id
|
|
49
|
+
@league = league
|
|
50
|
+
@number = id + 1
|
|
51
|
+
@colour = colour
|
|
52
|
+
|
|
53
|
+
if json.key?("min_rating") then
|
|
54
|
+
mmr_min = json["min_rating"]
|
|
55
|
+
@mmr_min = mmr_min if mmr_min.kind_of?(Integer)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
if json.key?("max_rating") then
|
|
59
|
+
mmr_max = json["max_rating"]
|
|
60
|
+
@mmr_max = mmr_max if mmr_max.kind_of?(Integer)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
@mmr_min ||= @@mmr_min
|
|
64
|
+
@mmr_max ||= @@mmr_max
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
###############################################################################
|
|
68
|
+
|
|
69
|
+
def lower
|
|
70
|
+
return @mmr_min
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
###############################################################################
|
|
74
|
+
|
|
75
|
+
def upper
|
|
76
|
+
return @mmr_max
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
###############################################################################
|
|
80
|
+
|
|
81
|
+
def to_s
|
|
82
|
+
result = String.new
|
|
83
|
+
|
|
84
|
+
mmr_min = @mmr_min > 0 ? @mmr_min.to_s : "Unknown"
|
|
85
|
+
mmr_max = @mmr_max > 0 ? @mmr_max.to_s : "Unknown"
|
|
86
|
+
|
|
87
|
+
result += "-------------------------------------------------------------------------------\n"
|
|
88
|
+
result += "League: #{@@console.format(colour: @colour, message: "#{@league} #{@number}")}\n"
|
|
89
|
+
result += "-------------------------------------------------------------------------------\n"
|
|
90
|
+
result += "Maximum MMR: #{@@console.format(colour: @colour, message: mmr_max)}\n"
|
|
91
|
+
result += "Minimum MMR: #{@@console.format(colour: @colour, message: mmr_min)}\n\n"
|
|
92
|
+
|
|
93
|
+
return result
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
###############################################################################
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
###############################################################################
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
###############################################################################
|
|
105
|
+
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
###############################################################################
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
###############################################################################
|