From c2f3bf0be85fb1cec46f36f615d9b8f24b38e928 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:39:41 +0530 Subject: [PATCH 01/14] Add `/automod_linkblocker` to command registry --- config/commands.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config/commands.json b/config/commands.json index 4152106..af283c3 100644 --- a/config/commands.json +++ b/config/commands.json @@ -529,6 +529,16 @@ "disabled": false, "bugged": false }, + "automod_linkblocker": { + "name": "Toggle Automod Link Blocker", + "description": "Lets you turn on or off the automod link-blocker for your server.", + "type": "automod", + "cooldown": null, + "args": ["toggle"], + "usable_by": "server admins", + "disabled": false, + "bugged": false + }, "squareroot": { "name": "Square Root", "description": "Finds the square root of any positive number.", From 544434865fd1bf42eec33efccc7d17b870a5882a Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:40:17 +0530 Subject: [PATCH 02/14] Add `/automod_linkblocker` to toggle the link blocker feature in servers --- cogs/automod.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cogs/automod.py b/cogs/automod.py index dd5eb4f..0cb9f08 100644 --- a/cogs/automod.py +++ b/cogs/automod.py @@ -39,6 +39,18 @@ async def automod_swearfilter(self, ctx: ApplicationContext, toggle:bool): automod.swearfilter_enabled(ctx.guild.id, toggle) if toggle is True: await ctx.respond("Swear-filter successfully **enabled**.", ephemeral=True) elif toggle is False: await ctx.respond("Swear-filter successfully **disabled**.", ephemeral=True) + + @commands.slash_command( + name="automod_linkblocker", + description="Turn on or off automod's link blocker in your server" + ) + @option(name="toggle", description="Do you want to turn it on or off?", type=bool) + async def automod_linkblocker(self, ctx: ApplicationContext, toggle: bool): + if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) + if automod.fetch_config(ctx.guild.id)["link_blocker"]["enabled"] == toggle: return await ctx.respond(f"That automod option is already set to `{toggle}`.", ephemeral=True) + automod.linkblocker_enabled(ctx.guild.id, toggle) + if toggle is True: await ctx.respond("Link blocker successfully **enabled**.", ephemeral=True) + elif toggle is False: await ctx.respond("Link blocker successfully **disabled**.", ephemeral=True) @commands.slash_command( name="automod_use_default_keywords", From 071302d0fe790cc4a25a2abe82a4ce147fa0492c Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:40:35 +0530 Subject: [PATCH 03/14] Beautify the code a little bit --- cogs/automod.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/automod.py b/cogs/automod.py index 0cb9f08..ddb4921 100644 --- a/cogs/automod.py +++ b/cogs/automod.py @@ -33,7 +33,7 @@ async def automod(self, ctx: ApplicationContext): description="Turn on or off automod's swear-filter in your server" ) @option(name="toggle", description="Do you want to turn it on or off?", type=bool) - async def automod_swearfilter(self, ctx: ApplicationContext, toggle:bool): + async def automod_swearfilter(self, ctx: ApplicationContext, toggle: bool): if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) if automod.fetch_config(ctx.guild.id)["swear_filter"]["enabled"] == toggle: return await ctx.respond(f"That automod option is already set to `{toggle}`.", ephemeral=True) automod.swearfilter_enabled(ctx.guild.id, toggle) @@ -57,7 +57,7 @@ async def automod_linkblocker(self, ctx: ApplicationContext, toggle: bool): description="Choose whether or not you want to use the default keywords for automod's swear-filter" ) @option(name="toggle", description="Do you want to turn it on or off?", type=bool) - async def automod_use_default_keywords(self, ctx: ApplicationContext, toggle:bool): + async def automod_use_default_keywords(self, ctx: ApplicationContext, toggle: bool): if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) if automod.fetch_config(ctx.guild.id)["swear_filter"]["keywords"]["use_default"] == toggle: return await ctx.respond(f"That automod option is already set to `{toggle}`.", ephemeral=True) automod.swearfilter_usedefaultkeywords(ctx.guild.id, toggle) From c4ae66cf93c9804855be1e133c65b5a10e137143 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:45:00 +0530 Subject: [PATCH 04/14] Add method to modify link blocker automod guild setting --- framework/isobot/db/automod.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/framework/isobot/db/automod.py b/framework/isobot/db/automod.py index 564e773..9f9fbd7 100644 --- a/framework/isobot/db/automod.py +++ b/framework/isobot/db/automod.py @@ -69,3 +69,10 @@ def swearfilter_removekeyword(self, server_id: int, keyword_id: int) -> int: data.pop(id-1) self.save(automod_config) return 0 + + def linkblocker_enabled(self, server_id: int, value: bool) -> int: + """Sets a `bool` value to define whether the server's link blocker is enabled or not.""" + automod_config = self.load() + automod_config[str(server_id)]["link_blocker"]["enabled"] = value + self.save(automod_config) + return 0 From 71c1d3f7461ba987c49cae93e663d6ab11dc2869 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:45:24 +0530 Subject: [PATCH 05/14] Add database auto-generated content for guild link blocker --- framework/isobot/db/automod.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/framework/isobot/db/automod.py b/framework/isobot/db/automod.py index 9f9fbd7..a4214bc 100644 --- a/framework/isobot/db/automod.py +++ b/framework/isobot/db/automod.py @@ -32,6 +32,12 @@ def generate(self, server_id: int) -> int: "default": ["fuck", "shit", "pussy", "penis", "cock", "vagina", "sex", "moan", "bitch", "hoe", "nigga", "nigger", "xxx", "porn"], "custom": [] } + }, + "link_blocker": { + "enabled": False, + "use_whitelist_only": False, + "whitelisted": [], + "blacklisted": [] } } self.save(automod_config) From 3357332a022f0cd6445ed032c3128da854be04ea Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:05:30 +0530 Subject: [PATCH 06/14] Add commands to toggle only whitelisted links, and to add links to whitelist and blacklist --- cogs/automod.py | 63 +++++++++++++++++++++++++++------- framework/isobot/db/automod.py | 21 ++++++++++++ 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/cogs/automod.py b/cogs/automod.py index ddb4921..884ac49 100644 --- a/cogs/automod.py +++ b/cogs/automod.py @@ -39,18 +39,6 @@ async def automod_swearfilter(self, ctx: ApplicationContext, toggle: bool): automod.swearfilter_enabled(ctx.guild.id, toggle) if toggle is True: await ctx.respond("Swear-filter successfully **enabled**.", ephemeral=True) elif toggle is False: await ctx.respond("Swear-filter successfully **disabled**.", ephemeral=True) - - @commands.slash_command( - name="automod_linkblocker", - description="Turn on or off automod's link blocker in your server" - ) - @option(name="toggle", description="Do you want to turn it on or off?", type=bool) - async def automod_linkblocker(self, ctx: ApplicationContext, toggle: bool): - if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) - if automod.fetch_config(ctx.guild.id)["link_blocker"]["enabled"] == toggle: return await ctx.respond(f"That automod option is already set to `{toggle}`.", ephemeral=True) - automod.linkblocker_enabled(ctx.guild.id, toggle) - if toggle is True: await ctx.respond("Link blocker successfully **enabled**.", ephemeral=True) - elif toggle is False: await ctx.respond("Link blocker successfully **disabled**.", ephemeral=True) @commands.slash_command( name="automod_use_default_keywords", @@ -106,4 +94,55 @@ async def automod_remove_custom_keyword(self, ctx: ApplicationContext, id: int): return await ctx.respond(f"Keyword (id: `{id}`) successfully removed from swear-filter configuration.") except IndexError: await ctx.respond("That keyword id doesn't exist. Please specify a valid id and try again.", ephemeral=True) + # Link Blocker Commands + @commands.slash_command( + name="automod_linkblocker", + description="Turn on or off automod's link blocker in your server" + ) + @option(name="toggle", description="Do you want to turn it on or off?", type=bool) + async def automod_linkblocker(self, ctx: ApplicationContext, toggle: bool): + if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) + if automod.fetch_config(ctx.guild.id)["link_blocker"]["enabled"] == toggle: return await ctx.respond(f"That automod option is already set to `{toggle}`.", ephemeral=True) + automod.linkblocker_enabled(ctx.guild.id, toggle) + if toggle is True: await ctx.respond("Link blocker successfully **enabled**.", ephemeral=True) + elif toggle is False: await ctx.respond("Link blocker successfully **disabled**.", ephemeral=True) + + @commands.slash_command( + name="automod_linkblocker_only_whitelisted_links", + description="Only allows whitelisted links in the server and blocks all other links" + ) + @option(name="toggle", description="Do you want to turn it on or off?", type=bool) + async def automod_linkblocker_only_whitelisted_links(self, ctx: ApplicationContext, toggle: bool): + if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) + if automod.fetch_config(ctx.guild.id)["link_blocker"]["use_whitelist_only"] == toggle: return await ctx.respond(f"That automod option is already set to `{toggle}`.", ephemeral=True) + automod.linkblocker_enabled(ctx.guild.id, toggle) + if toggle is True: await ctx.respond("Link blocker successfully **enabled**.", ephemeral=True) + elif toggle is False: await ctx.respond("Link blocker successfully **disabled**.", ephemeral=True) + + @commands.slash_command( + name="automod_linkblocker_add_whitelist", + description="Adds a link to your server link blocker's whitelist." + ) + @option(name="link", description="The link that you want to add (must be in form of https://{url})", type=str) + async def automod_linkblocker_add_whitelist(self, ctx: ApplicationContext, link: str): + if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) + if link in automod.fetch_config(ctx.guild.id)["link_blocker"]["whitelist"]: return await ctx.respond("This link is already in your server's link blocker whitelist.", ephemeral=True) + if "https://" in link or "http://" in link: + automod.linkblocker_add_whitelisted(link) + await ctx.respond(f"Link `{link}` has successfully been added to whitelist.", ephemeral=True) + else: return await ctx.respond(":warning: The link you entered is not formatted correctly. All added links must contain `https://`.") + + @commands.slash_command( + name="automod_linkblocker_add_blacklist", + description="Adds a link to your server link blocker's blacklist." + ) + @option(name="link", description="The link that you want to add (must be in form of https://{url})", type=str) + async def automod_linkblocker_add_blacklist(self, ctx: ApplicationContext, link: str): + if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) + if link in automod.fetch_config(ctx.guild.id)["link_blocker"]["blacklist"]: return await ctx.respond("This link is already in your server's link blocker blacklist.", ephemeral=True) + if "https://" in link or "http://" in link: + automod.linkblocker_add_blacklisted(link) + await ctx.respond(f"Link `{link}` has successfully been added to blacklist.", ephemeral=True) + else: return await ctx.respond(":warning: The link you entered is not formatted correctly. All added links must contain `https://`.") + def setup(bot): bot.add_cog(Automod(bot)) diff --git a/framework/isobot/db/automod.py b/framework/isobot/db/automod.py index a4214bc..6787606 100644 --- a/framework/isobot/db/automod.py +++ b/framework/isobot/db/automod.py @@ -82,3 +82,24 @@ def linkblocker_enabled(self, server_id: int, value: bool) -> int: automod_config[str(server_id)]["link_blocker"]["enabled"] = value self.save(automod_config) return 0 + + def linkblocker_only_whitelisted_links(self, server_id: int, value: bool) -> int: + """Sets a `bool` value to define whether the server's link blocker only accepts whitelisted links.""" + automod_config = self.load() + automod_config[str(server_id)]["link_blocker"]["use_whitelisted_only"] = value + self.save(automod_config) + return 0 + + def linkblocker_add_whitelisted(self, server_id: int, link: str) -> int: + """Adds a specified link to the server links whitelist. (only works if `use_whitelisted_only = True`)""" + automod_config = self.load() + automod_config[str(server_id)]["link_blocker"]["whitelisted"].append(link) + self.save(automod_config) + return 0 + + def linkblocker_add_blacklisted(self, server_id: int, link: str) -> int: + """Adds a specified link to the server links blacklist. (only works if `use_whitelisted_only = False`)""" + automod_config = self.load() + automod_config[str(server_id)]["link_blocker"]["blacklisted"].append(link) + self.save(automod_config) + return 0 From dfe38a70a23c604c9056a88e21d82933bbe9c2b0 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:05:48 +0530 Subject: [PATCH 07/14] Set `use_whitelist_only` flag to default `True` --- framework/isobot/db/automod.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/isobot/db/automod.py b/framework/isobot/db/automod.py index 6787606..8f0b5f4 100644 --- a/framework/isobot/db/automod.py +++ b/framework/isobot/db/automod.py @@ -35,7 +35,7 @@ def generate(self, server_id: int) -> int: }, "link_blocker": { "enabled": False, - "use_whitelist_only": False, + "use_whitelist_only": True, "whitelisted": [], "blacklisted": [] } From bb6f998c133f8576b3b0805582d95423b0f15190 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:07:00 +0530 Subject: [PATCH 08/14] Add a small comment line to code --- cogs/automod.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cogs/automod.py b/cogs/automod.py index 884ac49..ed7497d 100644 --- a/cogs/automod.py +++ b/cogs/automod.py @@ -28,6 +28,7 @@ async def automod(self, ctx: ApplicationContext): localembed.set_footer(text="More automod features will come soon!") await ctx.respond(embed=localembed) + # Swear-filter Commands @commands.slash_command( name="automod_swearfilter", description="Turn on or off automod's swear-filter in your server" From e997168d1ebca6ce724006fbc37deb2badfd96a8 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:10:19 +0530 Subject: [PATCH 09/14] Add commands to view whitelisted and blacklisted links in server --- cogs/automod.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cogs/automod.py b/cogs/automod.py index ed7497d..d706dd8 100644 --- a/cogs/automod.py +++ b/cogs/automod.py @@ -145,5 +145,39 @@ async def automod_linkblocker_add_blacklist(self, ctx: ApplicationContext, link: automod.linkblocker_add_blacklisted(link) await ctx.respond(f"Link `{link}` has successfully been added to blacklist.", ephemeral=True) else: return await ctx.respond(":warning: The link you entered is not formatted correctly. All added links must contain `https://`.") + + @commands.slash_command( + name="automod_view_whitelisted_links", + description="Shows a list of the whitelisted links set for this server", + ) + async def automod_view_custom_keywords(self, ctx: ApplicationContext): + loaded_config = automod.fetch_config(ctx.guild.id) + out = "" + if loaded_config["link_blocker"]["whitelisted"] != []: + i = 0 + for x in loaded_config["link_blocker"]["whitelisted"]: + i += 1 + out += f"{i}. {x}\n" + else: out = "*No whitelisted links are set for your server.*" + localembed = discord.Embed(title=f"Whitelisted links for {ctx.guild.name}", description=out, color=color) + localembed.set_footer(icon_url=ctx.author.avatar_url, text=f"Requested by {ctx.author}") + await ctx.respond(embed=localembed) + + @commands.slash_command( + name="automod_view_blacklisted_links", + description="Shows a list of the blacklisted links set for this server", + ) + async def automod_view_custom_keywords(self, ctx: ApplicationContext): + loaded_config = automod.fetch_config(ctx.guild.id) + out = "" + if loaded_config["link_blocker"]["blacklisted"] != []: + i = 0 + for x in loaded_config["link_blocker"]["blacklisted"]: + i += 1 + out += f"{i}. {x}\n" + else: out = "*No blacklisted links are set for your server.*" + localembed = discord.Embed(title=f"Blacklisted links for {ctx.guild.name}", description=out, color=color) + localembed.set_footer(icon_url=ctx.author.avatar_url, text=f"Requested by {ctx.author}") + await ctx.respond(embed=localembed) def setup(bot): bot.add_cog(Automod(bot)) From 103767895dd33c37b31b6d56914bb7ca0be71854 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:19:04 +0530 Subject: [PATCH 10/14] Add commands to remove blacklisted/whitelisted links from link blocker --- cogs/automod.py | 22 ++++++++++++++++++++++ framework/isobot/db/automod.py | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/cogs/automod.py b/cogs/automod.py index d706dd8..9eaec71 100644 --- a/cogs/automod.py +++ b/cogs/automod.py @@ -179,5 +179,27 @@ async def automod_view_custom_keywords(self, ctx: ApplicationContext): localembed = discord.Embed(title=f"Blacklisted links for {ctx.guild.name}", description=out, color=color) localembed.set_footer(icon_url=ctx.author.avatar_url, text=f"Requested by {ctx.author}") await ctx.respond(embed=localembed) + + @commands.slash_command( + name="automod_linkblocker_remove_blacklist", + description="Removes a blacklisted link (matching its id) from this server's link blocker" + ) + @option(name="id", description="What's the id of the link to remove? (can be found as serial number through /automod_view_blacklisted_links", type=int) + async def automod_linkblocker_remove_blacklist(self, ctx: ApplicationContext, id: int): + try: + automod.linkblocker_remove_blacklisted(ctx.guild.id, id) + return await ctx.respond(f"Blacklisted link (id: `{id}`) successfully removed from link blocker.") + except IndexError: await ctx.respond("That blacklisted link id doesn't exist. Please specify a valid id and try again.", ephemeral=True) + + @commands.slash_command( + name="automod_linkblocker_remove_whitelist", + description="Removes a whitelisted link (matching its id) from this server's link blocker" + ) + @option(name="id", description="What's the id of the link to remove? (can be found as serial number through /automod_view_whitelisted_links", type=int) + async def automod_linkblocker_remove_whitelist(self, ctx: ApplicationContext, id: int): + try: + automod.linkblocker_remove_whitelisted(ctx.guild.id, id) + return await ctx.respond(f"Whitelisted link (id: `{id}`) successfully removed from link blocker.") + except IndexError: await ctx.respond("That whitelisted link id doesn't exist. Please specify a valid id and try again.", ephemeral=True) def setup(bot): bot.add_cog(Automod(bot)) diff --git a/framework/isobot/db/automod.py b/framework/isobot/db/automod.py index 8f0b5f4..a929be1 100644 --- a/framework/isobot/db/automod.py +++ b/framework/isobot/db/automod.py @@ -103,3 +103,19 @@ def linkblocker_add_blacklisted(self, server_id: int, link: str) -> int: automod_config[str(server_id)]["link_blocker"]["blacklisted"].append(link) self.save(automod_config) return 0 + + def linkblocker_remove_whitelisted(self, server_id: int, keyword_id: int) -> int: + """Removes a whitelisted link (using id) from the server's automod configuration.""" + automod_config = self.load() + data: dict = automod_config[str(server_id)]["link_blocker"]["whitelisted"] + data.pop(keyword_id-1) + self.save(automod_config) + return 0 + + def linkblocker_remove_blacklisted(self, server_id: int, keyword_id: int) -> int: + """Removes a blacklisted link (using id) from the server's automod configuration.""" + automod_config = self.load() + data: dict = automod_config[str(server_id)]["link_blocker"]["blacklisted"] + data.pop(keyword_id-1) + self.save(automod_config) + return 0 From f1127f10bb12671622af4fb2529250e164889a88 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:22:04 +0530 Subject: [PATCH 11/14] Add a few new comments --- main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.py b/main.py index 3e395ad..498e66e 100644 --- a/main.py +++ b/main.py @@ -178,6 +178,7 @@ async def on_message(ctx): except discord.errors.Forbidden: logger.warn("Unable to send level up message to {ctx.author} ({ctx.author.id}), as they are not accepting DMs from isobot. This ID has been added to `levelup_messages` blacklist.", module="main/Levelling") settings.edit_setting(ctx.author.id, "levelup_messages", False) + # Swear-filter try: automod_config = automod.fetch_config(ctx.guild.id) if automod_config["swear_filter"]["enabled"] is True: @@ -186,6 +187,9 @@ async def on_message(ctx): await ctx.channel.send(f'{ctx.author.mention} watch your language.', delete_after=5) except AttributeError: pass + # Link Blocker + + @client.event async def after_invoke(ctx): logger.info(f"A command has been successfully run by {ctx.author.display_name}", module="main/Client", timestamp=True) From 4c8d8860292eb8fc0462d7dd203689601da9f411 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:31:52 +0530 Subject: [PATCH 12/14] Add code to check whether link sent in channel matches whitelisted/blacklisted --- main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.py b/main.py index 498e66e..460ae28 100644 --- a/main.py +++ b/main.py @@ -188,6 +188,20 @@ async def on_message(ctx): except AttributeError: pass # Link Blocker + try: + if ("http://" in ctx.content.lower()) or ("https://" in ctx.content.lower()): + automod_config = automod.fetch_config(ctx.guild.id) + if automod_config["link_blocker"]["enabled"] is True: + if automod_config["link_blocker"]["use_whitelist_only"]: + if not any(x in ctx.content.lower() for x in automod_config["link_blocker"]["whitelisted"]["default"]): + await ctx.delete() + await ctx.channel.send(f'{ctx.author.mention} This link is not allowed in this server.', delete_after=5) + else: + if any(x in ctx.content.lower() for x in automod_config["link_blocker"]["blacklisted"]["default"]): + await ctx.delete() + await ctx.channel.send(f'{ctx.author.mention} This link is not allowed in this server.', delete_after=5) + except AttributeError: pass + @client.event From 2f480360199d5fefb04c53988b1902bea6e5c66a Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:36:01 +0530 Subject: [PATCH 13/14] Add missing permission checks for a few automod commands --- cogs/automod.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cogs/automod.py b/cogs/automod.py index 9eaec71..5fe6ed3 100644 --- a/cogs/automod.py +++ b/cogs/automod.py @@ -90,6 +90,7 @@ async def automod_add_custom_keyword(self, ctx: ApplicationContext, keyword:str) ) @option(name="id", description="What's the id of the keyword to remove (can be found in bold through /automod_view_custom_keywords", type=int) async def automod_remove_custom_keyword(self, ctx: ApplicationContext, id: int): + if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) try: automod.swearfilter_removekeyword(ctx.guild.id, id) return await ctx.respond(f"Keyword (id: `{id}`) successfully removed from swear-filter configuration.") @@ -186,6 +187,7 @@ async def automod_view_custom_keywords(self, ctx: ApplicationContext): ) @option(name="id", description="What's the id of the link to remove? (can be found as serial number through /automod_view_blacklisted_links", type=int) async def automod_linkblocker_remove_blacklist(self, ctx: ApplicationContext, id: int): + if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) try: automod.linkblocker_remove_blacklisted(ctx.guild.id, id) return await ctx.respond(f"Blacklisted link (id: `{id}`) successfully removed from link blocker.") @@ -197,6 +199,7 @@ async def automod_linkblocker_remove_blacklist(self, ctx: ApplicationContext, id ) @option(name="id", description="What's the id of the link to remove? (can be found as serial number through /automod_view_whitelisted_links", type=int) async def automod_linkblocker_remove_whitelist(self, ctx: ApplicationContext, id: int): + if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) try: automod.linkblocker_remove_whitelisted(ctx.guild.id, id) return await ctx.respond(f"Whitelisted link (id: `{id}`) successfully removed from link blocker.") From 4a621ce26f352392d865ebad2978f254037bb949 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:37:27 +0530 Subject: [PATCH 14/14] Add Discord markdown V2 support for command embed --- cogs/automod.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/automod.py b/cogs/automod.py index 5fe6ed3..17cc9fc 100644 --- a/cogs/automod.py +++ b/cogs/automod.py @@ -64,7 +64,7 @@ async def automod_view_custom_keywords(self, ctx: ApplicationContext): i = 0 for x in loaded_config["swear_filter"]["keywords"]["custom"]: i += 1 - out += f"**{i})** {x}\n" + out += f"{i}. {x}\n" else: out = "*No custom keywords are set for your server.*" localembed = discord.Embed(title=f"Custom Swear-filter keywords for {ctx.guild.name}", description=out, color=color) localembed.set_footer(icon_url=ctx.author.avatar_url, text=f"Requested by {ctx.author}") @@ -88,7 +88,7 @@ async def automod_add_custom_keyword(self, ctx: ApplicationContext, keyword:str) name="automod_remove_custom_keyword", description="Removes a custom keyword (matching its id) from your server's swear-filter" ) - @option(name="id", description="What's the id of the keyword to remove (can be found in bold through /automod_view_custom_keywords", type=int) + @option(name="id", description="What's the id of the keyword to remove (can be found as serial number through /automod_view_custom_keywords", type=int) async def automod_remove_custom_keyword(self, ctx: ApplicationContext, id: int): if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True) try: