Пример #1
0
        public static async Task CheckHiScores()
        {
            Console.WriteLine("Updating hiscores");
            var manager = new HiscoresManager();
            var players = new List<string>(Data.Usernames);
            foreach (var player in players)
            {
                try
                {
                    await manager.Get(player);
                }
                catch{};
            }

            var totLevel = 0;
            var totXp = 0;

            var newAverage = new Player("Average");

            foreach (var skill in Data.Skills)
            {
                var xp = Data.AllPlayers.Values.Sum(x => x.Levels[skill].Xp) / Data.AllPlayers.Count;
                var level = GetLevel(xp);

                totXp += xp;
                totLevel += level;

                newAverage.Levels[skill] = new Stat(level, xp);
            }

            newAverage.TotalLevel = new Stat(totLevel, totXp);
            var message = newAverage.CompareLevels(Data.AveragePlayer);
            if (string.IsNullOrEmpty(message))
            {
                Data.AveragePlayer = newAverage;
                return;
            }
            var channel = await discord.GetChannelAsync(config.Channel);
            await channel.SendMessageAsync(message);

            Data.AveragePlayer = newAverage;
        }
Пример #2
0
        public static async Task ParseMessage(MessageCreateEventArgs e)
        {
            if (!e.Message.Content.StartsWith("!rhs"))
            {
                return;
            }
            var msg = e.Message.Content.ToLower().Substring(5);

            var res = "**Command not found**";

            if (msg == "commands" || msg == "help")
            {
                var builder = new StringBuilder();
                builder.AppendLine("**Bot commands:**");
                builder.AppendLine("1. !rhs <skill name>");
                builder.AppendLine("2. !rhs <clue level or all>");
                builder.AppendLine("3. !rhs <boss name>");
                builder.AppendLine("4. !rhs total");
                builder.AppendLine("5. !rhs points");
                builder.AppendLine("6. !rhs average");

                builder.AppendLine("!rhs help skills - Returns a list of skill names");
                builder.AppendLine("!rhs help bosses - Returns a list of boss names");

                res = builder.ToString();
            }

            if (msg.StartsWith("help") && msg != "help")
            {
                msg = msg.Substring(5);
                var builder = new StringBuilder();
                switch (msg)
                {
                case "skills":
                {
                    foreach (var x in Data.Skills)
                    {
                        builder.Append($"{x},");
                    }

                    builder.Length -= 1;
                    res             = builder.ToString();
                    break;
                }

                case "bosses":
                {
                    foreach (var x in Data.Bosses)
                    {
                        builder.Append($"{x},");
                    }

                    builder.Length -= 1;
                    res             = builder.ToString();
                    break;
                }
                }
            }

            if (msg.StartsWith("add"))
            {
                var player = msg.Substring(4);
                if (!Data.Usernames.Select(x => x.ToLower()).Contains(player.ToLower()))
                {
                    Data.Usernames.Add(player);
                    var hs = new HiscoresManager();
                    await hs.Get(player);

                    res = $"Added {player}";
                }
                else
                {
                    res = $"Account with name {player} has already been added";
                }
            }
            if (msg.StartsWith("remove"))
            {
                var player = msg.Substring(7);
                if (Data.Usernames.Select(x => x.ToLower()).Contains(player.ToLower()))
                {
                    var index = Data.Usernames.Select(x => x.ToLower()).ToList().IndexOf(player);
                    Data.Usernames.RemoveAt(index);
                    res = $"Removed {player}";
                }
                else
                {
                    res = $"No account with the name {player} found";
                }
            }

            if (msg == "usernames")
            {
                res = string.Join(',', Data.Usernames);
            }
            if (msg == "total")
            {
                res = GetTotals();
            }
            if (msg == "points")
            {
                res = GetPoints();
            }
            if (msg == "average")
            {
                res = GetAverage();
            }

            if (Data.Skills.Contains(msg))
            {
                res = GetLevels(msg);
            }
            if (Data.Bosses.Contains(msg))
            {
                res = GetBosses(msg);
            }
            if (Data.Clues.Contains(msg))
            {
                res = GetClues(msg);
            }

            await e.Message.RespondAsync(res);
        }