2020-08-11 08:18:55 +00:00
|
|
|
""" Pagermaid autorespond plugin. """
|
|
|
|
|
|
|
|
from telethon.events import StopPropagation
|
2022-01-18 08:47:20 +00:00
|
|
|
from pagermaid import persistent_vars, log, version
|
2020-08-11 08:18:55 +00:00
|
|
|
from pagermaid.listener import listener
|
2021-06-16 07:09:40 +00:00
|
|
|
from pagermaid.utils import alias_command
|
2020-08-11 08:18:55 +00:00
|
|
|
|
|
|
|
persistent_vars.update({'autorespond': {'enabled': False, 'message': None, 'amount': 0}})
|
|
|
|
|
|
|
|
|
2021-06-16 07:09:40 +00:00
|
|
|
@listener(is_plugin=True, outgoing=True, command=alias_command("autorespond"),
|
2020-08-11 08:18:55 +00:00
|
|
|
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']:
|
2021-07-15 08:12:49 +00:00
|
|
|
try:
|
|
|
|
if context.message.mentioned and not (await context.get_sender()).bot:
|
|
|
|
persistent_vars['autorespond']['amount'] += 1
|
|
|
|
await context.reply(persistent_vars['autorespond']['message'])
|
|
|
|
except AttributeError:
|
|
|
|
return
|