Skip to content

Commit

Permalink
ensure mentions are caputured
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 committed Jul 3, 2024
1 parent 36eee22 commit 261f637
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions bot/cogs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import datetime
import difflib
import itertools
import re
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -31,6 +30,7 @@

if TYPE_CHECKING:
from cogs.tickets import Tickets

from rodhaj import Rodhaj


Expand Down Expand Up @@ -347,16 +347,15 @@ async def get_guild_config(self, guild_id: int) -> Optional[GuildConfig]:

@alru_cache()
async def get_guild_settings(self, guild_id: int) -> Optional[GuildSettings]:
query = (
"SELECT account_age, guild_age, settings FROM guild_config WHERE id = $1;"
)
query = "SELECT account_age, guild_age, mention, settings FROM guild_config WHERE id = $1;"
rows = await self.pool.fetchrow(query, guild_id)
if rows is None:
self.get_guild_settings.cache_invalidate(guild_id)
return None
return GuildSettings(
account_age=rows["account_age"],
guild_age=rows["guild_age"],
mention=rows["mention"],
**rows["settings"],
)

Expand All @@ -373,27 +372,6 @@ async def get_partial_guild_settings(
**rows["settings"],
)

async def set_guild_settings(self, guild_id: int, key: str, value: Any) -> None:
current_guild_settings = await self.get_guild_settings(guild_id)

# If there are no guild configurations, then we have an issue here
# we will denote this with an error
if not current_guild_settings:
raise RuntimeError("Guild settings could not be found")

query = """
UPDATE guild_config
SET settings = $2::jsonb
WHERE id = $1;
"""
guild_dict = current_guild_settings.to_dict()
guild_dict[key] = value
encoded = msgspec.json.encode(
dict(itertools.islice(guild_dict.items(), 2, len(guild_dict)))
)
await self.bot.pool.execute(query, guild_id, encoded)
self.get_guild_settings.cache_invalidate(guild_id)

### Blocklist utilities

async def can_be_blocked(self, ctx: GuildContext, entity: discord.Member) -> bool:
Expand Down

0 comments on commit 261f637

Please sign in to comment.