Пример #1
0
        public async Task ProfileAsync()
        {
            var id          = Context.User.Id;
            var color       = Color.Red;
            var description = "You are not registered!";
            var embed       = new LocalEmbedBuilder()
                              .WithTitle("User profile");
            var player = ContrackerService.Contracker
                         .GetPlayer(discordId: id.ToString());

            if (player != null)
            {
                description = "You are gamer.";
                color       = Color.Green;
                var steamname = SteamService.GetSteamName(player.Steam);
                embed.AddField("Discord", Discord.MentionUser(Context.User))
                .AddField("Steam", $"[{steamname}](https://steamcommunity.com/profiles/{player.Steam})")
                .AddField("Total CP", player.Cp)
                .AddField("Stars", player.Stars);
            }

            await ReplyAsync(embed : embed
                             .WithDescription(description)
                             .WithColor(color)
                             .Build()).ConfigureAwait(true);
        }
Пример #2
0
        public async Task RegisterAsync(int accountNumber = -1)
        {
            Snowflake id    = Context.User.Id;
            var       users = DUserService.GetAccounts(id).Result;
            string    title;
            string    description;
            var       player = ContrackerService.GetPlayer(discordId: id.ToString());

            if (player == null)
            {
                switch (users.Count)
                {
                case 0:
                    title       = "Fail";
                    description = "`No Steam accounts associated with your account.`\n" +
                                  "[Go here](https://www.quora.com/How-will-I-add-my-gaming-accounts-in-Discord) " +
                                  "to see how to link your Steam account. You may unlink your account once you register.";
                    break;

                case 1:
                    if (DUserService.IsVerified(id).Result)
                    {
                        try
                        {
                            title       = "Success";
                            description = "`API request sent...`";
                            ContrackerService.Contracker.CreatePlayer(users.First(), id.ToString());
                        }
                        catch (XmlException e)
                        {
                            title       = "Fail";
                            description = "`An error has occured. Probably server's fault.`";
                            Console.WriteLine(e);
                        }
                    }
                    else
                    {
                        title       = "Fail";
                        description = "`Your Steam account is not verified.`\n" +
                                      "[Go here](https://www.reddit.com/r/discordapp/comments/6elfxl/its_now_possible_to_have_a_verified_steam_account/) " +
                                      "to see how to verify your Steam account.";
                    }

                    break;

                default:
                    if (accountNumber != -1 && accountNumber < users.Count)
                    {
                        title       = "Success";
                        description = "`Pretend this sends an API request...`\nwith account " +
                                      $"`{SteamService.GetSteamName(users[accountNumber]).Replace("`", "")}` " +
                                      $"or steamid `{users[accountNumber]}`";
                    }
                    else
                    {
                        title       = "Fail";
                        description = "`You have multiple linked Steam accounts.`\n" +
                                      "Use command `!register n` and replace `n` with the correct account number shown below." +
                                      "```\n" +
                                      string.Join("\n",
                                                  users.Select((x, index) =>
                                                               $"{index} - {SteamService.GetSteamName(x).Replace("`", "")}")) +
                                      "```";
                    }
                    break;
                }
            }
            else
            {
                title       = "You are already registered!";
                description = "You are registered on Steam account " +
                              $"`{SteamService.GetSteamName(player.Steam)}`";
            }
            await ReplyAsync(embed : new LocalEmbedBuilder()
                             .WithTitle(title)
                             .WithDescription(description)
                             .WithColor(Color.Honeydew)
                             .Build()).ConfigureAwait(true);
        }