Forráskód Böngészése

Added a funktion which deletes blacklisted words. Exeption for Mods included.

BaumSplitter41 3 hónapja
szülő
commit
e6d5c66ddf
2 módosított fájl, 46 hozzáadás és 1 törlés
  1. 38 0
      VPD_BOT/cogs/blacklisted_words.py
  2. 8 1
      VPD_BOT/config.cfg

+ 38 - 0
VPD_BOT/cogs/blacklisted_words.py

@@ -0,0 +1,38 @@
+import discord
+from discord.ext import commands
+from discord.commands import Option
+from discord.commands import slash_command
+import configparser
+
+
+class blacklist_words(commands.Cog):
+    def __init__(self, bot: discord.Bot):
+        self.bot = bot
+    
+
+    @commands.Cog.listener()
+    async def on_message(self, message):
+        if message.author.bot:
+            return
+
+        config = configparser.ConfigParser()
+        config.read('config.ini')
+        blacklist_words_words = config.get('Moderation', 'Blacklist_Words_List').split(',')
+        blacklist_words_words = [word.strip().lower() for word in blacklist_words_words]
+        team_role_ids = [int(role_id) for role_id in config.get('Moderation', 'Mod_role_IDs').split(',') if role_id.strip().isdigit()]
+        author_roles = [role.id for role in message.author.roles]
+        if any(role_id in author_roles for role_id in team_role_ids):
+            return
+
+        for word in blacklist_words_words:
+            if word in message.content.lower():
+                try:
+                    await message.delete()
+                    warning_msg = f"{message.author.mention}, your message was removed due to the use of prohibited language."
+                    await message.channel.send(warning_msg, delete_after=5)
+                except discord.Forbidden:
+                    print("Missing permissions to delete messages.")
+                break
+
+def setup(bot: discord.Bot):
+    bot.add_cog(blacklist_words(bot))

+ 8 - 1
VPD_BOT/config.cfg

@@ -38,4 +38,11 @@ department2_ranks =
 department2_units =
 department2_head_unit =
 
-remove_access_role_on_fire = true
+remove_access_role_on_fire = true
+
+[Moderation]
+Mod_role_IDs = 1447295632774660158
+Blacklist_Words = true
+Antispam = true
+Blacklist_Words_List = buy now, free money, click here, visit this site, subscribe, follow me, check this out
+Spam_Sensitivity_Index = 5  #Number of Messages within 10 seconds considered as spam