Skip to content

Commit 524dec6

Browse files
OMEGA3065LumiFae
andauthored
feat: command success/failure log (#18)
* Add a few more features for Administration logs * fix arguments saying Unknown for commands with no arguments * removed the NotFound feature * spelling mistake fix Co-authored-by: Lumi <me@jxtq.moe> * spelling mistake fix #2 Co-authored-by: Lumi <me@jxtq.moe> * Move around some config options to group related ones together * Apply suggestion from @LumiFae Co-authored-by: Lumi <me@jxtq.moe> --------- Co-authored-by: Lumi <me@jxtq.moe>
1 parent d505dbf commit 524dec6

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

DiscordLab.Administration/Config.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public class Config
2121
[Description("The channel to send normal command logs")]
2222
public ulong CommandLogChannelId { get; set; } = 0;
2323

24+
[Description("Should a secondary translation be used for remote admin commands whose response is a failure?")]
25+
public bool UseSecondaryTranslationRemoteAdmin { get; set; } = false;
26+
27+
[Description("Should a secondary translation be used for normal commands whose response is a failure?")]
28+
public bool UseSecondaryTranslationCommand { get; set; } = false;
29+
2430
[Description("Whether to add the commands to the bot. Is false then commands won't be used.")]
2531
public bool AddCommands { get; set; } = true;
2632
}

DiscordLab.Administration/Events.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ public override void OnServerCommandExecuted(CommandExecutedEventArgs ev)
8383
SocketTextChannel channel;
8484
TranslationBuilder builder = new TranslationBuilder("player", player)
8585
.AddCustomReplacer("type", ev.CommandType.ToString())
86-
.AddCustomReplacer("arguments", () => string.Join(" ", ev.Arguments))
86+
.AddCustomReplacer("arguments", () => !ev.Arguments.Any() ? " " : string.Join(" ", ev.Arguments))
8787
.AddCustomReplacer("command", ev.CommandName)
88-
.AddCustomReplacer("commanddescription", () => ev.Command.Description ?? "Unknown");
88+
.AddCustomReplacer("commanddescription", () => ev.Command.Description ?? "Unknown")
89+
.AddCustomReplacer("commandsuccess", () => ev.ExecutedSuccessfully ? "Yes" : "No");
8990

91+
MessageContent translation;
9092
if (ev.CommandType == CommandType.RemoteAdmin)
9193
{
9294
if (Config.RemoteAdminChannelId == 0)
@@ -98,8 +100,9 @@ public override void OnServerCommandExecuted(CommandExecutedEventArgs ev)
98100
Config.RemoteAdminChannelId, Config.GuildId));
99101
return;
100102
}
101-
102-
Translation.RemoteAdmin.SendToChannel(channel, builder);
103+
104+
translation = Config.UseSecondaryTranslationRemoteAdmin && !ev.ExecutedSuccessfully ? Translation.RemoteAdminCommandFailResponse : Translation.RemoteAdmin;
105+
translation.SendToChannel(channel, builder);
103106
return;
104107
}
105108

@@ -112,7 +115,8 @@ public override void OnServerCommandExecuted(CommandExecutedEventArgs ev)
112115
Config.GuildId));
113116
return;
114117
}
115-
116-
Translation.CommandLog.SendToChannel(channel, builder);
118+
119+
translation = Config.UseSecondaryTranslationCommand && !ev.ExecutedSuccessfully ? Translation.CommandLogFailResponse : Translation.CommandLog;
120+
translation.SendToChannel(channel, builder);
117121
}
118122
}

DiscordLab.Administration/Translation.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public class Translation
1414
"Player {player} has executed the remote admin command: `{command}`";
1515

1616
public MessageContent CommandLog { get; set; } = "Player {player} has executed the command: `{command}`";
17+
18+
public MessageContent RemoteAdminCommandFailResponse { get; set; } =
19+
"Player {player} has attempted to run a remote admin command which failed: `{command}`";
20+
21+
public MessageContent CommandLogFailResponse { get; set; } = "Player {player} has attempted to run a command which failed: `{command}`";
1722

1823
public string SendCommandName { get; set; } = "send";
1924

0 commit comments

Comments
 (0)