Implemented memcached caching

This commit is contained in:
2025-02-09 23:00:18 +01:00
parent d402c520a5
commit b3a7e3623a
20 changed files with 460 additions and 101 deletions

View File

@@ -1,6 +1,5 @@
import logging
from logging import Logger
from typing import Dict, Any
from discord import Member, Message, TextChannel, MessageType
from discord import utils as ds_utils
@@ -8,6 +7,7 @@ from discord.ext import commands
from libbot.utils import config_get
from classes.holo_bot import HoloBot
from classes.holo_user import HoloUser
from modules.database import col_users
logger: Logger = logging.getLogger(__name__)
@@ -25,16 +25,7 @@ class Logger(commands.Cog):
and (message.author.bot is False)
and (message.author.system is False)
):
if (await col_users.find_one({"user": message.author.id})) is None:
user: Dict[str, Any] = {}
defaults: Dict[str, Any] = await config_get("user", "defaults")
user["user"] = message.author.id
for key in defaults:
user[key] = defaults[key]
await col_users.insert_one(document=user)
await HoloUser.from_user(message.author, cache=self.client.cache)
if (
(message.type == MessageType.thread_created)
@@ -69,30 +60,21 @@ class Logger(commands.Cog):
id=await config_get("rules", "channels", "text"),
)
if welcome_chan is None:
logger.warning("Could not find a welcome channel by its id")
if (
(member != self.client.user)
and (member.bot is False)
and (member.system is False)
):
await welcome_chan.send(
content=(await config_get("welcome", "messages")).format(
mention=member.mention, rules=rules_chan.mention
if welcome_chan is not None and rules_chan is not None:
await welcome_chan.send(
content=(await config_get("welcome", "messages")).format(
mention=member.mention, rules=rules_chan.mention
)
)
)
else:
logger.warning("Could not find a welcome and/or rules channel by id")
if (await col_users.find_one({"user": member.id})) is None:
user: Dict[str, Any] = {}
defaults: Dict[str, Any] = await config_get("user", "defaults")
user["user"] = member.id
for key in defaults:
user[key] = defaults[key]
await col_users.insert_one(document=user)
await HoloUser.from_user(member, cache=self.client.cache)
def setup(client: HoloBot) -> None: