From fb714cb887ff520e6f5e08a37cf8823c75a629f2 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 11 Aug 2020 16:18:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20autorespond?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ autorespond.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ list.json | 14 ++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 autorespond.py create mode 100644 list.json diff --git a/.gitignore b/.gitignore index b6e4761..efeddfc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ __pycache__/ *.py[cod] *$py.class +# IDE +.idea/ + # C extensions *.so diff --git a/autorespond.py b/autorespond.py new file mode 100644 index 0000000..d8be9d6 --- /dev/null +++ b/autorespond.py @@ -0,0 +1,45 @@ +""" Pagermaid autorespond plugin. """ + +from telethon.events import StopPropagation +from pagermaid import persistent_vars, log +from pagermaid.listener import listener + +persistent_vars.update({'autorespond': {'enabled': False, 'message': None, 'amount': 0}}) + + +@listener(outgoing=True, command="autorespond", + description="启用自动回复。", + parameters="") +async def autorespond(context): + """ Enables the auto responder. """ + message = "我还在睡觉... ZzZzZzZzZZz" + if context.arguments: + message = context.arguments + await context.edit("成功启用自动响应器。") + await log(f"启用自动响应器,将自动回复 `{message}`.") + persistent_vars.update({'autorespond': {'enabled': True, 'message': message, 'amount': 0}}) + raise StopPropagation + + +@listener(outgoing=True) +async def disable_responder(context): + if persistent_vars['autorespond']['enabled']: + await log(f"禁用自动响应器。 在闲置期间 {persistent_vars['autorespond']['amount']}" + f" 条消息被自动回复") + persistent_vars.update({'autorespond': {'enabled': False, 'message': None, 'amount': 0}}) + + +@listener(incoming=True) +async def private_autorespond(context): + if persistent_vars['autorespond']['enabled']: + if context.is_private and not (await context.get_sender()).bot: + persistent_vars['autorespond']['amount'] += 1 + await context.reply(persistent_vars['autorespond']['message']) + + +@listener(incoming=True) +async def mention_autorespond(context): + if persistent_vars['autorespond']['enabled']: + if context.message.mentioned and not (await context.get_sender()).bot: + persistent_vars['autorespond']['amount'] += 1 + await context.reply(persistent_vars['autorespond']['message']) diff --git a/list.json b/list.json new file mode 100644 index 0000000..db8ecd8 --- /dev/null +++ b/list.json @@ -0,0 +1,14 @@ +{ + "list": [ + { + "name": "autorespond", + "version": "0.0.1", + "section": "chat", + "maintainer": "xtaodada", + "size": "10 kb", + "supported": true, + "des-short": "自动回复。", + "des": "此插件用于需要自动回复的场景。" + } + ] +} \ No newline at end of file