""" Remove Sent Msg After A Specified Time. """ # By tg @fruitymelon # extra requirements: dateparser import asyncio, time, traceback, sys from pagermaid import 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 offset = local_time_offset() // 3600 sign = "+" if offset >= 0 else "-" offset = abs(offset) offset_str = str(offset) offset_str = offset_str if len(offset_str) == 2 else f"0{offset_str}" settings = {'TIMEZONE': f'{sign}{offset_str}00'} all_chat = False all_chat_delta = None chats = [] times = [] helpmsg = """ 在指定的时间后删除自己的消息。 默认在当前群聊中启用,也可以设置为全部私聊、群聊和频道通用。重叠时,前者优先级更高。 PagerMaid 重启后将失效。 i.e. -autorm 4 seconds -autorm 1 minutes -autorm global 1 minutes 取消删除自己的消息: 取消当前群 -autorm cancel 取消全局 -autorm global cancel 取消所有群和全局 -autorm cancelall """ @listener(outgoing=True, ignore_edited=True) async def remove_message(context): """ Event handler to infinitely remove messages. """ try: text = context.message.text if context.message.text else "" chat_id = context.chat_id if chats.count(chat_id) != 0: index = chats.index(chat_id) delta = times[index] if text.startswith("-autorm"): context.arguments = text.lstrip("-autorm").lstrip() await autorm(context) if text.startswith(f"-{alias_command('dme')}"): return await asyncio.sleep(delta) await context.delete() return elif all_chat: delta = all_chat_delta if text.startswith("-autorm"): context.arguments = text.lstrip("-autorm").lstrip() await autorm(context) if text.startswith(f"-{alias_command('dme')}"): return await asyncio.sleep(delta) await context.delete() return except Exception as e: try: await sendmsg(context, await context.get_chat(), str(e)) except ValueError: pass @listener(is_plugin=True, outgoing=True, command=alias_command("autorm"), diagnostics=True, ignore_edited=False, description=helpmsg, parameters="