feat(logger): added the cog

This commit is contained in:
Seaswimmer 2024-05-24 02:55:52 -04:00
parent 09ab8aa69d
commit 1a26d82c36
Signed by: cswimr
GPG key ID: 5D671B5D03D65A7F
5 changed files with 208 additions and 0 deletions

7
logger/__init__.py Normal file
View file

@ -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))

106
logger/config.py Normal file
View file

@ -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,
)

17
logger/info.json Normal file
View file

@ -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"
]
}

48
logger/logger.py Normal file
View file

@ -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)

30
logger/menu.py Normal file
View file

@ -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)