Skip to content

Commit ed9d6f0

Browse files
committed
remove /x log stop commands
1 parent cdcf720 commit ed9d6f0

File tree

17 files changed

+175
-173
lines changed

17 files changed

+175
-173
lines changed

src/TaylorBot.Net/Core/src/TaylorBot.Net.Commands/PostExecution/InteractionCustomId.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public enum CustomIdNames
7575
ModMailConfigSetChannel = 128,
7676
ModMailConfigStop = 129,
7777
HelpCategory = 130,
78+
ModLogStop = 131,
79+
MonitorEditedStop = 132,
80+
MonitorDeletedStop = 133,
81+
MonitorMembersStop = 134,
7882
}
7983

8084
public static class CustomIdExtensions

src/TaylorBot.Net/Program.Commands.Discord/src/TaylorBot.Net.Commands.Discord.Program/DiscordCommandsProgram.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public static void ConfigureServices(HostBuilderContext hostBuilderContext, ISer
202202
.AddTransient<ModMailChannelLogger>()
203203
.AddSlashCommand<ModLogSetSlashCommand>()
204204
.AddButtonHandler<ModLogSetConfirmButtonHandler>()
205-
.AddSlashCommand<ModLogStopSlashCommand>()
205+
.AddButtonHandler<ModLogStopButtonHandler>()
206206
.AddSlashCommand<ModLogShowSlashCommand>()
207207
.ConfigureRequired<ModMailOptions>(config, "ModMail")
208208
.AddSlashCommand<ModMailMessageUserSlashCommand>()
@@ -252,16 +252,16 @@ public static void ConfigureServices(HostBuilderContext hostBuilderContext, ISer
252252
.AddTransient<IEditedLogChannelRepository, EditedLogChannelPostgresRepository>()
253253
.AddSlashCommand<MonitorEditedSetSlashCommand>()
254254
.AddButtonHandler<MonitorEditedSetConfirmButtonHandler>()
255+
.AddButtonHandler<MonitorEditedStopButtonHandler>()
255256
.AddSlashCommand<MonitorEditedShowSlashCommand>()
256-
.AddSlashCommand<MonitorEditedStopSlashCommand>()
257257
.AddSlashCommand<MonitorDeletedSetSlashCommand>()
258258
.AddButtonHandler<MonitorDeletedSetConfirmButtonHandler>()
259+
.AddButtonHandler<MonitorDeletedStopButtonHandler>()
259260
.AddSlashCommand<MonitorDeletedShowSlashCommand>()
260-
.AddSlashCommand<MonitorDeletedStopSlashCommand>()
261261
.AddSlashCommand<MonitorMembersSetSlashCommand>()
262262
.AddButtonHandler<MonitorMembersSetConfirmButtonHandler>()
263+
.AddButtonHandler<MonitorMembersStopButtonHandler>()
263264
.AddSlashCommand<MonitorMembersShowSlashCommand>()
264-
.AddSlashCommand<MonitorMembersStopSlashCommand>()
265265
.AddSlashCommand<CommandServerDisableSlashCommand>()
266266
.AddSlashCommand<CommandServerEnableSlashCommand>()
267267
.AddSlashCommand<CommandChannelDisableSlashCommand>()

src/TaylorBot.Net/Program.Commands.Discord/src/TaylorBot.Net.Commands.Discord.Program/Modules/Mod/Commands/ModLogSlashCommands.cs

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ namespace TaylorBot.Net.Commands.Discord.Program.Modules.Mod.Commands;
1515
public class ModLogSetSlashCommand(
1616
IModLogChannelRepository modLogChannelRepository,
1717
UserHasPermissionOrOwnerPrecondition.Factory userHasPermission,
18-
CommandMentioner mention,
19-
InGuildPrecondition.Factory inGuild) : ISlashCommand<ModLogSetSlashCommand.Options>
18+
InGuildPrecondition.Factory inGuild,
19+
CommandMentioner mention) : ISlashCommand<ModLogSetSlashCommand.Options>
2020
{
2121
public static string CommandName => "mod log set";
2222

@@ -69,7 +69,7 @@ public async ValueTask<Embed> AddOrUpdateAsync(RunContext context, GuildTextChan
6969
.WithDescription(
7070
$"""
7171
Ok, I will now log moderation command usage in {channel.Mention}
72-
Use {mention.SlashCommand("mod log stop", context)} to undo this action ↩️
72+
Use {mention.SlashCommand("mod log show", context)} to see the current configuration ↩️
7373
""")
7474
.Build();
7575
}
@@ -106,44 +106,6 @@ await responseClient.EditOriginalResponseAsync(button.Interaction, EmbedFactory.
106106
}
107107
}
108108

109-
public class ModLogStopSlashCommand(
110-
IModLogChannelRepository modLogChannelRepository,
111-
UserHasPermissionOrOwnerPrecondition.Factory userHasPermission,
112-
CommandMentioner mention,
113-
InGuildPrecondition.Factory inGuild) : ISlashCommand<NoOptions>
114-
{
115-
public static string CommandName => "mod log stop";
116-
117-
public ISlashCommandInfo Info => new MessageCommandInfo(CommandName);
118-
119-
public ValueTask<Command> GetCommandAsync(RunContext context, NoOptions options)
120-
{
121-
return new(new Command(
122-
new(Info.Name),
123-
async () =>
124-
{
125-
var guild = context.Guild?.Fetched;
126-
ArgumentNullException.ThrowIfNull(guild);
127-
128-
await modLogChannelRepository.RemoveModLogAsync(guild);
129-
130-
return new EmbedResult(new EmbedBuilder()
131-
.WithColor(TaylorBotColors.SuccessColor)
132-
.WithDescription(
133-
$"""
134-
Ok, I will stop logging moderation command usage in this server ✅
135-
Use {mention.SlashCommand("mod log set", context)} to log moderation command usage in a specific channel ↩️
136-
""")
137-
.Build());
138-
},
139-
Preconditions: [
140-
inGuild.Create(botMustBeInGuild: true),
141-
userHasPermission.Create(GuildPermission.ManageGuild)
142-
]
143-
));
144-
}
145-
}
146-
147109
public class ModLogShowSlashCommand(
148110
IModLogChannelRepository modLogChannelRepository,
149111
UserHasPermissionOrOwnerPrecondition.Factory userHasPermission,
@@ -166,6 +128,7 @@ public ValueTask<Command> GetCommandAsync(RunContext context, NoOptions options)
166128
var modLog = await modLogChannelRepository.GetModLogForGuildAsync(guild);
167129

168130
var embed = new EmbedBuilder().WithColor(TaylorBotColors.SuccessColor);
131+
List<InteractionComponent> components = [];
169132

170133
if (modLog != null)
171134
{
@@ -175,8 +138,12 @@ public ValueTask<Command> GetCommandAsync(RunContext context, NoOptions options)
175138
embed.WithDescription(
176139
$"""
177140
This server is configured to log moderation command usage in {channel.Mention}
178-
Use {mention.SlashCommand("mod log stop", context)} to stop logging moderation command usage in this server ↩️
179141
""");
142+
components.Add(InteractionComponent.CreateActionRow(InteractionComponent.CreateButton(
143+
style: InteractionButtonStyle.Danger,
144+
custom_id: InteractionCustomId.Create(ModLogStopButtonHandler.CustomIdName).RawId,
145+
label: "Stop Logging",
146+
emoji: new("🗑"))));
180147
}
181148
else
182149
{
@@ -196,12 +163,46 @@ There is no moderation command usage logging configured in this server ❌
196163
""");
197164
}
198165

199-
return new EmbedResult(embed.Build());
166+
return new MessageResult(new(new(embed.Build()), components));
200167
},
201168
Preconditions: [
202169
inGuild.Create(botMustBeInGuild: true),
203-
userHasPermission.Create(GuildPermission.ManageGuild)
170+
userHasPermission.Create(GuildPermission.ManageGuild),
204171
]
205172
));
206173
}
207174
}
175+
176+
public class ModLogStopButtonHandler(
177+
IModLogChannelRepository modLogChannelRepository,
178+
IInteractionResponseClient responseClient,
179+
UserHasPermissionOrOwnerPrecondition.Factory userHasPermission,
180+
InGuildPrecondition.Factory inGuild,
181+
CommandMentioner mention) : IButtonHandler
182+
{
183+
public static CustomIdNames CustomIdName => CustomIdNames.ModLogStop;
184+
185+
public IComponentHandlerInfo Info => new MessageHandlerInfo(
186+
CustomIdName.ToText(),
187+
Preconditions: [
188+
inGuild.Create(),
189+
userHasPermission.Create(GuildPermission.ManageGuild),
190+
],
191+
RequireOriginalUser: true);
192+
193+
public async Task HandleAsync(DiscordButtonComponent button, RunContext context)
194+
{
195+
var guild = context.Guild;
196+
ArgumentNullException.ThrowIfNull(guild);
197+
198+
await modLogChannelRepository.RemoveModLogAsync(guild);
199+
200+
var embed = EmbedFactory.CreateSuccessEmbed(
201+
$"""
202+
Moderation command usage logging is now disabled in this server ✅
203+
Use {mention.SlashCommand("mod log set", context)} to re-enable it ↩️
204+
""");
205+
206+
await responseClient.EditOriginalResponseAsync(button.Interaction, embed);
207+
}
208+
}

src/TaylorBot.Net/Program.Commands.Discord/src/TaylorBot.Net.Commands.Discord.Program/Modules/Mod/Domain/IModLogChannelRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public record ModLog(SnowflakeId ChannelId);
99
public interface IModLogChannelRepository
1010
{
1111
ValueTask AddOrUpdateModLogAsync(GuildTextChannel textChannel);
12-
ValueTask RemoveModLogAsync(IGuild guild);
12+
ValueTask RemoveModLogAsync(CommandGuild guild);
1313
ValueTask<ModLog?> GetModLogForGuildAsync(IGuild guild);
1414
}

src/TaylorBot.Net/Program.Commands.Discord/src/TaylorBot.Net.Commands.Discord.Program/Modules/Mod/Infrastructure/ModLogChannelPostgresRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Dapper;
1+
using Dapper;
22
using Discord;
33
using TaylorBot.Net.Commands.Discord.Program.Modules.Mod.Domain;
44
using TaylorBot.Net.Core.Infrastructure;
@@ -28,7 +28,7 @@ ON CONFLICT (guild_id) DO UPDATE SET
2828
);
2929
}
3030

31-
public async ValueTask RemoveModLogAsync(IGuild guild)
31+
public async ValueTask RemoveModLogAsync(CommandGuild guild)
3232
{
3333
await using var connection = postgresConnectionFactory.CreateConnection();
3434

src/TaylorBot.Net/Program.Commands.Discord/src/TaylorBot.Net.Commands.Discord.Program/Modules/Monitor/Commands/MonitorDeletedSlashCommands.cs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using TaylorBot.Net.Commands.PostExecution;
66
using TaylorBot.Net.Commands.Preconditions;
77
using TaylorBot.Net.Core.Client;
8+
using TaylorBot.Net.Core.Colors;
89
using TaylorBot.Net.Core.Embed;
910
using TaylorBot.Net.Core.Snowflake;
1011
using TaylorBot.Net.EntityTracker.Domain.TextChannel;
@@ -78,7 +79,7 @@ public async ValueTask<Embed> AddOrUpdateAsync(RunContext context, GuildTextChan
7879
return EmbedFactory.CreateSuccess(
7980
$"""
8081
Ok, I will now log deleted messages in {channel.Mention}. **Please wait up to 5 minutes for changes to take effect** ⌚
81-
Use {mention.SlashCommand("monitor deleted stop", context)} to stop monitoring deleted messages ↩️
82+
Use {mention.SlashCommand("monitor deleted show", context)} to see the current configuration ↩️
8283
""");
8384
}
8485
}
@@ -135,22 +136,27 @@ public ValueTask<Command> GetCommandAsync(RunContext context, NoOptions options)
135136

136137
var log = await deletedLogChannelRepository.GetDeletedLogForGuildAsync(guild);
137138

138-
Embed? embed = null;
139+
var embed = new EmbedBuilder().WithColor(TaylorBotColors.SuccessColor);
140+
List<InteractionComponent> components = [];
139141

140142
if (log != null)
141143
{
142144
var channel = (ITextChannel?)await guild.GetChannelAsync(log.ChannelId.Id);
143145
if (channel != null)
144146
{
145-
embed = EmbedFactory.CreateSuccess(
147+
embed.WithDescription(
146148
$"""
147149
This server is configured to log deleted messages in {channel.Mention}
148-
Use {mention.SlashCommand("monitor deleted stop", context)} to stop monitoring deleted messages in this server ↩️
149150
""");
151+
components.Add(InteractionComponent.CreateActionRow(InteractionComponent.CreateButton(
152+
style: InteractionButtonStyle.Danger,
153+
custom_id: InteractionCustomId.Create(MonitorDeletedStopButtonHandler.CustomIdName).RawId,
154+
label: "Stop Monitoring",
155+
emoji: new("🗑"))));
150156
}
151157
else
152158
{
153-
embed = EmbedFactory.CreateSuccess(
159+
embed.WithDescription(
154160
$"""
155161
I can't find the previously configured deleted messages logging channel in this server ❌
156162
Was it deleted? Use {mention.SlashCommand("monitor deleted set", context)} to log deleted messages in another channel ↩️
@@ -159,14 +165,14 @@ I can't find the previously configured deleted messages logging channel in this
159165
}
160166
else
161167
{
162-
embed = EmbedFactory.CreateSuccess(
168+
embed.WithDescription(
163169
$"""
164170
Deleted message monitoring is not configured in this server ❌
165171
Use {mention.SlashCommand("monitor deleted set", context)} to log deleted messages in a specific channel ↩️
166172
""");
167173
}
168174

169-
return new EmbedResult(embed);
175+
return new MessageResult(new(new(embed.Build()), components));
170176
},
171177
Preconditions: [
172178
inGuild.Create(botMustBeInGuild: true),
@@ -176,37 +182,36 @@ Deleted message monitoring is not configured in this server ❌
176182
}
177183
}
178184

179-
public class MonitorDeletedStopSlashCommand(
185+
public class MonitorDeletedStopButtonHandler(
180186
IDeletedLogChannelRepository deletedLogChannelRepository,
187+
IInteractionResponseClient responseClient,
181188
UserHasPermissionOrOwnerPrecondition.Factory userHasPermission,
182189
InGuildPrecondition.Factory inGuild,
183-
CommandMentioner mention) : ISlashCommand<NoOptions>
190+
CommandMentioner mention) : IButtonHandler
184191
{
185-
public static string CommandName => "monitor deleted stop";
192+
public static CustomIdNames CustomIdName => CustomIdNames.MonitorDeletedStop;
186193

187-
public ISlashCommandInfo Info => new MessageCommandInfo(CommandName);
194+
public IComponentHandlerInfo Info => new MessageHandlerInfo(
195+
CustomIdName.ToText(),
196+
Preconditions: [
197+
inGuild.Create(),
198+
userHasPermission.Create(GuildPermission.ManageGuild),
199+
],
200+
RequireOriginalUser: true);
188201

189-
public ValueTask<Command> GetCommandAsync(RunContext context, NoOptions options)
202+
public async Task HandleAsync(DiscordButtonComponent button, RunContext context)
190203
{
191-
return new(new Command(
192-
new(Info.Name),
193-
async () =>
194-
{
195-
var guild = context.Guild?.Fetched;
196-
ArgumentNullException.ThrowIfNull(guild);
204+
var guild = context.Guild;
205+
ArgumentNullException.ThrowIfNull(guild);
197206

198-
await deletedLogChannelRepository.RemoveDeletedLogAsync(guild);
207+
await deletedLogChannelRepository.RemoveDeletedLogAsync(guild);
199208

200-
return new EmbedResult(EmbedFactory.CreateSuccess(
201-
$"""
202-
Ok, I will stop logging deleted messages in this server. **Please wait up to 5 minutes for changes to take effect** ⌚
203-
Use {mention.SlashCommand("monitor deleted set", context)} to log deleted messages in a specific channel ↩️
204-
"""));
205-
},
206-
Preconditions: [
207-
inGuild.Create(botMustBeInGuild: true),
208-
userHasPermission.Create(GuildPermission.ManageGuild)
209-
]
210-
));
209+
var embed = EmbedFactory.CreateSuccessEmbed(
210+
$"""
211+
Deleted message logging is now disabled in this server. **Please wait up to 5 minutes for changes to take effect** ⌚
212+
Use {mention.SlashCommand("monitor deleted set", context)} to re-enable it ↩️
213+
""");
214+
215+
await responseClient.EditOriginalResponseAsync(button.Interaction, embed);
211216
}
212217
}

0 commit comments

Comments
 (0)