import logging from typing import Dict, List, Any from discord import Cog, Message from discord.ext import commands from classes.holo_bot import HoloBot from modules.database import col_analytics logger = logging.getLogger(__name__) class Analytics(commands.Cog): def __init__(self, client: HoloBot): self.client: HoloBot = client @Cog.listener() async def on_message(self, message: Message) -> None: if ( (message.author != self.client.user) and (message.author.bot is False) and (message.author.system is False) ): stickers: List[Dict[str, Any]] = [] for sticker in message.stickers: stickers.append( { "id": sticker.id, "name": sticker.name, "format": sticker.format, "url": sticker.url, } ) attachments: List[Dict[str, Any]] = [] 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, } ) await col_analytics.insert_one( { "user": message.author.id, "channel": message.channel.id, "content": message.content, "stickers": stickers, "attachments": attachments, } ) def setup(client: HoloBot) -> None: client.add_cog(Analytics(client))