Skip to content

Commit

Permalink
Use proper/full command name in interaction command logging
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Oct 17, 2024
1 parent 0b1a469 commit 1da33cf
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Events/InteractionEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ private static async Task LogCmdUsage(CommandContext context)
try
{
// Ignore home server, excluded servers, and authorized users
if (context.Guild is not null && (context.Guild.Id == Program.HomeServer.Id ||
Program.ConfigJson.Logs.SlashCommands.CmdLogExcludedGuilds.Contains(context.Guild.Id.ToString())) ||
Program.ConfigJson.Base.AuthorizedUsers.Contains(context.User.Id.ToString()))
return;
//if (context.Guild is not null && (context.Guild.Id == Program.HomeServer.Id ||
// Program.ConfigJson.Logs.SlashCommands.CmdLogExcludedGuilds.Contains(context.Guild.Id.ToString())) ||
// Program.ConfigJson.Base.AuthorizedUsers.Contains(context.User.Id.ToString()))
// return;

// Increment count
if (await Program.Db.HashExistsAsync("commandCounts", context.Command.Name))
await Program.Db.HashIncrementAsync("commandCounts", context.Command.Name);
if (await Program.Db.HashExistsAsync("commandCounts", context.Command.FullName))
await Program.Db.HashIncrementAsync("commandCounts", context.Command.FullName);
else
await Program.Db.HashSetAsync("commandCounts", context.Command.Name, 1);
await Program.Db.HashSetAsync("commandCounts", context.Command.FullName, 1);

// Log to log channel if configured
if (Program.ConfigJson.Logs.SlashCommands.LogChannel is not null)
{
var description = context.Channel.IsPrivate
? $"{context.User.Username} (`{context.User.Id}`) used {SlashCmdMentionHelpers.GetSlashCmdMention(context.Command.Name)} in DMs."
: $"{context.User.Username} (`{context.User.Id}`) used {SlashCmdMentionHelpers.GetSlashCmdMention(context.Command.Name)} in `{context.Channel.Name}` (`{context.Channel.Id}`) in \"{context.Guild.Name}\" (`{context.Guild.Id}`).";
? $"{context.User.Username} (`{context.User.Id}`) used {SlashCmdMentionHelpers.GetSlashCmdMention(context.Command.FullName)} in DMs."
: $"{context.User.Username} (`{context.User.Id}`) used {SlashCmdMentionHelpers.GetSlashCmdMention(context.Command.FullName)} in `{context.Channel.Name}` (`{context.Channel.Id}`) in \"{context.Guild.Name}\" (`{context.Guild.Id}`).";

var embed = new DiscordEmbedBuilder()
.WithColor(Program.BotColor)
Expand All @@ -47,13 +47,13 @@ private static async Task LogCmdUsage(CommandContext context)
{
Program.Discord.Logger.LogError(Program.BotEventId,
"{User} used {Command} in {Guild} but it could not be logged because the log channel cannot be accessed",
context.User.Id, context.Command.Name, context.Guild.Id);
context.User.Id, context.Command.FullName, context.Guild.Id);
}
catch (FormatException)
{
Program.Discord.Logger.LogError(Program.BotEventId,
"{User} used {Command} in {Guild} but it could not be logged because the log channel ID is invalid",
context.User.Id, context.Command.Name, context.Guild.Id);
context.User.Id, context.Command.FullName, context.Guild.Id);
}
}
}
Expand All @@ -63,7 +63,7 @@ private static async Task LogCmdUsage(CommandContext context)
{
Title = "An exception was thrown when logging a slash command",
Description =
$"An exception was thrown when {context.User.Mention} used `/{context.Command.Name}`. Details are below.",
$"An exception was thrown when {context.User.Mention} used `/{context.Command.FullName}`. Details are below.",
Color = DiscordColor.Red
};
embed.AddField("Exception Details",
Expand Down

0 comments on commit 1da33cf

Please sign in to comment.