From f9b5531b476948f9ef62b0e2e5406f415262fdaa Mon Sep 17 00:00:00 2001 From: Sean Stoves Date: Sat, 8 Aug 2020 23:03:09 -0400 Subject: [PATCH] Added raffle clear command and permission node. --- ChaosBot/Discord/Modules/User/RaffleCmd.cs | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/ChaosBot/Discord/Modules/User/RaffleCmd.cs b/ChaosBot/Discord/Modules/User/RaffleCmd.cs index 0662647..b449273 100644 --- a/ChaosBot/Discord/Modules/User/RaffleCmd.cs +++ b/ChaosBot/Discord/Modules/User/RaffleCmd.cs @@ -71,6 +71,10 @@ namespace ChaosBot.Discord.Modules.User { await TotalRaffle(); } + else if ((cmd.ToLower() == "clear") && (await CheckPermissions.CheckPerms(Context, "points.clear", "Admin"))) + { + await ClearRaffle(userMention); + } else { await RaffleHelp(); @@ -264,6 +268,46 @@ namespace ChaosBot.Discord.Modules.User false); } + public async Task ClearRaffle(string confirm = null) + { + try + { + if(confirm == "confirm") + { + using (ChaosbotContext dbContext = new ChaosbotContext()) + { + IQueryable ctxRaffles = dbContext.Raffles; + + IQueryable ctxRaffleDetail = ctxRaffles + .Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)); + + int cur = ctxRaffleDetail.Count(); + + if (cur != 0) + { + dbContext.Raffles.RemoveRange(ctxRaffleDetail); + await dbContext.SaveChangesAsync(); + } + } + + await ReplyAsync( + $"{Context.User.Mention} has removed all tickets.", + false); + } + else + { + await ReplyAsync( + $"{Context.User.Mention}, if you wish to clear ALL tickets, please send the below command.```{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle clear confirm```", + false); + } + } + catch (Exception ex) + { + _logger.Error( + $"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); + } + } + public async Task PickRaffle() { try