diff --git a/Commands/AddCommand.cs b/Commands/AddCommand.cs index fc553d0..3e56175 100644 --- a/Commands/AddCommand.cs +++ b/Commands/AddCommand.cs @@ -5,6 +5,7 @@ using DSharpPlus.Commands; using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Entities; +using DSharpPlus.Exceptions; namespace SupportChild.Commands; @@ -30,7 +31,6 @@ public class AddCommand DiscordMember member; try { - // TODO: This throws an exception instead of returning null now member = (user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id)); if (member == null) @@ -62,12 +62,10 @@ public class AddCommand Description = "Added " + member.Mention + " to ticket." }); - // TODO: This throws an exception instead of returning null now - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, @@ -75,6 +73,10 @@ public class AddCommand " by " + command.Member?.Mention + "." }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } catch (Exception) { diff --git a/Commands/AddStaffCommand.cs b/Commands/AddStaffCommand.cs index 4e95b91..45b3f82 100644 --- a/Commands/AddStaffCommand.cs +++ b/Commands/AddStaffCommand.cs @@ -5,6 +5,7 @@ using DSharpPlus.Commands; using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Entities; +using DSharpPlus.Exceptions; using MySqlConnector; namespace SupportChild.Commands; @@ -57,17 +58,19 @@ public class AddStaffCommand Description = staffMember.Mention + " was added to staff." }); - // TODO: This throws an exception instead of returning null now - - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = staffMember.Mention + " was added to staff.\n" }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } } \ No newline at end of file diff --git a/Commands/AdminCommands.cs b/Commands/AdminCommands.cs index 02eef40..08f15a2 100644 --- a/Commands/AdminCommands.cs +++ b/Commands/AdminCommands.cs @@ -7,6 +7,7 @@ using DSharpPlus.Commands; using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Entities; +using DSharpPlus.Exceptions; using DSharpPlus.Interactivity; using DSharpPlus.Interactivity.Extensions; @@ -117,18 +118,20 @@ public class AdminCommands Description = "Channel has been designated ticket " + ticketID + "." }); - // TODO: This throws an exception instead of returning null now - - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = command.Channel.Mention + " has been designated ticket " + ticketID + " by " + command.Member.Mention + "." }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } [RequireGuild] @@ -175,18 +178,20 @@ public class AdminCommands Description = "Channel has been undesignated as a ticket." }); - // TODO: This throws an exception instead of returning null now - - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = command.Channel.Mention + " has been undesignated as a ticket by " + command.Member.Mention + "." }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } else { diff --git a/Commands/AssignCommand.cs b/Commands/AssignCommand.cs index 478d582..bebd1ad 100644 --- a/Commands/AssignCommand.cs +++ b/Commands/AssignCommand.cs @@ -92,16 +92,19 @@ public class AssignCommand catch (UnauthorizedException) { } } - // TODO: This throws an exception instead of returning null now - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = member.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "." }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } } \ No newline at end of file diff --git a/Commands/BlacklistCommand.cs b/Commands/BlacklistCommand.cs index b28ec42..55bca8b 100644 --- a/Commands/BlacklistCommand.cs +++ b/Commands/BlacklistCommand.cs @@ -5,6 +5,7 @@ using DSharpPlus.Commands; using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Entities; +using DSharpPlus.Exceptions; namespace SupportChild.Commands; @@ -34,17 +35,20 @@ public class BlacklistCommand Description = "Blacklisted " + user.Mention + "." }, true); - // TODO: This throws an exception instead of returning null now - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = user.Mention + " was blacklisted from opening tickets by " + command.Member.Mention + "." }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } catch (Exception) { diff --git a/Commands/CloseCommand.cs b/Commands/CloseCommand.cs index 8295107..da68298 100644 --- a/Commands/CloseCommand.cs +++ b/Commands/CloseCommand.cs @@ -83,12 +83,10 @@ public class CloseCommand closeReason = "\nReason: " + cachedReason + "\n"; } - // TODO: This throws an exception instead of returning null now - - // Log it if the log channel exists - DiscordChannel logChannel = await interaction.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); DiscordEmbed embed = new DiscordEmbedBuilder { Color = DiscordColor.Green, @@ -104,6 +102,10 @@ public class CloseCommand await logChannel.SendMessageAsync(message); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } if (Config.closingNotifications) { @@ -117,8 +119,7 @@ public class CloseCommand try { - // TODO: This throws an exception instead of returning null now - DiscordMember staffMember = await interaction.Guild.GetMemberAsync(ticket.creatorID); + DiscordUser staffMember = await SupportChild.client.GetUserAsync(ticket.creatorID); await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read); DiscordMessageBuilder message = new DiscordMessageBuilder(); diff --git a/Commands/NewCommand.cs b/Commands/NewCommand.cs index ab91bae..188e85b 100644 --- a/Commands/NewCommand.cs +++ b/Commands/NewCommand.cs @@ -268,19 +268,20 @@ public class NewCommand } } - // TODO: This throws an exception instead of returning null now - - // Log it if the log channel exists - DiscordChannel logChannel = await category.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { - DiscordEmbed logMessage = new DiscordEmbedBuilder + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); + await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = "Ticket " + ticketChannel.Mention + " opened by " + member.Mention + ".\n", Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "Ticket " + ticketID } - }; - await logChannel.SendMessageAsync(logMessage); + }); + } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); } return (true, "Ticket opened, " + member.Mention + "!\n" + ticketChannel.Mention); diff --git a/Commands/RandomAssignCommand.cs b/Commands/RandomAssignCommand.cs index d248b42..ad1b7b1 100644 --- a/Commands/RandomAssignCommand.cs +++ b/Commands/RandomAssignCommand.cs @@ -69,17 +69,20 @@ public class RandomAssignCommand catch (UnauthorizedException) { } } - // TODO: This throws an exception instead of returning null now - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = staffMember.Mention + " was randomly assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "." }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } private static async Task GetRandomVerifiedStaffMember(SlashCommandContext command, DiscordRole targetRole, Database.Ticket ticket) diff --git a/Commands/RemoveStaffCommand.cs b/Commands/RemoveStaffCommand.cs index ad5f74d..b42b449 100644 --- a/Commands/RemoveStaffCommand.cs +++ b/Commands/RemoveStaffCommand.cs @@ -4,6 +4,7 @@ using DSharpPlus.Commands; using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Entities; +using DSharpPlus.Exceptions; using MySqlConnector; namespace SupportChild.Commands; @@ -39,16 +40,19 @@ public class RemoveStaffCommand Description = "User was removed from staff." }, true); - // TODO: This throws an exception instead of returning null now - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = "User was removed from staff.\n" }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } } \ No newline at end of file diff --git a/Commands/TranscriptCommand.cs b/Commands/TranscriptCommand.cs index e726609..97657c8 100644 --- a/Commands/TranscriptCommand.cs +++ b/Commands/TranscriptCommand.cs @@ -79,12 +79,11 @@ public class TranscriptCommand return; } } - // TODO: This throws an exception instead of returning null now - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read); DiscordMessageBuilder message = new DiscordMessageBuilder(); @@ -98,6 +97,10 @@ public class TranscriptCommand await logChannel.SendMessageAsync(message); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } try { diff --git a/Commands/UnassignCommand.cs b/Commands/UnassignCommand.cs index b26c140..6452696 100644 --- a/Commands/UnassignCommand.cs +++ b/Commands/UnassignCommand.cs @@ -4,6 +4,7 @@ using DSharpPlus.Commands; using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Entities; +using DSharpPlus.Exceptions; namespace SupportChild.Commands; @@ -41,16 +42,19 @@ public class UnassignCommand Description = "Unassigned staff member from ticket." }); - // TODO: This throws an exception instead of returning null now - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = "Staff member was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "." }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } } \ No newline at end of file diff --git a/Commands/UnblacklistCommand.cs b/Commands/UnblacklistCommand.cs index b200db9..06fd2ad 100644 --- a/Commands/UnblacklistCommand.cs +++ b/Commands/UnblacklistCommand.cs @@ -5,6 +5,7 @@ using DSharpPlus.Commands; using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Entities; +using DSharpPlus.Exceptions; namespace SupportChild.Commands; @@ -33,17 +34,20 @@ public class UnblacklistCommand Description = "Removed " + user.Mention + " from blacklist." }, true); - // TODO: This throws an exception instead of returning null now - // Log it if the log channel exists - DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel); - if (logChannel != null) + try { + // Log it if the log channel exists + DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel); await logChannel.SendMessageAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = user.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "." }); } + catch (NotFoundException) + { + Logger.Error("Could not find the log channel."); + } } catch (Exception) {