public static async Task <Rank> GetCurrentRank(string UplayID) { TrackerDataSnippet data = await TRNHttpProvider.GetData(UplayID); Rank r = data.ToRank(); return(r); }
public async Task TrackUser(DiscordGuild g, ulong discordID, string uplayNickname, string relevantChannelName) { try { // SocketGuildUser trackedPerson = g.GetSingleUser(discordID); string queryR6ID = await _data.QueryMapping(discordID); if (queryR6ID != null) { await g.ReplyToUser("Vas discord ucet uz sledujeme. / We are already tracking your Discord account.", relevantChannelName, discordID); return; } string r6TabId = await TRNHttpProvider.GetID(uplayNickname); if (r6TabId == null) { await g.ReplyToUser("Nepodarilo se nam najit vas Uplay ucet. / We failed to find your Uplay account data.", relevantChannelName, discordID); return; } await _data.InsertIntoMapping(discordID, r6TabId); await g.ReplyToUser($"Nove sledujeme vase uspechy pod prezdivkou {uplayNickname} na platforme PC. / We now track you as {uplayNickname} on PC.", relevantChannelName, discordID); // Update the newly added user. bool ret = await Bot.Instance.UpdateOne(discordID); if (ret) { // Print user's rank too. Rank r = await TRNHttpProvider.GetCurrentRank(r6TabId); if (r.Digits()) { await g.ReplyToUser($"Aktualne vidime vas rank jako {r.FullPrint()}", relevantChannelName, discordID); } else { await g.ReplyToUser($"Aktualne vidime vas rank jako {r.CompactFullPrint()}", relevantChannelName, discordID); } } else { await g.ReplyToUser("Stala se chyba pri nastaven noveho ranku.", relevantChannelName, discordID); } } catch (RankParsingException e) { await g.ReplyToUser("Communication to the R6Tab server failed. Please try again or contact the local Discord admins.", relevantChannelName, discordID); await g.Reply("Pro admina: " + e.Message, relevantChannelName); } }
public async Task Uplay(string discordNick) { if (!await InstanceCheck()) { return; } var author = (Discord.WebSocket.SocketGuildUser)Context.Message.Author; DiscordGuild contextGuild = Bot.Instance.guilds.byID[Context.Guild.Id]; var target = contextGuild.GetSingleUser(discordNick); if (target == null) { await ReplyAsync(author.Username + ": Nenasli jsme cloveka ani podle prezdivky, ani podle Discord jmena."); return; } if (Bot.Instance._data.DiscordUplay.ContainsKey(target.Id)) { string uplayId = Bot.Instance._data.DiscordUplay[target.Id]; // This is only the uplay id, the user name might be different. We have to query a tracker to get the current // Uplay user name. string uplayName = ""; try { uplayName = await TRNHttpProvider.GetCurrentUplay(uplayId); if (uplayName == null || uplayName.Length == 0) { throw new RankParsingException("Returned uplayName is empty."); } } catch (Exception r) { await ReplyAsync(author.Username + ": Nepodarilo se ziskat prezdivku z trackeru."); await ReplyAsync("Admin info: " + r.Message); return; } await ReplyAsync($"{author.Username}: Clen {discordNick} se na Uplayi jmenuje \"{uplayName}\"."); return; } else { await ReplyAsync(author.Username + ": Discord uzivatel " + discordNick + " existuje, ale nenasli jsme ho v databazi ranku."); return; } }
public async Task Update() { if (!await InstanceCheck()) { return; } try { var author = (Discord.WebSocket.SocketGuildUser)Context.Message.Author; string authorR6TabId = await Bot.Instance._data.QueryMapping(author.Id); if (authorR6TabId == null) { await ReplyAsync(author.Username + ": vas rank netrackujeme, tak nemuzeme slouzit."); return; } bool ret = await Bot.Instance.UpdateOne(author.Id); if (ret) { await ReplyAsync(author.Username + ": Aktualizovali jsme vase MMR a rank. Nezapomente, ze to jde jen jednou za 30 minut."); // Print user's rank too. Rank r = await TRNHttpProvider.GetCurrentRank(authorR6TabId); if (r.Digits()) { await ReplyAsync(author.Username + ": Aktualne vidime vas rank jako " + r.FullPrint()); } else { await ReplyAsync(author.Username + ": Aktualne vidime vas rank jako " + r.CompactFullPrint()); } } else { await ReplyAsync(author.Username + ": Stala se chyba pri aktualizaci ranku, mate stale predchozi rank."); } } catch (RankParsingException) { await ReplyAsync("Communication to the R6Tab server failed. Please try again or contact the local Discord admins."); return; } }
public async Task QueryMMRAsync(string discordNick) { if (!await InstanceCheck()) { return; } var author = (Discord.WebSocket.SocketGuildUser)Context.Message.Author; DiscordGuild contextGuild = Bot.Instance.guilds.byID[Context.Guild.Id]; var target = contextGuild.GetSingleUser(discordNick); if (target == null) { await ReplyAsync(author.Username + ": Nenasli jsme cloveka ani podle prezdivky, ani podle Discord jmena."); return; } if (Bot.Instance._data.DiscordUplay.ContainsKey(target.Id)) { string uplayId = Bot.Instance._data.DiscordUplay[target.Id]; int mmr = -1; try { mmr = await TRNHttpProvider.GetCurrentMMR(uplayId); if (mmr < 0) { throw new RankParsingException("Returned MMR is less than 0, that is almost surely wrong."); } } catch (Exception r) { await ReplyAsync(author.Username + ": Nepodarilo se ziskat MMR z trackeru."); await ReplyAsync("Admin info: " + r.Message); return; } await ReplyAsync($"{author.Username}: Clen {discordNick} ma {mmr} MMR."); return; } else { await ReplyAsync(author.Username + ": Discord uzivatel " + discordNick + " existuje, ale nenasli jsme ho v databazi ranku."); return; } }
// Call RefreshRank() only when you hold the mutex to the internal dictionaries. private async Task RefreshRank(ulong discordID, string r6TabID) { try { TrackerDataSnippet data = await TRNHttpProvider.UpdateAndGetData(r6TabID); Rank fetchedRank = data.ToRank(); bool updateRequired = true; if (await _data.TrackingContains(discordID)) { Rank curRank = await _data.QueryRank(discordID); if (curRank.Equals(fetchedRank)) { updateRequired = false; } else { Console.WriteLine("The fetched rank and the stored rank disagree for the user " + discordID); Console.WriteLine($"The fetched rank equals {fetchedRank} and the stored rank is {curRank}."); } } else { Console.WriteLine("The user with DiscordID " + discordID + " is not yet in the database of ranks."); } if (updateRequired) { await _data.UpdateRanks(discordID, fetchedRank); await UpdateRoles(discordID, fetchedRank); } else { // System.Console.WriteLine("Ranks match for player " + player.Username); } } catch (RankParsingException) { Console.WriteLine("Failed to update rank for player " + discordID); } catch (System.Net.Http.HttpRequestException) { Console.WriteLine("Network unrechable, delaying update."); return; } }
public async Task Rank() { if (!await InstanceCheck()) { return; } var author = (Discord.WebSocket.SocketGuildUser)Context.Message.Author; string authorR6TabId = await Bot.Instance._data.QueryMapping(author.Id); if (authorR6TabId == null) { await ReplyAsync(author.Username + ": vas rank netrackujeme, tak nemuzeme slouzit."); return; } else { try { Rank r = await TRNHttpProvider.GetCurrentRank(authorR6TabId); if (r.Digits()) { await ReplyAsync(author.Username + ": Aktualne vidime vas rank jako " + r.FullPrint()); } else { await ReplyAsync(author.Username + ": Aktualne vidime vas rank jako " + r.CompactFullPrint()); } } catch (RankParsingException) { await ReplyAsync("Communication to the R6Tab server failed. Please try again or contact the Discord admins."); } } }
public async Task Track(string nick) { if (!await InstanceCheck()) { return; } var author = (Discord.WebSocket.SocketGuildUser)Context.Message.Author; try { string queryR6ID = await Bot.Instance._data.QueryMapping(author.Id); if (queryR6ID != null) { await ReplyAsync(author.Username + ": Vas discord ucet uz sledujeme. / We are already tracking your Discord account."); return; } string r6TabId = await TRNHttpProvider.GetID(nick); if (r6TabId == null) { await ReplyAsync(author.Username + ": Nepodarilo se nam najit vas Uplay ucet. / We failed to find your Uplay account data."); return; } await Bot.Instance._data.InsertIntoMapping(author.Id, r6TabId); await ReplyAsync(author.Username + ": nove sledujeme vase uspechy pod prezdivkou " + nick + " na platforme PC. / We now track you as " + nick + " on PC."); // Update the newly added user. bool ret = await Bot.Instance.UpdateOne(author.Id); if (ret) { // Print user's rank too. Rank r = await TRNHttpProvider.GetCurrentRank(r6TabId); if (r.Digits()) { await ReplyAsync(author.Username + ": Aktualne vidime vas rank jako " + r.FullPrint()); } else { await ReplyAsync(author.Username + ": Aktualne vidime vas rank jako " + r.CompactFullPrint()); } } else { await ReplyAsync(author.Username + ": Stala se chyba pri nastaven noveho ranku."); } } catch (RankParsingException) { await ReplyAsync("Communication to the R6Tab server failed. Please try again or contact the local Discord admins."); return; } }