2023-05-06 18:52:46 +03:00
|
|
|
import logging
|
2024-12-16 21:34:37 +02:00
|
|
|
from typing import Dict, List, Any
|
2023-05-06 20:17:40 +03:00
|
|
|
|
|
|
|
from discord import Cog, Message
|
2023-05-06 18:52:46 +03:00
|
|
|
from discord.ext import commands
|
|
|
|
|
2024-12-17 23:14:06 +02:00
|
|
|
from classes.holo_bot import HoloBot
|
2023-05-06 20:17:40 +03:00
|
|
|
from modules.database import col_analytics
|
2023-05-06 18:52:46 +03:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Analytics(commands.Cog):
|
2024-12-17 23:14:06 +02:00
|
|
|
def __init__(self, client: HoloBot):
|
|
|
|
self.client: HoloBot = client
|
2023-05-06 18:52:46 +03:00
|
|
|
|
|
|
|
@Cog.listener()
|
2024-12-16 21:34:37 +02:00
|
|
|
async def on_message(self, message: Message) -> None:
|
2023-05-06 18:52:46 +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 18:52:46 +03:00
|
|
|
):
|
2024-12-16 21:34:37 +02:00
|
|
|
stickers: List[Dict[str, Any]] = []
|
|
|
|
|
2023-05-07 10:57:35 +03:00
|
|
|
for sticker in message.stickers:
|
|
|
|
stickers.append(
|
|
|
|
{
|
|
|
|
"id": sticker.id,
|
|
|
|
"name": sticker.name,
|
|
|
|
"format": sticker.format,
|
|
|
|
"url": sticker.url,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-12-16 21:34:37 +02:00
|
|
|
attachments: List[Dict[str, Any]] = []
|
|
|
|
|
2023-05-07 10:57:35 +03:00
|
|
|
for attachment in message.attachments:
|
|
|
|
attachments.append(
|
|
|
|
{
|
|
|
|
"content_type": attachment.content_type,
|
|
|
|
"description": attachment.description,
|
|
|
|
"filename": attachment.filename,
|
|
|
|
"is_spoiler": attachment.is_spoiler(),
|
|
|
|
"size": attachment.size,
|
|
|
|
"url": attachment.url,
|
|
|
|
"width": attachment.width,
|
|
|
|
"height": attachment.height,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-12-16 17:25:35 +02:00
|
|
|
await col_analytics.insert_one(
|
2023-05-06 18:52:46 +03:00
|
|
|
{
|
|
|
|
"user": message.author.id,
|
|
|
|
"channel": message.channel.id,
|
2023-05-07 10:57:35 +03:00
|
|
|
"content": message.content,
|
2023-05-08 20:27:22 +03:00
|
|
|
"stickers": stickers,
|
2023-05-07 10:57:35 +03:00
|
|
|
"attachments": attachments,
|
2023-05-06 18:52:46 +03:00
|
|
|
}
|
|
|
|
)
|
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(Analytics(client))
|