private static async Task <string> GetHighScoreTotalLevel(string rsUsername)
        {
            var streamData = await RSHighScoreHelper.TryGetStreamData(rsUsername);

            var lines         = RSHighScoreHelper.ReadLines(() => streamData).ToList();
            var skillDataList = RSHighScoreHelper.GetSkillTotalLevel(lines);

            return(skillDataList.ToString());
        }
Ejemplo n.º 2
0
        private static void SendNotificationByAccount(KeyValuePair <string, RSAccountData> keyPair, DiscordSocketClient client)
        {
            const string rs_log = "rs_log";

            var rsUsername     = keyPair.Key;
            var oldAccountData = keyPair.Value;

            var stream        = RSHighScoreHelper.TryGetStreamData(rsUsername).Result;
            var lines         = RSHighScoreHelper.ReadLines(() => stream).ToList();
            var skillDataList = RSHighScoreHelper.GetSkillDataList(lines);

            var totalLevel    = RSHighScoreHelper.CalculateTotalLevel(skillDataList);
            var oldTotalLevel = RSHighScoreHelper.CalculateTotalLevel(oldAccountData.SkillDataList);

            if (totalLevel > oldTotalLevel && oldTotalLevel != -1)
            {
                foreach (var serverId in oldAccountData.ServerIds)
                {
                    var guild = client.GetGuild(serverId);
                    if (guild == null)
                    {
                        Console.WriteLine($"Could not find a server with id '{serverId}'");
                        continue;
                    }

                    var channel = guild.TextChannels.SingleOrDefault(c => c.Name == rs_log);
                    if (channel == null)
                    {
                        Console.WriteLine($"Could not find a text channel named '{rs_log}' on the server named '{guild.Name}'");
                        continue;
                    }

                    channel.SendMessageAsync(embed: GetMessage(rsUsername, skillDataList, oldAccountData.SkillDataList, totalLevel, oldTotalLevel).Build()).Wait();
                }
            }
            ;
            _ListToUpdate.Add(new KeyValuePair <string, RSAccountData>(rsUsername, new RSAccountData(oldAccountData.ServerIds, skillDataList)));
        }