pollmaster-docker/essentials/messagecache.py
Matthias Nadler dae2a6e494 Migration to rewrite
some performance chances with message caching/fetching and user fetching
2019-04-12 20:30:36 +02:00

23 lines
653 B
Python

import discord
class MessageCache:
def __init__(self, _bot):
self._bot = _bot
self._cache_dict = {}
def put(self, key, value: discord.Message):
self._cache_dict[key] = value
print("cache size:", self._cache_dict.__len__())
def get(self, key):
# Try to find it in this cache, then see if it is cached in the bots own message cache
message = self._cache_dict.get(key, None)
if message == None:
for m in self._bot._connection._messages:
if m.id == key:
return m
return message
def clear(self):
self._cache_dict = {}