Added analytics

This commit is contained in:
Profitroll 2023-05-06 17:52:46 +02:00
parent 7fdf37e35a
commit c9f2da5834
2 changed files with 32 additions and 1 deletions

30
cogs/analytics.py Normal file
View File

@ -0,0 +1,30 @@
import logging
from discord import (
Cog,
Message,
)
from discord.ext import commands
from modules.database import col_analytics
logger = logging.getLogger(__name__)
class Analytics(commands.Cog):
def __init__(self, client):
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)
):
col_analytics.insert_one(
{
"message": message.content,
"user": message.author.id,
"channel": message.channel.id,
}
)

View File

@ -18,12 +18,13 @@ db = db_client.get_database(name=db_config["name"])
collections = db.list_collection_names() collections = db.list_collection_names()
for collection in ["users", "warnings", "scheduler"]: for collection in ["users", "warnings", "scheduler", "analytics"]:
if not collection in collections: if not collection in collections:
db.create_collection(collection) db.create_collection(collection)
col_users = db.get_collection("users") col_users = db.get_collection("users")
col_warnings = db.get_collection("warnings") col_warnings = db.get_collection("warnings")
col_analytics = db.get_collection("analytics")
# col_checkouts = db.get_collection("checkouts") # col_checkouts = db.get_collection("checkouts")
# col_trackings = db.get_collection("trackings") # col_trackings = db.get_collection("trackings")
# col_authorized = db.get_collection("authorized") # col_authorized = db.get_collection("authorized")