From ef231ea44331a0701299488bea0d56400d5cbc44 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 11 Aug 2020 23:47:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20autorm=20sendat=20weather=20xtao?= =?UTF-8?q?-some=20yb-dl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autochangename.py | 2 +- autorm.py | 200 ++++++++++++++++++++++++ dme.py | 2 +- sendat.py | 333 +++++++++++++++++++++++++++++++++++++++ weather.py | 50 ++++++ xtao-some.py | 390 ++++++++++++++++++++++++++++++++++++++++++++++ yb-dl.py | 57 +++++++ 7 files changed, 1032 insertions(+), 2 deletions(-) create mode 100644 autorm.py create mode 100644 sendat.py create mode 100644 weather.py create mode 100644 xtao-some.py create mode 100644 yb-dl.py diff --git a/autochangename.py b/autochangename.py index 51ee03a..807542e 100644 --- a/autochangename.py +++ b/autochangename.py @@ -14,7 +14,7 @@ all_time_emoji_name = ["clock12", "clock1230", "clock1", "clock130", "clock2", " time_emoji_symb = [emojize(":%s:" %s, use_aliases=True) for s in all_time_emoji_name] -@listener(outgoing=True, command="autochangename", +@listener(is_plugin=True, outgoing=True, command="autochangename", description="每 30 秒更新一次 last_name") async def change_name_auto(context): await context.delete() diff --git a/autorm.py b/autorm.py new file mode 100644 index 0000000..398722e --- /dev/null +++ b/autorm.py @@ -0,0 +1,200 @@ +""" Remove Sent Msg After A Specified Time. """ + +# By tg @fruitymelon +# extra requirements: dateparser + +try: + import dateparser + imported = True +except ImportError: + imported = False + +import asyncio, time, traceback +from pagermaid import log +from pagermaid.listener import listener +from datetime import datetime + +# 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) + 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) + await asyncio.sleep(delta) + await context.delete() + return + except Exception as e: + await sendmsg(context, await context.get_chat(), str(e)) + +@listener(is_plugin=True, outgoing=True, command="autorm", diagnostics=True, ignore_edited=False, + description=helpmsg, + parameters="