-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_match_teams.rb
More file actions
95 lines (76 loc) · 2.17 KB
/
verify_match_teams.rb
File metadata and controls
95 lines (76 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require 'pry'
require 'yaml'
require 'digest'
require 'httparty'
require 'discordrb'
creds = YAML.load_file '../secrets.yml'
DEV_ID = creds[:dev_id]
AUTH_KEY = creds[:auth_key]
def make_sig method, timestamp
Digest::MD5.hexdigest(
DEV_ID +
method +
AUTH_KEY +
timestamp
)
end
def base_url method, sig
"http://api.realmroyale.com/realmapi.svc/" +
method +
'/' +
DEV_ID +
'/' +
sig +
'/'
end
timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
sig = make_sig 'createsession', timestamp
session_url = base_url('CreateSessionJSON', sig) + timestamp
response = HTTParty.get session_url
session_id = response['session_id']
teams = YAML.load_file 'teams.yml'
lobbies = {}
teams.each do |team|
team[:players].each do |player|
begin
name = URI.escape player
player_uri = "#{session_id}/#{timestamp}/#{name}"
sig = make_sig 'searchplayers', timestamp
search_uri = base_url('SearchPlayersJSON', sig)
response = HTTParty.get search_uri + player_uri
player_id = response.first['id'].to_s
sig = make_sig 'getplayerstatus', timestamp
status_uri = base_url('GetPlayerStatusJSON', sig)
response = HTTParty.get status_uri + player_uri
match_id = response['match_id']
#skip since they aren't in a game
next if match_id == 0
game = lobbies[match_id]
if game.nil?
lobbies[match_id] = [team[:name]]
else
lobbies[match_id] = game << team[:name]
end
break
rescue
next
end
end
end
#for each lobbie
# for each team
# find players
bot = Discordrb::Bot.new(token: '', client_id: )
lobbies.each_with_index do |game, i|
fields = game[1].map do |team_name|
players = teams.select {|team| team[:name] == team_name}.first[:players]
player_string = players.join("\n")
{
name: team_name, value: player_string, inline:true
}
end
bot.send_message(, '', false, {
color: 3447003,
fields: fields
})
end