repeat 自动复读(无引用)一个人的消息。

This commit is contained in:
xtaodada 2021-07-20 16:55:21 +08:00
parent 2525ac4481
commit 38a7e041dd
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 55 additions and 0 deletions

View File

@ -629,6 +629,16 @@
"supported": true,
"des-short": "强制加入频道讨论群。",
"des": "自动删除未加入频道讨论群用户的发言。命令forcegroup 。"
},
{
"name": "repeat",
"version": "1.0",
"section": "chat",
"maintainer": "xtaodada",
"size": "1.8 kb",
"supported": true,
"des-short": "自动复读(无引用)一个人的消息。",
"des": "自动复读无引用一个人的消息。命令repeat 。"
}
]
}

45
repeat.py Normal file
View File

@ -0,0 +1,45 @@
from pagermaid import redis, redis_status, log
from pagermaid.listener import listener
from pagermaid.utils import alias_command
@listener(is_plugin=True, outgoing=True, command=alias_command("repeat"),
description='自动复读(无引用)一个人的消息。',
parameters="<[reply]|status>")
async def repeat(context):
if not context.is_group:
await context.edit('请在群组中运行。')
return
if not redis_status():
await context.edit('出错了呜呜呜 ~ Redis 数据库离线。')
return
reply = await context.get_reply_message()
if not reply or not reply.sender:
await context.edit('请回复一个用户。')
return
uid = reply.sender_id
if len(context.parameter) == 1:
if redis.get(f'repeat_{context.chat_id}_{uid}'):
await context.edit('此用户存在于自动复读列表。')
else:
await context.edit('此用户不存在于自动复读列表。')
return
if redis.get(f'repeat_{context.chat_id}_{uid}'):
redis.delete(f'repeat_{context.chat_id}_{uid}')
await context.edit('从自动复读列表移除成功。')
else:
redis.set(f'repeat_{context.chat_id}_{uid}', 'true')
await context.edit('添加到自动复读列表成功。')
@listener(is_plugin=True, incoming=True, ignore_edited=True)
async def repeat_msg(context):
""" Event handler. """
if not redis_status():
return
if redis.get(f'repeat_{context.chat_id}_{context.sender_id}'):
try:
msg = await context.client.get_messages(context.chat_id, ids=context.id)
return await context.client.send_message(context.chat_id, msg)
except Exception as e:
await log(f'Repeat Error:\n{e}')