Преглед на файлове

Added a system, where the supervisors a informated when a department member leaves the server.

BaumSplitter41 преди 1 месец
родител
ревизия
44308363eb
променени са 3 файла, в които са добавени 56 реда и са изтрити 5 реда
  1. 53 0
      VPD_BOT/cogs/info_on_leave.py
  2. 0 5
      VPD_BOT/cogs/ping_on_einweisung.py
  3. 3 0
      VPD_BOT/config.cfg

+ 53 - 0
VPD_BOT/cogs/info_on_leave.py

@@ -0,0 +1,53 @@
+import discord
+from discord.ext import commands
+from discord.commands import Option
+from discord.commands import slash_command
+import configparser
+import time
+
+#Gives supervisors an information, when a department member leaves the server.
+
+class infoleaving(commands.Cog):
+    def __init__(self, bot: discord.Bot):
+        self.bot = bot
+    
+    def _load_config(self):
+        config = configparser.ConfigParser()
+        configFilePath = r'config.cfg'
+        config.read(configFilePath)
+        return config
+    def _get_info_channel(self):
+        config = self._load_config()
+        info_channel_id = int(config["Einweisung"]["info_channel_id"])
+        info_channel = self.bot.get_channel(info_channel_id)
+        if info_channel is None:
+            print(f"Log channel with ID {info_channel_id} not found.")
+            return None
+        return info_channel
+    
+    @commands.Cog.listener()
+    async def on_member_remove(self, member):
+
+        config = self._load_config()
+        enable_info = config.getboolean("Einweisung","enable_channel_info_on_leaving")
+        if not enable_info:
+            return
+        info_channel = self._get_info_channel()
+        if info_channel is None:
+            return
+        department_roles_ids = [int(role_id.strip()) for role_id in config.get("Role Management", "department1_ranks").split(",")]
+        department_roles = [member.guild.get_role(role_id) for role_id in department_roles_ids]
+        if any(role.id in department_roles for role in member.roles):
+            embed = discord.Embed(
+                title="Departmentmeber left the server.",
+                description=f"{member.mention} has left the server. Name: {member.name}, {member.nick}, ID: {member.id}",
+                color=discord.Color.dark_red(),
+                timestamp=discord.utils.utcnow()
+            )
+            embed.set_footer(text=f"User ID: {member.id}")
+            await info_channel.send(embed=embed)
+        else:
+            return
+
+def setup(bot: discord.Bot):
+    bot.add_cog(infoleaving(bot))

+ 0 - 5
VPD_BOT/cogs/ping_on_einweisung.py

@@ -44,11 +44,6 @@ class einweisungping(commands.Cog):
             if after.channel.id == channel_join_id: 
                 ping_message = f"{' '.join(role.mention for role in ping_roles)} {member.mention} ist dem Einweisungskanal beigetreten!"
                 await channel_ping.send(ping_message)
-        
-
-        
-
-
 
 def setup(bot: discord.Bot):
     bot.add_cog(einweisungping(bot))

+ 3 - 0
VPD_BOT/config.cfg

@@ -40,6 +40,9 @@ channel_ping_id = 1481397681996697620
 channel_join_id = 1469775998424846542
 ping_role_id = 1459945390571782245, 1459945659548565634, 1469776566882930690
 
+enable_channel_info_on_leaving = true
+channel_info_id = 1472559057465245737
+
 #Role IDs for the rolemanagment commands
 [Role Management]
 department1_command = 1451668309648084992