🎉 autorespond

This commit is contained in:
xtaodada 2020-08-11 16:18:55 +08:00
parent f267e6b9ff
commit fb714cb887
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
3 changed files with 62 additions and 0 deletions

3
.gitignore vendored
View File

@ -3,6 +3,9 @@ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
# IDE
.idea/
# C extensions # C extensions
*.so *.so

45
autorespond.py Normal file
View File

@ -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="<message>")
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'])

14
list.json Normal file
View File

@ -0,0 +1,14 @@
{
"list": [
{
"name": "autorespond",
"version": "0.0.1",
"section": "chat",
"maintainer": "xtaodada",
"size": "10 kb",
"supported": true,
"des-short": "自动回复。",
"des": "此插件用于需要自动回复的场景。"
}
]
}