diff --git a/logger/__init__.py b/logger/__init__.py new file mode 100644 index 0000000..df5efcd --- /dev/null +++ b/logger/__init__.py @@ -0,0 +1,7 @@ +from redbot.core.bot import Red + +from .logger import Logger + + +async def setup(bot: Red) -> None: + await bot.add_cog(Logger(bot)) diff --git a/logger/config.py b/logger/config.py new file mode 100644 index 0000000..470cf99 --- /dev/null +++ b/logger/config.py @@ -0,0 +1,106 @@ +from redbot.core import Config + +config: Config = Config.get_conf(None, identifier=34236413658947743, cog_name="Logger", force_registration=True) + +def register_config(): + config.register_guild( + guild_update = False, + guild_update_channel = None, + channel_update = False, + channel_update_channel = None, + channel_delete = False, + channel_delete_channel = None, + overwrite_create = False, + overwrite_create_channel = None, + overwrite_update = False, + overwrite_update_channel = None, + overwrite_delete = False, + overwrite_delete_channel = None, + kick = False, + kick_channel = None, + member_prune = False, + member_prune_channel = None, + ban = False, + ban_channel = None, + unban = False, + unban_channel = None, + member_update = False, + member_update_channel = None, + member_role_update = False, + member_role_update_channel = None, + member_move = False, + member_move_channel = None, + member_disconnect = False, + member_disconnect_channel = None, + bot_add = False, + bot_add_channel = None, + role_create = False, + role_create_channel = None, + role_update = False, + role_update_channel = None, + role_delete = False, + role_delete_channel = None, + invite_create = False, + invite_create_channel = None, + invite_delete = False, + invite_delete_channel = None, + webhook_create = False, + webhook_create_channel = None, + webhook_update = False, + webhook_update_channel = None, + webhook_delete = False, + webhook_delete_channel = None, + emoji_create = False, + emoji_create_channel = None, + emoji_update = False, + emoji_update_channel = None, + emoji_delete = False, + emoji_delete_channel = None, + message_delete = False, + message_delete_channel = 967981200549494804, + message_edit = False, + message_edit_channel = 967981200549494804, + message_pin = False, + message_pin_channel = None, + message_unpin = False, + message_unpin_channel = None, + message_ignored_channels = [], + integration_create = False, + integration_create_channel = None, + integration_update = False, + integration_update_channel = None, + integration_delete = False, + integration_delete_channel = None, + stage_instance_create = False, + stage_instance_create_channel = None, + stage_instance_update = False, + stage_instance_update_channel = None, + stage_instance_delete = False, + stage_instance_delete_channel = None, + sticker_create = False, + sticker_create_channel = None, + sticker_update = False, + sticker_update_channel = None, + sticker_delete = False, + sticker_delete_channel = None, + scheduled_event_create = False, + scheduled_event_create_channel = None, + scheduled_event_update = False, + scheduled_event_update_channel = None, + scheduled_event_delete = False, + scheduled_event_delete_channel = None, + thread_create = False, + thread_create_channel = None, + thread_update = False, + thread_update_channel = None, + thread_delete = False, + thread_delete_channel = None, + app_command_permission_update = False, + app_command_permission_update_channel = None, + automod_rule_create = False, + automod_rule_create_channel = None, + automod_rule_update = False, + automod_rule_update_channel = None, + automod_rule_delete = False, + automod_rule_delete_channel = None, + ) diff --git a/logger/info.json b/logger/info.json new file mode 100644 index 0000000..42b8064 --- /dev/null +++ b/logger/info.json @@ -0,0 +1,17 @@ +{ + "author" : ["SeaswimmerTheFsh (seasw.)"], + "install_msg" : "Thank you for installing Logger!", + "name" : "Logger", + "short" : "Log events configurably.", + "description" : "Logger logs events to a channel of your choice. You can configure which events to log and which channel to log them to.", + "end_user_data_statement" : "This cog does not store end user data.", + "hidden": false, + "disabled": false, + "min_bot_version": "3.5.0", + "min_python_version": [3, 10, 0], + "tags": [ + "utility", + "moderation", + "logging" + ] + } diff --git a/logger/logger.py b/logger/logger.py new file mode 100644 index 0000000..a4be99c --- /dev/null +++ b/logger/logger.py @@ -0,0 +1,48 @@ +import time + +import discord +from redbot.core import commands +from redbot.core.bot import Red +from redbot.core.utils.chat_formatting import bold + +from .config import config, register_config + + +class Logger(commands.Cog): + def __init__(self, bot: Red) -> None: + self.bot: Red = bot + register_config() + + @commands.Cog.listener() + async def on_raw_message_delete(self, payload: discord.RawMessageDeleteEvent) -> None: + if not payload.guild_id: + return + + if self.bot.cog_disabled_in_guild(self, payload.guild_id): + return + + #if payload.channel_id in await config.guild(payload.guild_id).message_ignored_channels(): + #return + + if payload.cached_message: + if payload.cached_message.author.bot: + return + + if len(payload.cached_message.content) > 3898: + content = payload.cached_message.content[:3900] + "..." + else: + content = payload.cached_message.content + + author = payload.cached_message.author + + c = await config.guild(payload.guild_id).message_delete_channel() + if c: + channel = self.bot.get_channel(c) + if channel: + embed = discord.Embed(color=discord.Color.from_str(value="#ff470f")) + embed.set_author(name=f"{author.display_name} - Deleted Message", icon_url=author.display_avatar.url) + embed.description = bold(text=f"Message sent by {author.mention} deleted in {payload.cached_message.channel.mention}") + content + embed.set_footer(text=f"Author: {author.id} | Message ID: {payload.message_id}") + embed.timestamp = time.time() + + await channel.send(embed=embed) diff --git a/logger/menu.py b/logger/menu.py new file mode 100644 index 0000000..b55a0eb --- /dev/null +++ b/logger/menu.py @@ -0,0 +1,30 @@ + +from discord import Embed, Message, ui +from redbot.core import commands + +from .config import config + + +async def get_config(ctx: commands.Context) -> dict: + return dict(sorted(await config.guild(ctx.guild).all().items())) + +async def get_embed(ctx: commands.Context, type: str = None): + conf = await get_config(ctx) + if not type or type not in conf.keys(): + embed = Embed( + title="Logger Configuration - Message Delete", + description="Please select a configuration option below.", + color=await ctx.embed_color(), + ) + + +class ConfigMenu(ui.View): + def __init__(self, ctx: commands.Context, message: Message, type: str = None, timeout: int = None): + super().__init__() + self.ctx = ctx + self.message = message + self.type = type + self.timeout = timeout + + async def on_timeout(self): + await self.message.edit(view=None)