From c9f2da5834da45d438adb0e8ecdf6b470fa01d27 Mon Sep 17 00:00:00 2001 From: profitroll Date: Sat, 6 May 2023 17:52:46 +0200 Subject: [PATCH] Added analytics --- cogs/analytics.py | 30 ++++++++++++++++++++++++++++++ modules/database.py | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 cogs/analytics.py diff --git a/cogs/analytics.py b/cogs/analytics.py new file mode 100644 index 0000000..e7a3c85 --- /dev/null +++ b/cogs/analytics.py @@ -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, + } + ) diff --git a/modules/database.py b/modules/database.py index d0b3987..8e2aa71 100644 --- a/modules/database.py +++ b/modules/database.py @@ -18,12 +18,13 @@ db = db_client.get_database(name=db_config["name"]) collections = db.list_collection_names() -for collection in ["users", "warnings", "scheduler"]: +for collection in ["users", "warnings", "scheduler", "analytics"]: if not collection in collections: db.create_collection(collection) col_users = db.get_collection("users") col_warnings = db.get_collection("warnings") +col_analytics = db.get_collection("analytics") # col_checkouts = db.get_collection("checkouts") # col_trackings = db.get_collection("trackings") # col_authorized = db.get_collection("authorized")