Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DM relay blocking functionality #181

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Commands/DmRelayBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Cliptok.Commands
{
internal class DmRelayBlock : BaseCommandModule
{
[Command("dmrelayblock")]
[Description("Stop a member's DMs from being relayed to the configured DM relay channel.")]
[Aliases("dmblock")]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.TrialModerator)]
public async Task DmRelayBlockCommand(CommandContext ctx, [Description("The member to stop relaying DMs from.")] DiscordUser user)
{
// Only function in configured DM relay channel/thread; do nothing if in wrong channel
if (ctx.Channel.Id != Program.cfgjson.DmLogChannelId && Program.cfgjson.LogChannels.All(a => a.Value.ChannelId != ctx.Channel.Id)) return;

// Check blocklist for user
if (await Program.db.SetContainsAsync("dmRelayBlocklist", user.Id))
{
// If already in list, remove
await Program.db.SetRemoveAsync("dmRelayBlocklist", user.Id);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} {user.Mention} has been unblocked successfully!");
return;
}

// If not in list, add
await Program.db.SetAddAsync("dmRelayBlocklist", user.Id);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} {user.Mention} has been blocked. Their DMs will not appear here.");
}
}
}
3 changes: 3 additions & 0 deletions Events/DirectMessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ public class DirectMessageEvent
{
public static async void DirectMessageEventHandler(DiscordMessage message)
{
// Ignore message if user is blocked
if (await Program.db.SetContainsAsync("dmRelayBlocklist", message.Author.Id)) return;

// Auto-response to contact modmail if DM follows warn/mute and is within configured time limit

bool sentAutoresponse = false;
Expand Down
Loading