Added raffle clear command and permission node.

This commit is contained in:
Sean "Solao Bajiuik" Stoves 2020-08-08 23:03:09 -04:00
parent 59b6ff0569
commit f9b5531b47

View File

@ -71,6 +71,10 @@ namespace ChaosBot.Discord.Modules.User
{ {
await TotalRaffle(); await TotalRaffle();
} }
else if ((cmd.ToLower() == "clear") && (await CheckPermissions.CheckPerms(Context, "points.clear", "Admin")))
{
await ClearRaffle(userMention);
}
else else
{ {
await RaffleHelp(); await RaffleHelp();
@ -264,6 +268,46 @@ namespace ChaosBot.Discord.Modules.User
false); false);
} }
public async Task ClearRaffle(string confirm = null)
{
try
{
if(confirm == "confirm")
{
using (ChaosbotContext dbContext = new ChaosbotContext())
{
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
IQueryable<Raffle> 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<string>("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() public async Task PickRaffle()
{ {
try try