Skip to content

Commit

Permalink
Remove boolean return values from lockdown helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Dec 15, 2024
1 parent 2470aa1 commit e7c6e4e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
20 changes: 14 additions & 6 deletions Commands/InteractionCommands/LockdownInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ await thread.ModifyAsync(a =>
return;
}

bool success = await LockdownHelpers.LockChannelAsync(user: ctx.User, channel: currentChannel, duration: lockDuration, reason: reason, lockThreads: lockThreads);
if (success)
try
{
await LockdownHelpers.LockChannelAsync(user: ctx.User, channel: currentChannel, duration: lockDuration, reason: reason, lockThreads: lockThreads);
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent("Channel locked successfully.").AsEphemeral(true));
else
}
catch (ArgumentException)
{
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent("Failed to lock this channel!").AsEphemeral(true));
}
}

[SlashCommand("all", "Lock all lockable channels in the server. See also: unlock all")]
Expand Down Expand Up @@ -123,11 +127,15 @@ public class UnlockCmds
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} A mass lockdown or unlock is already ongoing. Refusing your request. sorry.").AsEphemeral(true));
return;
}
bool success = await LockdownHelpers.UnlockChannel(currentChannel, ctx.Member);
if (success)
try
{
await LockdownHelpers.UnlockChannel(currentChannel, ctx.Member);
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent("Channel unlocked successfully.").AsEphemeral(true));
else
}
catch (ArgumentException)
{
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent("Failed to unlock this channel!").AsEphemeral(true));
}
}

[SlashCommand("all", "Unlock all lockable channels in the server. See also: lockdown all")]
Expand Down
14 changes: 8 additions & 6 deletions Helpers/LockdownHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{
public class LockdownHelpers
{
public static async Task<bool> LockChannelAsync(DiscordUser user, DiscordChannel channel, TimeSpan? duration = null, string reason = "No reason specified.", bool lockThreads = false)
public static async Task LockChannelAsync(DiscordUser user, DiscordChannel channel, TimeSpan? duration = null, string reason = "No reason specified.", bool lockThreads = false)
{
if (!Program.cfgjson.LockdownEnabledChannels.Contains(channel.Id))
{
return false;
throw new ArgumentException($"Channel {channel.Id} is not in the lockdown whitelist.");
}

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

await channel.SendMessageAsync(msg);
return true;
}

public static async Task<bool> UnlockChannel(DiscordChannel discordChannel, DiscordMember discordMember, string reason = "No reason specified.", bool isMassUnlock = false)
public static async Task UnlockChannel(DiscordChannel discordChannel, DiscordMember discordMember, string reason = "No reason specified.", bool isMassUnlock = false)
{
if (!Program.cfgjson.LockdownEnabledChannels.Contains(discordChannel.Id))
{
throw new ArgumentException($"Channel {discordChannel.Id} is not in the lockdown whitelist.");
}

// 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
var permissions = discordChannel.PermissionOverwrites.ToArray();

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

await Program.db.HashDeleteAsync("unlocks", discordChannel.Id);
await discordChannel.SendMessageAsync($"{Program.cfgjson.Emoji.Unlock} This channel has been unlocked!");

return true;
}

}
Expand Down

0 comments on commit e7c6e4e

Please sign in to comment.