2023-10-18 15:50:27 +00:00
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from cashews import cache
|
|
|
|
|
2024-11-17 13:14:22 +00:00
|
|
|
from sticker.scheduler import add_delete_message_id_job
|
2023-10-18 15:50:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ServiceMessage:
|
|
|
|
@staticmethod
|
|
|
|
async def set_cache(uid: int, cid: int, mid: int):
|
|
|
|
old = await ServiceMessage.get_cache(uid, cid)
|
|
|
|
old.append(mid)
|
|
|
|
await cache.set(f"service_message:{uid}:{cid}", old, expire=600)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def get_cache(uid: int, cid: int) -> List[int]:
|
|
|
|
data = await cache.get(f"service_message:{uid}:{cid}")
|
2024-11-11 08:57:10 +00:00
|
|
|
return data or []
|
2023-10-18 15:50:27 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def try_delete(uid: int, cid: int):
|
|
|
|
mid = await ServiceMessage.get_cache(uid, cid)
|
|
|
|
if mid:
|
2024-11-17 13:14:22 +00:00
|
|
|
add_delete_message_id_job(cid, list(mid), 1)
|