2024-12-16 21:34:37 +02:00
|
|
|
from typing import Dict, Any, Union
|
|
|
|
|
|
|
|
from discord import Member, Message, TextChannel
|
2023-05-06 18:08:35 +03:00
|
|
|
from discord import utils as ds_utils
|
|
|
|
from discord.ext import commands
|
2024-12-16 00:36:48 +02:00
|
|
|
from libbot import config_get
|
2023-05-06 18:08:35 +03:00
|
|
|
|
2024-12-17 23:14:06 +02:00
|
|
|
from classes.holo_bot import HoloBot
|
2023-05-06 18:08:35 +03:00
|
|
|
from modules.database import col_users
|
|
|
|
|
|
|
|
|
|
|
|
class Logger(commands.Cog):
|
2024-12-17 23:14:06 +02:00
|
|
|
def __init__(self, client: HoloBot):
|
|
|
|
self.client: HoloBot = client
|
2023-05-06 18:08:35 +03:00
|
|
|
|
|
|
|
@commands.Cog.listener()
|
|
|
|
async def on_message(self, message: Message):
|
2023-05-06 19:56:01 +03:00
|
|
|
if (
|
|
|
|
(message.author != self.client.user)
|
2024-12-16 00:21:41 +02:00
|
|
|
and (message.author.bot is False)
|
|
|
|
and (message.author.system is False)
|
2023-05-06 19:56:01 +03:00
|
|
|
):
|
2024-12-16 17:25:35 +02:00
|
|
|
if (await col_users.find_one({"user": message.author.id})) is None:
|
2024-12-16 21:34:37 +02:00
|
|
|
user: Dict[str, Any] = {}
|
|
|
|
defaults: Dict[str, Any] = await config_get("user", "defaults")
|
2023-05-06 19:56:01 +03:00
|
|
|
|
2023-05-06 18:08:35 +03:00
|
|
|
user["user"] = message.author.id
|
|
|
|
|
|
|
|
for key in defaults:
|
|
|
|
user[key] = defaults[key]
|
|
|
|
|
2024-12-16 17:25:35 +02:00
|
|
|
await col_users.insert_one(document=user)
|
2023-05-06 18:08:35 +03:00
|
|
|
|
|
|
|
@commands.Cog.listener()
|
2024-12-16 21:34:37 +02:00
|
|
|
async def on_member_join(self, member: Member) -> None:
|
|
|
|
welcome_chan: Union[TextChannel, None] = ds_utils.get(
|
2023-05-06 19:56:01 +03:00
|
|
|
self.client.get_guild(await config_get("guild")).channels,
|
|
|
|
id=await config_get("welcome", "channels", "text"),
|
|
|
|
)
|
2024-12-16 21:34:37 +02:00
|
|
|
rules_chan: Union[TextChannel, None] = ds_utils.get(
|
2023-05-06 19:56:01 +03:00
|
|
|
self.client.get_guild(await config_get("guild")).channels,
|
|
|
|
id=await config_get("rules", "channels", "text"),
|
|
|
|
)
|
|
|
|
|
|
|
|
if (
|
|
|
|
(member != self.client.user)
|
2024-12-16 00:21:41 +02:00
|
|
|
and (member.bot is False)
|
|
|
|
and (member.system is False)
|
2023-05-06 19:56:01 +03:00
|
|
|
):
|
|
|
|
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
|
|
|
|
2024-12-16 17:25:35 +02:00
|
|
|
if (await col_users.find_one({"user": member.id})) is None:
|
2024-12-16 21:34:37 +02:00
|
|
|
user: Dict[str, Any] = {}
|
|
|
|
defaults: Dict[str, Any] = await config_get("user", "defaults")
|
2023-05-06 19:56:01 +03:00
|
|
|
|
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]
|
|
|
|
|
2024-12-16 17:25:35 +02:00
|
|
|
await col_users.insert_one(document=user)
|
2024-06-23 13:05:03 +03:00
|
|
|
|
|
|
|
|
2024-12-17 23:14:06 +02:00
|
|
|
def setup(client: HoloBot) -> None:
|
2024-06-23 13:05:03 +03:00
|
|
|
client.add_cog(Logger(client))
|