forcesubscribe 消息发送 5 秒后自动删除

This commit is contained in:
xtaodada 2021-07-15 18:16:54 +08:00
parent f233dbdd8b
commit e932e9e711
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 10 additions and 5 deletions

View File

@ -1,6 +1,7 @@
from pagermaid import bot, redis, redis_status from pagermaid import bot, redis, redis_status
from pagermaid.utils import lang, alias_command from pagermaid.utils import lang, alias_command
from pagermaid.listener import listener from pagermaid.listener import listener
from asyncio import sleep
from telethon.events.chataction import ChatAction from telethon.events.chataction import ChatAction
from telethon.tl.custom.message import Message from telethon.tl.custom.message import Message
from telethon.tl.functions.channels import GetParticipantRequest from telethon.tl.functions.channels import GetParticipantRequest
@ -29,7 +30,9 @@ async def force_subscribe_join(event: ChatAction.Event):
redis.set(f'sub.chat_id.{event.chat_id}.{user.id}', 'true') redis.set(f'sub.chat_id.{event.chat_id}.{user.id}', 'true')
redis.expire(f'sub.chat_id.{event.chat_id}.{user.id}', 3600) redis.expire(f'sub.chat_id.{event.chat_id}.{user.id}', 3600)
except UserNotParticipantError: except UserNotParticipantError:
await event.reply(f'[{user.first_name}](tg://user?id={user.id}) 您需要先加入频道 @{join_chat} 才能发言。') msg = await event.reply(f'[{user.first_name}](tg://user?id={user.id}) 您需要先加入频道 @{join_chat} 才能发言。')
await sleep(5)
await msg.delete()
except ChatAdminRequiredError: except ChatAdminRequiredError:
redis.delete(f"sub.chat_id.{event.chat_id}") redis.delete(f"sub.chat_id.{event.chat_id}")
@ -54,9 +57,11 @@ async def force_subscribe_msg(context: Message):
except UserNotParticipantError: except UserNotParticipantError:
try: try:
await context.delete() await context.delete()
await bot.send_message(context.chat_id, msg = await bot.send_message(context.chat_id,
f'[{context.sender.first_name}](tg://user?id={context.sender_id}) ' f'[{context.sender.first_name}](tg://user?id={context.sender_id}) '
f'您需要先加入频道 @{join_chat} 才能发言。') f'您需要先加入频道 @{join_chat} 才能发言。')
await sleep(5)
await msg.delete()
except ChatAdminRequiredError: except ChatAdminRequiredError:
redis.delete(f"sub.chat_id.{context.chat_id}") redis.delete(f"sub.chat_id.{context.chat_id}")
except ChatAdminRequiredError: except ChatAdminRequiredError:

View File

@ -612,7 +612,7 @@
}, },
{ {
"name": "forcesubscribe", "name": "forcesubscribe",
"version": "1.0", "version": "1.01",
"section": "daily", "section": "daily",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "4.2 kb", "size": "4.2 kb",