refactor(state): switch to LimitedSizeDict
This commit is contained in:
parent
3c4480c834
commit
82cd56ace8
22
state.py
22
state.py
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user