コード例 #1
0
        public async Task DeleteUserAward(string id = null)
        {
            if (id == null)
            {
                EmbedBuilder eb = new EmbedBuilder
                {
                    Title       = "Invalid Syntax",
                    Description = "**Syntax:** " + Guild.Load(Context.Guild.Id).Prefix + "deleteaward [id]",
                    Color       = new Color(210, 47, 33)
                }
                .WithCurrentTimestamp();

                await ReplyAsync("", false, eb.Build());

                return;
            }

            if (int.TryParse(id, out var aId))
            {
                Award award;

                try
                {
                    award = Award.GetAward(aId);
                }
                catch (AwardNotFoundException exception)
                {
                    await ReplyAsync(Context.User.Mention + ", I couldn't find an award with that ID. Please try again.");

                    await new LogMessage(LogSeverity.Warning, "AwardModule", exception.Message).PrintToConsole();
                    return;
                }

                AdminLog.Log(Context.User.Id, Context.Message.Content, Context.Guild.Id);

                EmbedBuilder awardEmbed = new EmbedBuilder()
                {
                    Title       = "Are you sure you wish to delete Award ID: " + award.AwardId,
                    Description = "You're about to delete the following award:",
                    Color       = new Color(255, 0, 0),
                    Footer      = new EmbedFooterBuilder()
                    {
                        Text = "Responding with anything but \"Confirm\" will cancel the operation."
                    }
                }
                .AddField("Award Category", award.AwardCategory)
                .AddField("Award", award.AwardText)
                .WithCurrentTimestamp();

                try
                {
                    awardEmbed.AddField("Awarded To", award.UserId.GetUser().Mention);
                }
                catch (UserNotFoundException exception)
                {
                    awardEmbed.AddField("Awarded To", award.UserId.ToString());
                    await new LogMessage(LogSeverity.Warning, "AwardModule", exception.Message).PrintToConsole();
                }

                awardEmbed
                .AddField("Date Awarded", award.DateAwarded.ToLongDateString())
                .AddField("Confirmation",
                          "If you wish to delete this award, please type \"Confirm\" into the chat, or type \"Cancel\" if you wish to cancel");

                await ReplyAsync("", false, awardEmbed.Build());

                var response = await NextMessageAsync();

                if (response != null)
                {
                    if (response.Content.ToUpper() == "CONFIRM")
                    {
                        AdminLog.Log(Context.User.Id, Context.Message.Content + " confirm", Context.Guild.Id);

                        Award.DeleteAward(award.AwardId);

                        await ReplyAsync("Award ID: " + award.AwardId + " has been deleted.");
                    }
                    else if (response.Content.ToUpper() == "CANCEL")
                    {
                        await ReplyAsync(Context.User.Mention + ", the operation was cancelled successfully.");
                    }
                    else
                    {
                        await ReplyAsync(Context.User.Mention + ", we've cancelled the deleteaward operation as none of the keywords were mentioned.");
                    }
                }
                else
                {
                    await ReplyAsync(Context.User.Mention + ", you didn't reply before the timeout, therefore the operation has been automatically cancelled.");
                }
            }
            else
            {
                EmbedBuilder eb = new EmbedBuilder
                {
                    Title       = "Invalid Syntax",
                    Description = "**Syntax:** " + Guild.Load(Context.Guild.Id).Prefix + "deleteaward [id]",
                    Color       = new Color(210, 47, 33),
                    Footer      = new EmbedFooterBuilder()
                    {
                        Text = "You can use the command listawards to find the ID's of the quotes."
                    }
                }
                .WithCurrentTimestamp();

                await ReplyAsync("", false, eb.Build());
            }
        }