Discord/cogs/logger.py

68 lines
2.1 KiB
Python
Raw Normal View History

2023-05-06 18:08:35 +03:00
from discord import Member, Message
from discord import utils as ds_utils
from discord.ext import commands
2024-06-23 13:05:03 +03:00
from libbot.pycord.classes import PycordBot
2023-05-06 18:08:35 +03:00
from modules.database import col_users
from modules.utils import config_get
class Logger(commands.Cog):
2024-06-23 13:05:03 +03:00
def __init__(self, client: PycordBot):
2023-05-06 18:08:35 +03:00
self.client = client
@commands.Cog.listener()
async def on_message(self, message: Message):
if (
(message.author != self.client.user)
and (message.author.bot == False)
and (message.author.system == False)
):
2023-05-06 18:08:35 +03:00
if col_users.find_one({"user": message.author.id}) is None:
user = {}
defaults = await config_get("user", "defaults")
2023-05-06 18:08:35 +03:00
user["user"] = message.author.id
for key in defaults:
user[key] = defaults[key]
col_users.insert_one(document=user)
@commands.Cog.listener()
async def on_member_join(self, member: Member):
welcome_chan = ds_utils.get(
self.client.get_guild(await config_get("guild")).channels,
id=await config_get("welcome", "channels", "text"),
)
rules_chan = ds_utils.get(
self.client.get_guild(await config_get("guild")).channels,
id=await config_get("rules", "channels", "text"),
)
if (
(member != self.client.user)
and (member.bot == False)
and (member.system == False)
):
await welcome_chan.send(
content=(await config_get("welcome", "messages")).format(
mention=member.mention, rules=rules_chan.mention
)
)
2023-05-06 18:08:35 +03:00
if col_users.find_one({"user": member.id}) is None:
user = {}
defaults = await config_get("user", "defaults")
2023-05-06 18:08:35 +03:00
user["user"] = member.id
for key in defaults:
2023-05-06 19:31:23 +03:00
user[key] = defaults[key]
col_users.insert_one(document=user)
2024-06-23 13:05:03 +03:00
def setup(client: PycordBot):
client.add_cog(Logger(client))