From e8bf4d3004d26b8d5fe04c7f58352a0b0705ce4a Mon Sep 17 00:00:00 2001 From: Toastie Date: Fri, 27 Dec 2024 02:01:09 +1300 Subject: [PATCH] Added tickets where the user has left to /admin listinvalid --- Commands/AdminCommands.cs | 23 +++++++++++++++++------ Logger.cs | 9 ++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Commands/AdminCommands.cs b/Commands/AdminCommands.cs index a52d753..1c8686b 100644 --- a/Commands/AdminCommands.cs +++ b/Commands/AdminCommands.cs @@ -47,16 +47,27 @@ public class AdminCommands } // Check which tickets channels no longer exist - List listItems = new List(); + List invalidTickets = new List(); foreach (Database.Ticket ticket in openTickets) { - if (allChannels.All(channel => channel.Id != ticket.channelID)) + DiscordChannel channel = allChannels.FirstOrDefault(c => c.Id == ticket.channelID); + if (channel == null) { - listItems.Add("ID: **" + ticket.id.ToString("00000") + ":** <#" + ticket.channelID + ">\n"); + invalidTickets.Add("**`ticket-" + ticket.id.ToString("00000") + ":`** Channel no longer exists (<#" + ticket.channelID + ">)\n"); + continue; + } + + try + { + await channel.Guild.GetMemberAsync(ticket.creatorID); + } + catch (NotFoundException) + { + invalidTickets.Add("**`ticket-" + ticket.id.ToString("00000") + ":`** Creator has left (<#" + ticket.channelID + ">)\n"); } } - if (listItems.Count == 0) + if (invalidTickets.Count == 0) { await command.RespondAsync(new DiscordEmbedBuilder { @@ -67,7 +78,7 @@ public class AdminCommands } List embeds = new List(); - foreach (string message in Utilities.ParseListIntoMessages(listItems)) + foreach (string message in Utilities.ParseListIntoMessages(invalidTickets)) { embeds.Add(new DiscordEmbedBuilder { @@ -145,7 +156,7 @@ public class AdminCommands [Command("unsetticket")] [Description("Deletes a ticket from the ticket system without deleting the channel.")] public async Task UnsetTicket(SlashCommandContext command, - [Parameter("ticket-id")][Description("(Optional) Ticket to unset. Uses the channel you are in by default.")] long ticketID = 0) + [Parameter("ticket-id")][Description("(Optional) Ticket to unset. Uses the channel you are in by default. Use ticket ID, not channel ID!")] long ticketID = 0) { Database.Ticket ticket; diff --git a/Logger.cs b/Logger.cs index 3547132..9d59993 100644 --- a/Logger.cs +++ b/Logger.cs @@ -1,5 +1,7 @@ using Microsoft.Extensions.Logging; using System; +using DSharpPlus; +using DSharpPlus.Exceptions; namespace SupportChild; @@ -76,7 +78,12 @@ public class Logger : ILogger return; // Ratelimit messages are usually warnings, but they are unimportant in this case so downgrade them to debug. - if (formatter(state, exception).StartsWith("Hit Discord ratelimit on route ")) + if (formatter(state, exception).StartsWith("Hit Discord ratelimit on route ") && logLevel == LogLevel.Warning) + { + logLevel = LogLevel.Debug; + } + // The bot will handle NotFoundExceptions on its own, downgrade to debug + else if (exception is NotFoundException && eventId == LoggerEvents.RestError) { logLevel = LogLevel.Debug; }