private ulong GetRegionRole(RLRegion region) { switch (region) { case RLRegion.Europe: return(385785137960452106); case RLRegion.NorthAmerica: return(385780548016013312); case RLRegion.SouthAmerica: return(407255951406530561); case RLRegion.Oceania: return(407256306190385175); case RLRegion.AsiaCentral: return(407256310435020813); case RLRegion.MiddleEast: return(407256685074317322); case RLRegion.Africa: return(407256688610246660); } throw new ArgumentException("Invalid region."); }
public async Task LinkAsync([OverrideTypeReader(typeof(RLRegionTypeReader))] RLRegion region, [OverrideTypeReader(typeof(RLPlatformTypeReader))] RlsPlatform platform, [Remainder] string uniqueId) { await Context.Channel.TriggerTypingAsync(); var user = Context.Message.Author as SocketGuildUser; try { // check if discord id is already in the database if (await Database.GetUserInfoAsync(user.Id) != null) { await ReplyAsync($"{user.Mention}, you've already linked your rocket league account to your discord. If not all playlists are linked do `!link`."); return; } // try to retrieve the account info and show it to the user so he/she can confirm it's them var player = await _RLSClient.GetPlayerAsync(platform, uniqueId); if (player == null) { await ReplyAsync($"Failed to retrieve player information!"); return; } var embedBuilder = new EmbedBuilder() .WithColor(RLBot.EMBED_COLOR) .WithTitle($"Rocket League Stats") .AddField("Username", player.DisplayName) .WithThumbnailUrl(player.Avatar); if (!player.RankedSeasons.TryGetValue(Enum.GetValues(typeof(RlsSeason)).Cast <RlsSeason>().Max(), out var season)) { await ReplyAsync($"{user.Mention}, the following account was found, but no information could be retrieved for the current season.", false, embedBuilder.Build()); return; } List <IRole> roles = new List <IRole>(); int rp1 = -1; if (season.TryGetValue(RlsPlaylistRanked.Duel, out PlayerRank duel)) { embedBuilder.AddField("1V1", GetRankString(duel.Tier) + $" ({duel.RankPoints})", true); rp1 = duel.RankPoints; roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Duel, duel.RankPoints).RoleID)); } else { embedBuilder.AddField("1V1", "Unranked"); } int rp2 = -1; if (season.TryGetValue(RlsPlaylistRanked.Doubles, out PlayerRank doubles)) { embedBuilder.AddField("2V2", GetRankString(doubles.Tier) + $" ({doubles.RankPoints})", true); rp2 = doubles.RankPoints; roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Doubles, doubles.RankPoints).RoleID)); } else { embedBuilder.AddField("2V2", "Unranked"); } int rp3 = -1; if (season.TryGetValue(RlsPlaylistRanked.Standard, out PlayerRank standard)) { embedBuilder.AddField("3V3", GetRankString(standard.Tier) + $" ({standard.RankPoints})", true); rp3 = standard.RankPoints; roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Standard, standard.RankPoints).RoleID)); } else { embedBuilder.AddField("3V3", "Unranked"); } await ReplyAsync($"{user.Mention}, reply with yes if this is you. (Cannot be undone!)", false, embedBuilder.Build()); var msg = await NextMessageAsync(timeout : new TimeSpan(0, 0, 30)); if (msg == null) { await ReplyAsync("Message timed out.."); return; } else if (msg.Content.ToLower() != "yes" && msg.Content.ToLower() != "y") { await ReplyAsync($"{user.Mention}, account linking cancelled."); return; } // check if the user has all the required ranks if (rp1 == -1 && rp2 == -1 && rp3 == -1) { await ReplyAsync($"{user.Mention}, the accounts can't be linked untill you have received a rank in at least 1 playlist."); return; } // prepare the roles for the user roles.Add(Context.Guild.GetRole(GetRegionRole(region))); roles.Add(Context.Guild.GetRole(GetPlatformRole(platform))); // try to add the user to the database with their current elo await Database.InsertUserInfoAsync(user.Id, uniqueId, (short)rp1, (short)rp2, (short)rp3); // give the rolse to the user await user.AddRolesAsync(roles); await ReplyAsync($"Accounts linked succesfull!"); } catch (SqlException ex) when(ex.Number == 2627) { await ReplyAsync($"{user.Mention}, this account is already linked to someone else."); } catch (Exception ex) { await ReplyAsync($"{user.Mention}, " + ex.Message); } }