""" Remove Someone's Msg After A Specified Time. """ # extra requirements: dateparser, redis import time import traceback from asyncio import sleep from telethon.tl.types import PeerUser from telethon.tl.custom import Message from pagermaid import redis, redis_status, version from pagermaid.listener import listener from pagermaid.utils import alias_command, pip_install pip_install("dateparser") import dateparser # https://stackoverflow.com/questions/1111056/get-time-zone-information-of-the-system-in-python def local_time_offset(t=None): """Return offset of local zone from GMT, either at present or at time t.""" # python2.3 localtime() can't take None if t is None: t = time.time() if time.localtime(t).tm_isdst and time.daylight: return -time.altzone else: return -time.timezone @listener(incoming=True, ignore_edited=True) async def remove_others_message(context): """ Event handler to infinitely remove messages. """ if not redis_status(): return if not context.is_group: return chat_id = context.chat_id if not isinstance(context.from_id, PeerUser): return uid = context.from_id.user_id mid = context.id data = redis.get(f"autodel.{chat_id}.{uid}") if data: delta = float(data.decode()) await sleep(delta) # 检查消息是否仍然存在 chat = await context.get_chat() msg = await context.client.get_messages(chat, ids=mid) if msg: try: await context.delete() except Exception as e: try: await send_msg(context, await context.get_chat(), str(e)) except ValueError: pass @listener(is_plugin=True, outgoing=True, command=alias_command("autodel"), diagnostics=True, description=""" 在指定的时间后删除所回复用户发送的消息。只对当前群组有效。 i.e. -autodel 4 seconds -autodel 1 minutes -autodel 1 hours 取消删除消息: -autodel cancel """, parameters="