Exemplo n.º 1
0
        public async Task PurgePlayer(CommandContext ctx, [Description("Player Id")] long playerId)
        {
            await ctx.TriggerTypingAsync();

            var userId = ctx.User?.Id ?? 0;

            Log.Info($"Requesting {nameof(GetPlayerById)}({playerId}) by {userId}...");
            if (userId != _coder)
            {
                var emoji = DiscordEmoji.FromName(ctx.Client, ":no_entry:");
                var embed = new DiscordEmbedBuilder
                {
                    Title       = "Access denied",
                    Description = $"{emoji} You may be a *coder*, but you are not **The Coder**!",
                    Color       = DiscordColor.Red
                };

                await ctx.RespondAsync("", embed : embed);

                return;
            }

            try
            {
                var provider = new DbProvider(_connectionString);
                var player   = provider.GetPlayer(playerId);
                if (player == null)
                {
                    await ctx.RespondAsync($"There is no player on the database with the id `{playerId}`.");

                    return;
                }

                await ctx.RespondAsync($"The id `{playerId}` corresponds to the tanker `{player.Name}` on the `{player.Platform}`...");

                var recorder = new DbRecorder(_connectionString);
                recorder.PurgePlayer(playerId);

                await ctx.RespondAsync($"The tanker `{player.Name}` on `{player.Platform}` was purged from the database. Rip.");
            }
            catch (Exception ex)
            {
                Log.Error($"{nameof(GetDbStatus)}", ex);
                await ctx.RespondAsync(
                    $"Sorry, {ctx.User?.Mention}. There was an error... the *Coder* will be notified of `{ex.Message}`.");
            }
        }