Переглянути джерело

Added the posibility to print logs in channel about actions on the server. For example messages deleted, edited or members leave and join and role updates.

BaumSplitter41 3 місяців тому
батько
коміт
eb840a151b
2 змінених файлів з 215 додано та 0 видалено
  1. 214 0
      VPD_BOT/cogs/logs.py
  2. 1 0
      VPD_BOT/config.cfg

+ 214 - 0
VPD_BOT/cogs/logs.py

@@ -0,0 +1,214 @@
+import discord
+from discord.ext import commands
+from discord.commands import Option
+from discord.commands import slash_command
+import configparser
+import time
+
+
+class actionlog(commands.Cog):
+    def __init__(self, bot: discord.Bot):
+        self.bot = bot
+    
+#Delted Message Log
+    @commands.Cog.listener()
+    async def on_message_delete(self, message):
+
+        config = configparser.ConfigParser()
+        config.read("config.ini")
+        enable_log = config.getboolean("LOGS","enable_action_log")
+        if enable_log == "false":
+            return
+        log_channel_id = int(config["LOGS"]["action_log_channel_id"])
+        log_channel = self.bot.get_channel(log_channel_id)
+        if message.author.bot:
+            return
+        else:
+            embed = discord.Embed(
+                title="Message Deleted",
+                description=f"A message by {message.author.mention} was deleted in {message.channel.mention}.",
+                color=discord.Color.red(),
+                timestamp=message.created_at
+            )
+            embed.add_field(name="Message Content", value=message.content or "No content", inline=False)
+            embed.set_footer(text=f"User ID: {message.author.id} | Message ID: {message.id}")
+            await log_channel.send(embed=embed)
+
+#Edited Message Log
+    @commands.Cog.listener()
+    async def on_message_edit(self, before, after):
+
+        config = configparser.ConfigParser()
+        config.read("config.ini")
+        enable_log = config.getboolean("LOGS","enable_action_log")
+        if enable_log == "false":
+            return
+        log_channel_id = int(config["LOGS"]["action_log_channel_id"])
+        log_channel = self.bot.get_channel(log_channel_id)
+        if before.author.bot:
+            return
+        else:
+            embed = discord.Embed(
+                title="Message Edited",
+                description=f"A message by {before.author.mention} was edited in {before.channel.mention}.",
+                color=discord.Color.orange(),
+                timestamp=after.edited_at or discord.utils.utcnow()
+            )
+            embed.add_field(name="Before", value=before.content or "No content", inline=False)
+            embed.add_field(name="After", value=after.content or "No content", inline=False)
+            embed.set_footer(text=f"User ID: {before.author.id} | Message ID: {before.id}")
+            await log_channel.send(embed=embed)
+
+#Member Join Log
+    @commands.Cog.listener()
+    async def on_member_join(self, member):
+
+        config = configparser.ConfigParser()
+        config.read("config.ini")
+        enable_log = config.getboolean("LOGS","enable_action_log")
+        if enable_log == "false":
+            return
+        log_channel_id = int(config["LOGS"]["action_log_channel_id"])
+        log_channel = self.bot.get_channel(log_channel_id)
+
+        embed = discord.Embed(
+            title="Member Joined",
+            description=f"{member.mention} has joined the server.",
+            color=discord.Color.green(),
+            timestamp=discord.utils.utcnow()
+        )
+        embed.set_footer(text=f"User ID: {member.id}")
+        await log_channel.send(embed=embed)
+
+#Member Leave Log
+    @commands.Cog.listener()
+    async def on_member_remove(self, member):
+
+        config = configparser.ConfigParser()
+        config.read("config.ini")
+        enable_log = config.getboolean("LOGS","enable_action_log")
+        if enable_log == "false":
+            return
+        log_channel_id = int(config["LOGS"]["action_log_channel_id"])
+        log_channel = self.bot.get_channel(log_channel_id)
+
+        embed = discord.Embed(
+            title="Member Left",
+            description=f"{member.mention} has left the server.",
+            color=discord.Color.dark_red(),
+            timestamp=discord.utils.utcnow()
+        )
+        embed.set_footer(text=f"User ID: {member.id}")
+        await log_channel.send(embed=embed)
+
+
+#Role Update Log
+    @commands.Cog.listener()
+    async def on_guild_role_update(self, before, after):
+
+        config = configparser.ConfigParser()
+        config.read("config.ini")
+        enable_log = config.getboolean("LOGS","enable_action_log")
+        if enable_log == "false":
+            return
+        log_channel_id = int(config["LOGS"]["action_log_channel_id"])
+        log_channel = self.bot.get_channel(log_channel_id)
+
+        embed = discord.Embed(
+            title="Role Updated",
+            description=f"The role **{before.name}** has been updated.",
+            color=discord.Color.blue(),
+            timestamp=discord.utils.utcnow()
+        )
+        embed.add_field(name="Before", value=f"Name: {before.name}\nColor: {before.color}\nPermissions: {before.permissions}", inline=False)
+        embed.add_field(name="After", value=f"Name: {after.name}\nColor: {after.color}\nPermissions: {after.permissions}", inline=False)
+        embed.set_footer(text=f"Role ID: {before.id}")
+        await log_channel.send(embed=embed)
+
+#Role added log
+
+    @commands.Cog.listener()
+    async def on_guild_role_create(self, role):
+
+        config = configparser.ConfigParser()
+        config.read("config.ini")
+        enable_log = config.getboolean("LOGS","enable_action_log")
+        if enable_log == "false":
+            return
+        log_channel_id = int(config["LOGS"]["action_log_channel_id"])
+        log_channel = self.bot.get_channel(log_channel_id)
+
+        embed = discord.Embed(
+            title="Role Created",
+            description=f"The role **{role.name}** has been created.",
+            color=discord.Color.green(),
+            timestamp=discord.utils.utcnow()
+        )
+        embed.set_footer(text=f"Role ID: {role.id}")
+        await log_channel.send(embed=embed)
+
+#Role deleted log
+
+    @commands.Cog.listener()
+    async def on_guild_role_delete(self, role):
+
+        config = configparser.ConfigParser()
+        config.read("config.ini")
+        enable_log = config.getboolean("LOGS","enable_action_log")
+        if enable_log == "false":
+            return
+        log_channel_id = int(config["LOGS"]["action_log_channel_id"])
+        log_channel = self.bot.get_channel(log_channel_id)
+
+        embed = discord.Embed(
+            title="Role Deleted",
+            description=f"The role **{role.name}** has been deleted.",
+            color=discord.Color.red(),
+            timestamp=discord.utils.utcnow()
+        )
+        embed.set_footer(text=f"Role ID: {role.id}")
+        await log_channel.send(embed=embed)
+
+
+#User Role update log
+    @commands.Cog.listener()
+    async def on_member_update(self, before, after):
+        
+        config = configparser.ConfigParser()
+        config.read("config.ini")
+        enable_log = config.getboolean("LOGS","enable_action_log")
+        if enable_log == "false":
+            return
+        log_channel_id = int(config["LOGS"]["action_log_channel_id"])
+        log_channel = self.bot.get_channel(log_channel_id)
+
+        before_roles = set(before.roles)
+        after_roles = set(after.roles)
+
+        added_roles = after_roles - before_roles
+        removed_roles = before_roles - after_roles
+
+        for role in added_roles:
+            embed = discord.Embed(
+                title="Role Added",
+                description=f"The role **{role.name}** has been added to {after.mention}.",
+                color=discord.Color.green(),
+                timestamp=discord.utils.utcnow()
+            )
+            embed.set_footer(text=f"User ID: {after.id} | Role ID: {role.id}")
+            await log_channel.send(embed=embed)
+
+        for role in removed_roles:
+            embed = discord.Embed(
+                title="Role Removed",
+                description=f"The role **{role.name}** has been removed from {after.mention}.",
+                color=discord.Color.red(),
+                timestamp=discord.utils.utcnow()
+            )
+            embed.set_footer(text=f"User ID: {after.id} | Role ID: {role.id}")
+            await log_channel.send(embed=embed)
+
+
+
+def setup(bot: discord.Bot):
+    bot.add_cog(actionlog(bot))

+ 1 - 0
VPD_BOT/config.cfg

@@ -8,6 +8,7 @@ rules_role = 1442528544394575892
 status_log = 1448305623287464050
 mod_log = 1447580463668400305
 action_log = 1466410535271530735
+enable_action_log = true
 
 #Role IDs for the Teamroles
 [Team Roles]