Skip to content

Commit

Permalink
Fix logging issues
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Dec 8, 2024
1 parent 426c927 commit c9b175c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
21 changes: 16 additions & 5 deletions Commands/AddStaffCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,23 @@ await command.RespondAsync(new DiscordEmbedBuilder
cmd.ExecuteNonQuery();
cmd.Dispose();

await command.RespondAsync(new DiscordEmbedBuilder
if (alreadyStaff)
{
Color = DiscordColor.Green,
Description = alreadyStaff ? staffMember.Mention + " is already a staff member, refreshed username in database." : staffMember.Mention + " was added to staff."
}, true);
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = staffMember.Mention + " is already a staff member, refreshed username in database."
}, true);
}
else
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = staffMember.Mention + " was added to staff."
}, true);

await LogChannel.Success(staffMember.Mention + " was added to staff by " + command.User.Mention + ".");
await LogChannel.Success(staffMember.Mention + " was added to staff by " + command.User.Mention + ".");
}
}
}
16 changes: 12 additions & 4 deletions Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public static async Task CreateSelector(SlashCommandContext command, List<Databa
return (false, "Error: Could not find the category to place the ticket in.");
}

if (category.Children.Count == 50)
{
return (false, "This ticket category is full, can not create ticket channel.");
}

DiscordMember member = null;
try
{
Expand All @@ -151,7 +156,10 @@ public static async Task CreateSelector(SlashCommandContext command, List<Databa
{
ticketChannel = await category.Guild.CreateChannelAsync("ticket", DiscordChannelType.Text, category);
}
catch (Exception) { /* ignored */ }
catch (Exception e)
{
Logger.Error("Error occured while creating ticket.", e);
}

if (ticketChannel == null)
{
Expand All @@ -173,7 +181,7 @@ public static async Task CreateSelector(SlashCommandContext command, List<Databa
catch (DiscordException e)
{
Logger.Error("Exception occurred trying to modify channel: " + e);
Logger.Error("JsomMessage: " + e.JsonMessage);
Logger.Error("JsonMessage: " + e.JsonMessage);
}

try
Expand All @@ -183,7 +191,7 @@ public static async Task CreateSelector(SlashCommandContext command, List<Databa
catch (DiscordException e)
{
Logger.Error("Exception occurred trying to add channel permissions: " + e);
Logger.Error("JsomMessage: " + e.JsonMessage);
Logger.Error("JsonMessage: " + e.JsonMessage);
}

DiscordMessage message = await ticketChannel.SendMessageAsync("Hello, " + member.Mention + "!\n" + Config.welcomeMessage);
Expand Down Expand Up @@ -230,7 +238,7 @@ await assignedStaff.SendMessageAsync(new DiscordEmbedBuilder
catch (DiscordException e)
{
Logger.Error("Exception occurred assign random staff member: " + e);
Logger.Error("JsomMessage: " + e.JsonMessage);
Logger.Error("JsonMessage: " + e.JsonMessage);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public static async Task OnComponentInteractionCreated(DiscordClient client, Com
catch (DiscordException ex)
{
Logger.Error("Interaction Exception occurred: " + ex);
Logger.Error("JsomMessage: " + ex.JsonMessage);
Logger.Error("JsonMessage: " + ex.JsonMessage);
}
catch (Exception ex)
{
Expand Down
7 changes: 3 additions & 4 deletions LogChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,24 @@ private static async Task Log(DiscordColor color, string message, uint ticketID

try
{
DiscordChannel logChannel = await SupportBoi.client.GetChannelAsync(Config.logChannel);

DiscordMessageBuilder messageBuilder = new();
DiscordEmbedBuilder embedBuilder = new()
{
Color = color,
Description = message
};

if (ticketID != 0)
{
embedBuilder.WithFooter("Ticket: " + ticketID.ToString("00000"));
}

DiscordMessageBuilder messageBuilder = new();
messageBuilder.AddEmbed(embedBuilder);
if (file != null)
{
messageBuilder.AddFile(file.fileName, file.contents);
}

DiscordChannel logChannel = await SupportBoi.client.GetChannelAsync(Config.logChannel);
await logChannel.SendMessageAsync(messageBuilder);
}
catch (NotFoundException)
Expand Down

0 comments on commit c9b175c

Please sign in to comment.