-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrants.rb
122 lines (106 loc) · 3.21 KB
/
entrants.rb
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
GUILD_ID = '737431333478989907'
PARTICIPANT_ROLE_ID = '957901704815345664'
EVENT_SLUG = 'tournament/tales-of-smash-lcq-x-smashth-que/event/tales-of-smash-lcq-x-smashth-que'
GraphData =
SmashggClient::CLIENT.parse <<-GRAPHQL
query($slug: String) {
event(slug: $slug){
entrants(query: {perPage: 500}) {
nodes {
name
participants {
user {
id
slug
}
requiredConnections {
externalId
}
}
}
}
}
}
GRAPHQL
response = SmashggClient::CLIENT.query(
GraphData,
variables: {
slug: EVENT_SLUG
}
)
players = response.data.event.entrants.nodes.filter_map do |entrant|
if entrant.participants.first.required_connections.first&.external_id
{
name: entrant.name,
smashgg_user_id: entrant.participants.first.user.id,
smashgg_user_slug: entrant.participants.first.user.slug,
discord_id: entrant.participants.first.required_connections.first.external_id
}
end
end
players.sort_by! { |player| player[:smashgg_user_id] }
# add @smashtheque_player_id
players.each do |player|
discord_user = DiscordUser.where(discord_id: player[:discord_id]).first
if discord_user&.player
player[:smashtheque_player_id] = discord_user.player.id
next
end
smashgg_user = SmashggUser.where(slug: player[:smashgg_user_slug]).first
if smashgg_user&.player
player[:smashtheque_player_id] = smashgg_user.player.id
end
end
# use @smashtheque_player_id
players.each do |player|
if player[:smashtheque_player_id]
smashtheque_player = Player.find(player[:smashtheque_player_id])
player[:track_records] = {
all: {
online: {
rank: smashtheque_player.rank(is_online: true),
points: smashtheque_player.points(is_online: true)
},
offline: {
rank: smashtheque_player.rank(is_online: false),
points: smashtheque_player.points(is_online: false)
}
}
}
TrackRecord.points_years.each do |year|
player[:track_records][year] = {
online: {
rank: smashtheque_player.rank(is_online: true, year: year),
points: smashtheque_player.points(is_online: true, year: year)
},
offline: {
rank: smashtheque_player.rank(is_online: false, year: year),
points: smashtheque_player.points(is_online: false, year: year)
}
}
end
end
end
# print
players.each do |player|
line = [
player[:smashgg_user_id],
"https://www.start.gg/#{player[:smashgg_user_slug]}",
player[:name],
player[:smashtheque_player_id]
]
if player[:smashtheque_player_id]
line << [
"https://www.smashtheque.fr/players/#{player[:smashtheque_player_id]}",
player[:track_records][:all][:online][:rank],
player[:track_records][:all][:online][:points],
player[:track_records][2021][:online][:rank],
player[:track_records][2022][:online][:rank]
]
end
puts line.join("\t")
end; nil
players.each do |player|
discord_user = DiscordUser.where(discord_id: player[:discord_id]).first_or_create
SmashggUser.where(slug: player[:smashgg_user_slug]).first_or_create
end; nil