Catch not found exceptions

This commit is contained in:
Toastie 2024-12-26 18:57:41 +13:00
parent d70c2ae0d2
commit 03497a28f8
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
12 changed files with 100 additions and 63 deletions

View file

@ -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)
{

View file

@ -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.");
}
}
}

View file

@ -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
{

View file

@ -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.");
}
}
}

View file

@ -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)
{

View file

@ -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();

View file

@ -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);

View file

@ -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<DiscordMember> GetRandomVerifiedStaffMember(SlashCommandContext command, DiscordRole targetRole, Database.Ticket ticket)

View file

@ -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.");
}
}
}

View file

@ -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
{

View file

@ -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.");
}
}
}

View file

@ -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)
{