Skip to content

Commit e7c6e4e

Browse files
Remove boolean return values from lockdown helpers
1 parent 2470aa1 commit e7c6e4e

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

Commands/InteractionCommands/LockdownInteractions.cs

+14-6
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ await thread.ModifyAsync(a =>
5757
return;
5858
}
5959

60-
bool success = await LockdownHelpers.LockChannelAsync(user: ctx.User, channel: currentChannel, duration: lockDuration, reason: reason, lockThreads: lockThreads);
61-
if (success)
60+
try
61+
{
62+
await LockdownHelpers.LockChannelAsync(user: ctx.User, channel: currentChannel, duration: lockDuration, reason: reason, lockThreads: lockThreads);
6263
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent("Channel locked successfully.").AsEphemeral(true));
63-
else
64+
}
65+
catch (ArgumentException)
66+
{
6467
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent("Failed to lock this channel!").AsEphemeral(true));
68+
}
6569
}
6670

6771
[SlashCommand("all", "Lock all lockable channels in the server. See also: unlock all")]
@@ -123,11 +127,15 @@ public class UnlockCmds
123127
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} A mass lockdown or unlock is already ongoing. Refusing your request. sorry.").AsEphemeral(true));
124128
return;
125129
}
126-
bool success = await LockdownHelpers.UnlockChannel(currentChannel, ctx.Member);
127-
if (success)
130+
try
131+
{
132+
await LockdownHelpers.UnlockChannel(currentChannel, ctx.Member);
128133
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent("Channel unlocked successfully.").AsEphemeral(true));
129-
else
134+
}
135+
catch (ArgumentException)
136+
{
130137
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent("Failed to unlock this channel!").AsEphemeral(true));
138+
}
131139
}
132140

133141
[SlashCommand("all", "Unlock all lockable channels in the server. See also: lockdown all")]

Helpers/LockdownHelpers.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
public class LockdownHelpers
44
{
5-
public static async Task<bool> LockChannelAsync(DiscordUser user, DiscordChannel channel, TimeSpan? duration = null, string reason = "No reason specified.", bool lockThreads = false)
5+
public static async Task LockChannelAsync(DiscordUser user, DiscordChannel channel, TimeSpan? duration = null, string reason = "No reason specified.", bool lockThreads = false)
66
{
77
if (!Program.cfgjson.LockdownEnabledChannels.Contains(channel.Id))
88
{
9-
return false;
9+
throw new ArgumentException($"Channel {channel.Id} is not in the lockdown whitelist.");
1010
}
1111

1212
// Get the permissions that are already on the channel, so that we can make sure they are kept when we adjust overwrites for lockdown
@@ -86,11 +86,15 @@ public static async Task<bool> LockChannelAsync(DiscordUser user, DiscordChannel
8686
}
8787

8888
await channel.SendMessageAsync(msg);
89-
return true;
9089
}
9190

92-
public static async Task<bool> UnlockChannel(DiscordChannel discordChannel, DiscordMember discordMember, string reason = "No reason specified.", bool isMassUnlock = false)
91+
public static async Task UnlockChannel(DiscordChannel discordChannel, DiscordMember discordMember, string reason = "No reason specified.", bool isMassUnlock = false)
9392
{
93+
if (!Program.cfgjson.LockdownEnabledChannels.Contains(discordChannel.Id))
94+
{
95+
throw new ArgumentException($"Channel {discordChannel.Id} is not in the lockdown whitelist.");
96+
}
97+
9498
// Get the permissions that are already on the channel, so that we can make sure they are kept when we adjust overwrites for the unlock
9599
var permissions = discordChannel.PermissionOverwrites.ToArray();
96100

@@ -160,8 +164,6 @@ public static async Task<bool> UnlockChannel(DiscordChannel discordChannel, Disc
160164

161165
await Program.db.HashDeleteAsync("unlocks", discordChannel.Id);
162166
await discordChannel.SendMessageAsync($"{Program.cfgjson.Emoji.Unlock} This channel has been unlocked!");
163-
164-
return true;
165167
}
166168

167169
}

0 commit comments

Comments
 (0)