Skip to content

Commit

Permalink
feat: defer all commands
Browse files Browse the repository at this point in the history
people have crappy servers
  • Loading branch information
LumiFae committed Dec 31, 2024
1 parent 98f29be commit 27841b8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions DiscordLab.AdvancedLogging/Commands/RemoveLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ public class RemoveLog : ISlashCommand

public async Task Run(SocketSlashCommand command)
{
await command.DeferAsync(true);
List<Log> logs = DiscordBot.Instance.GetLogs().ToList();
string log = command.Data.Options.First().Value.ToString();
Log logToRemove = logs.FirstOrDefault(l => l.Handler == log.Split('.')[0] && l.Event == log.Split('.')[1]);
if (logToRemove == null)
{
await command.RespondAsync("Log not found.", ephemeral: true);
await command.ModifyOriginalResponseAsync(m => m.Content = "Log not found.");
return;
}

logs.Remove(logToRemove);

WriteableConfig.WriteConfigOption("AdvancedLogging", JArray.FromObject(logs));

await command.RespondAsync("Log removed.", ephemeral: true);
await command.ModifyOriginalResponseAsync(m => m.Content = "Log removed.");
}
}
}
8 changes: 4 additions & 4 deletions DiscordLab.Bot/Commands/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ public class Discord : ISlashCommand

public async Task Run(SocketSlashCommand command)
{
await command.DeferAsync(true);
string subcommand = command.Data.Options.First().Name;
if (subcommand == "list")
{
if (UpdateStatus.Statuses == null)
{
await command.RespondAsync("No modules available as of current, please wait for your server to fully start.");
await command.ModifyOriginalResponseAsync(m => m.Content = "No modules available as of current, please wait for your server to fully start.");
return;
}
string modules = string.Join("\n", UpdateStatus.Statuses.Where(s => s.ModuleName != "DiscordLab.Bot").Select(s => s.ModuleName));
await command.RespondAsync("List of available DiscordLab modules:\n\n" + modules, ephemeral:true);
await command.ModifyOriginalResponseAsync(m => m.Content = "List of available DiscordLab modules:\n\n" + modules);
}
else if (subcommand == "install")
{
if (UpdateStatus.Statuses == null)
{
await command.RespondAsync("No modules available as of current, please wait for your server to fully start.");
await command.ModifyOriginalResponseAsync(m => m.Content = "No modules available as of current, please wait for your server to fully start.");
return;
}
await command.DeferAsync(true);
string module = command.Data.Options.First().Options.First().Value.ToString();
if(string.IsNullOrWhiteSpace(module))
{
Expand Down
6 changes: 3 additions & 3 deletions DiscordLab.Moderation/Commands/Ban.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Ban : ISlashCommand

public async Task Run(SocketSlashCommand command)
{
await command.DeferAsync(true);
string user = command.Data.Options.First(option => option.Name == Translation.BanCommandUserOptionName)
.Value.ToString();
string reason = command.Data.Options.First(option => option.Name == Translation.BanCommandReasonOptionName)
Expand All @@ -55,12 +56,11 @@ public async Task Run(SocketSlashCommand command)
string response = Server.ExecuteCommand($"/oban {user} {duration} {reason}");
if (!response.Contains("has been banned"))
{
await command.RespondAsync(Translation.FailedExecuteCommand.Replace("{reason}", response),
ephemeral: true);
await command.ModifyOriginalResponseAsync(m=> m.Content = Translation.FailedExecuteCommand.Replace("{reason}", response));
}
else
{
await command.RespondAsync(Translation.BanCommandSuccess.Replace("{player}", user), ephemeral: true);
await command.ModifyOriginalResponseAsync(m => m.Content = Translation.BanCommandSuccess.Replace("{player}", user));
if (ModerationLogsHandler.Instance.IsEnabled)
{
ModerationLogsHandler.Instance.SendBanLogMethod.Invoke(
Expand Down
4 changes: 2 additions & 2 deletions DiscordLab.Moderation/Commands/SendCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public class SendCommand : ISlashCommand

public async Task Run(SocketSlashCommand command)
{
await command.DeferAsync(true);
string commandToExecute = command.Data.Options.First(option => option.Name == Translation.SendCommandCommandOptionName)
.Value.ToString();

string response = Server.ExecuteCommand(commandToExecute);
await command.RespondAsync(Translation.SendCommandResponse.Replace("{response}", response),
ephemeral: true);
await command.ModifyOriginalResponseAsync(m => m.Content = Translation.SendCommandResponse.Replace("{response}", response));
}
}
}
6 changes: 3 additions & 3 deletions DiscordLab.Moderation/Commands/Unban.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ public class Unban : ISlashCommand

public async Task Run(SocketSlashCommand command)
{
await command.DeferAsync(true);
string user = command.Data.Options.First(option => option.Name == Translation.BanCommandUserOptionName)
.Value.ToString();

string response = Server.ExecuteCommand($"/unban id {user}");
if (!response.Contains("Done"))
{
await command.RespondAsync(Translation.FailedExecuteCommand.Replace("{reason}", response),
ephemeral: true);
await command.ModifyOriginalResponseAsync(m => m.Content = Translation.FailedExecuteCommand.Replace("{reason}", response));
}
else
{
await command.RespondAsync(Translation.UnbanCommandSuccess.Replace("{player}", user), ephemeral: true);
await command.ModifyOriginalResponseAsync(m => m.Content = Translation.UnbanCommandSuccess.Replace("{player}", user));
if (ModerationLogsHandler.Instance.IsEnabled)
{
ModerationLogsHandler.Instance.SendUnbanLogMethod.Invoke(
Expand Down

0 comments on commit 27841b8

Please sign in to comment.