Discord/cogs/analytics.py

62 lines
1.9 KiB
Python
Raw Normal View History

2023-05-06 18:52:46 +03:00
import logging
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-06-23 13:05:03 +03:00
from libbot.pycord.classes import PycordBot
2023-05-06 18:52:46 +03:00
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-06-23 13:05:03 +03:00
def __init__(self, client: PycordBot):
2023-05-06 18:52:46 +03:00
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)
):
2023-05-07 10:57:35 +03:00
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,
}
)
2023-05-06 18:52:46 +03:00
col_analytics.insert_one(
{
"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
def setup(client: PycordBot):
client.add_cog(Analytics(client))