Skip to content

Commit

Permalink
Merge pull request #12832 from PennyDreadfulMTG/emoji-cache
Browse files Browse the repository at this point in the history
Do not attempt to re-cache emoji for an hour regardless of result
  • Loading branch information
mergify[bot] authored Jun 26, 2024
2 parents b15f62d + 8822d24 commit 3950b89
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions discordbot/emoji.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import time

from interactions.client import Client
from interactions.models import PartialEmoji
Expand All @@ -8,15 +9,22 @@
from shared import redis_wrapper as redis

CACHE: dict[str, PartialEmoji] = {}
CACHE_TIME: float = 0.0

async def find_emoji(emoji: str, client: Client) -> PartialEmoji | None:
global CACHE_TIME

if res := CACHE.get(emoji):
return res

if not client.guilds:
return None

if CACHE_TIME > time.time() - 60 * 60:
return None

try:
CACHE_TIME = time.time()
for guild in client.guilds:
emojis = await guild.fetch_all_custom_emojis()
res = next((x for x in emojis if x.name == emoji), None)
Expand Down

0 comments on commit 3950b89

Please sign in to comment.