Implemented memcached caching
This commit is contained in:
@@ -56,7 +56,7 @@ class Analytics(commands.Cog):
|
||||
# Insert entry into the database
|
||||
await col_analytics.insert_one(
|
||||
{
|
||||
"user": message.author.id,
|
||||
"user_id": message.author.id,
|
||||
"channel": message.channel.id,
|
||||
"content": message.content,
|
||||
"stickers": stickers,
|
||||
|
@@ -47,7 +47,9 @@ class CustomChannels(commands.Cog):
|
||||
|
||||
Command to create a custom channel for a user.
|
||||
"""
|
||||
holo_user_ctx: HoloUser = await HoloUser.from_user(ctx.user)
|
||||
holo_user_ctx: HoloUser = await HoloUser.from_user(
|
||||
ctx.user, cache=self.client.cache
|
||||
)
|
||||
|
||||
# Return if the user is using the command outside of a guild
|
||||
if not hasattr(ctx.author, "guild"):
|
||||
@@ -100,7 +102,9 @@ class CustomChannels(commands.Cog):
|
||||
manage_channels=True,
|
||||
)
|
||||
|
||||
await holo_user_ctx.set_custom_channel(created_channel.id)
|
||||
await holo_user_ctx.set_custom_channel(
|
||||
created_channel.id, cache=self.client.cache
|
||||
)
|
||||
|
||||
await ctx.respond(
|
||||
embed=Embed(
|
||||
@@ -136,7 +140,9 @@ class CustomChannels(commands.Cog):
|
||||
|
||||
Command to change properties of a custom channel.
|
||||
"""
|
||||
holo_user_ctx: HoloUser = await HoloUser.from_user(ctx.user)
|
||||
holo_user_ctx: HoloUser = await HoloUser.from_user(
|
||||
ctx.user, cache=self.client.cache
|
||||
)
|
||||
|
||||
custom_channel: TextChannel | None = ds_utils.get(
|
||||
ctx.guild.channels, id=holo_user_ctx.custom_channel
|
||||
@@ -182,7 +188,9 @@ class CustomChannels(commands.Cog):
|
||||
"""Command /customchannel remove [<confirm>]
|
||||
|
||||
Command to remove a custom channel. Requires additional confirmation."""
|
||||
holo_user_ctx: HoloUser = await HoloUser.from_user(ctx.user)
|
||||
holo_user_ctx: HoloUser = await HoloUser.from_user(
|
||||
ctx.user, cache=self.client.cache
|
||||
)
|
||||
|
||||
# Return if the user does not have a custom channel
|
||||
if holo_user_ctx.custom_channel is None:
|
||||
@@ -211,7 +219,7 @@ class CustomChannels(commands.Cog):
|
||||
color=Color.FAIL,
|
||||
)
|
||||
)
|
||||
await holo_user_ctx.remove_custom_channel()
|
||||
await holo_user_ctx.remove_custom_channel(cache=self.client.cache)
|
||||
return
|
||||
|
||||
# Return if the confirmation is missing
|
||||
@@ -227,7 +235,7 @@ class CustomChannels(commands.Cog):
|
||||
|
||||
await custom_channel.delete(reason="Власник запросив видалення")
|
||||
|
||||
await holo_user_ctx.remove_custom_channel()
|
||||
await holo_user_ctx.remove_custom_channel(cache=self.client.cache)
|
||||
|
||||
try:
|
||||
await ctx.respond(
|
||||
|
19
cogs/data.py
19
cogs/data.py
@@ -14,7 +14,6 @@ from libbot.utils import config_get, json_write
|
||||
from classes.holo_bot import HoloBot
|
||||
from classes.holo_user import HoloUser
|
||||
from enums import Color
|
||||
from modules.database import col_users
|
||||
from modules.utils_sync import guild_name
|
||||
|
||||
logger: Logger = logging.getLogger(__name__)
|
||||
@@ -90,7 +89,7 @@ class Data(commands.Cog):
|
||||
{
|
||||
"id": member.id,
|
||||
"nick": member.nick,
|
||||
"username": f"{member.name}#{member.discriminator}",
|
||||
"username": member.name,
|
||||
"bot": member.bot,
|
||||
}
|
||||
)
|
||||
@@ -101,6 +100,7 @@ class Data(commands.Cog):
|
||||
|
||||
await ctx.respond(file=File(Path(f"tmp/{uuid}"), filename="users.json"))
|
||||
|
||||
# TODO Deprecate this command
|
||||
@data.command(
|
||||
name="migrate",
|
||||
description="Мігрувати всіх користувачів до бази",
|
||||
@@ -164,20 +164,7 @@ class Data(commands.Cog):
|
||||
if member.bot:
|
||||
continue
|
||||
|
||||
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)
|
||||
|
||||
logging.info(
|
||||
"Added DB record for user %s during migration", member.id
|
||||
)
|
||||
await HoloUser.from_user(member, cache=self.client.cache)
|
||||
|
||||
await ctx.respond(
|
||||
embed=Embed(
|
||||
|
@@ -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:
|
||||
|
Reference in New Issue
Block a user