refactor(state): switch to LimitedSizeDict

This commit is contained in:
Ryan 2025-01-05 19:24:44 -05:00
parent 3c4480c834
commit 82cd56ace8
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3

View File

@ -1,9 +1,27 @@
import collections
import time import time
import disnake import disnake
command_locks = {}
executed_messages = {} class LimitedSizeDict(collections.OrderedDict):
def __init__(self, *args, **kwds):
self.size_limit = kwds.pop("size_limit", 1000)
super().__init__(*args, **kwds)
self._check_size_limit()
def __setitem__(self, key, value):
super().__setitem__(key, value)
self._check_size_limit()
def _check_size_limit(self):
if self.size_limit is not None:
while len(self) > self.size_limit:
self.popitem(last=False)
command_locks = LimitedSizeDict()
message_responses = LimitedSizeDict()
players = {} players = {}
intents = disnake.Intents.default() intents = disnake.Intents.default()