Compare commits
12 commits
Author | SHA1 | Date | |
---|---|---|---|
ce3193e113 | |||
6e7171fc48 | |||
c584fb60e2 | |||
742d786bab | |||
6d0d45736d | |||
ce502d5725 | |||
7520ee783b | |||
0f1a9fb66c | |||
0f82ddcf7b | |||
6fbd2531a8 | |||
24703bb32f | |||
1a26d82c36 |
5 changed files with 208 additions and 0 deletions
7
logger/__init__.py
Normal file
7
logger/__init__.py
Normal 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
106
logger/config.py
Normal 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
17
logger/info.json
Normal 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
48
logger/logger.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
from datetime import UTC, datetime
|
||||
|
||||
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 payload.guild_id:
|
||||
guild = self.bot.get_guild(payload.guild_id)
|
||||
if guild is None:
|
||||
return
|
||||
else:
|
||||
return
|
||||
|
||||
if await self.bot.cog_disabled_in_guild(self, guild):
|
||||
return
|
||||
|
||||
if payload.channel_id in await config.guild(guild).message_ignored_channels():
|
||||
return
|
||||
|
||||
if payload.cached_message:
|
||||
if payload.cached_message.author.bot:
|
||||
return
|
||||
|
||||
content = f">>> {payload.cached_message.content}"
|
||||
|
||||
author = payload.cached_message.author
|
||||
|
||||
c = await config.guild(guild).message_delete_channel()
|
||||
if c:
|
||||
channel = self.bot.get_channel(c)
|
||||
if channel:
|
||||
embed = discord.Embed(color=discord.Color.from_str(value="#ff470f"), timestamp=datetime.now(tz=UTC))
|
||||
embed.set_author(name=f"{author.name}", icon_url=author.display_avatar.url)
|
||||
embed.description = bold(text=f"Message sent by {author.mention} deleted in {payload.cached_message.channel.mention}\n", escape_formatting=False) + content
|
||||
embed.set_footer(text=f"Author: {author.id} | Message ID: {payload.message_id}", icon_url=guild.icon.url)
|
||||
|
||||
await channel.send(embed=embed)
|
30
logger/menu.py
Normal file
30
logger/menu.py
Normal 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)
|
Loading…
Reference in a new issue