Discord/cogs/analytics.py
2024-06-23 12:05:03 +02:00

62 lines
1.9 KiB
Python

import logging
from discord import Cog, Message
from discord.ext import commands
from libbot.pycord.classes import PycordBot
from modules.database import col_analytics
logger = logging.getLogger(__name__)
class Analytics(commands.Cog):
def __init__(self, client: PycordBot):
self.client = client
@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)
):
stickers = []
for sticker in message.stickers:
stickers.append(
{
"id": sticker.id,
"name": sticker.name,
"format": sticker.format,
"url": sticker.url,
}
)
attachments = []
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,
}
)
col_analytics.insert_one(
{
"user": message.author.id,
"channel": message.channel.id,
"content": message.content,
"stickers": stickers,
"attachments": attachments,
}
)
def setup(client: PycordBot):
client.add_cog(Analytics(client))