mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-22 00:35:36 +00:00
✨ forcesubscribe 自动删除未关注指定公开频道的用户的发言。
This commit is contained in:
parent
8619b795a7
commit
f233dbdd8b
96
forcesubscribe.py
Normal file
96
forcesubscribe.py
Normal file
@ -0,0 +1,96 @@
|
||||
from pagermaid import bot, redis, redis_status
|
||||
from pagermaid.utils import lang, alias_command
|
||||
from pagermaid.listener import listener
|
||||
from telethon.events.chataction import ChatAction
|
||||
from telethon.tl.custom.message import Message
|
||||
from telethon.tl.functions.channels import GetParticipantRequest
|
||||
from telethon.errors.rpcerrorlist import UserNotParticipantError, ChatAdminRequiredError
|
||||
from telethon import events
|
||||
|
||||
|
||||
@bot.on(events.ChatAction())
|
||||
async def force_subscribe_join(event: ChatAction.Event):
|
||||
if not redis_status():
|
||||
return
|
||||
if not (event.user_joined or event.user_added):
|
||||
return
|
||||
join_chat = redis.get(f"sub.chat_id.{event.chat_id}")
|
||||
if not join_chat:
|
||||
return
|
||||
else:
|
||||
join_chat = join_chat.decode()
|
||||
user = await event.get_user()
|
||||
if user.bot:
|
||||
return
|
||||
if redis.get(f"sub.chat_id.{event.chat_id}.{user.id}"):
|
||||
return
|
||||
try:
|
||||
await bot(GetParticipantRequest(join_chat, user.id))
|
||||
redis.set(f'sub.chat_id.{event.chat_id}.{user.id}', 'true')
|
||||
redis.expire(f'sub.chat_id.{event.chat_id}.{user.id}', 3600)
|
||||
except UserNotParticipantError:
|
||||
await event.reply(f'[{user.first_name}](tg://user?id={user.id}) 您需要先加入频道 @{join_chat} 才能发言。')
|
||||
except ChatAdminRequiredError:
|
||||
redis.delete(f"sub.chat_id.{event.chat_id}")
|
||||
|
||||
|
||||
@listener(is_plugin=True, incoming=True, ignore_edited=True)
|
||||
async def force_subscribe_msg(context: Message):
|
||||
if not redis_status():
|
||||
return
|
||||
join_chat = redis.get(f"sub.chat_id.{context.chat_id}")
|
||||
if not join_chat:
|
||||
return
|
||||
if redis.get(f"sub.chat_id.{context.chat_id}.{context.sender_id}"):
|
||||
return
|
||||
else:
|
||||
join_chat = join_chat.decode()
|
||||
if context.sender.bot:
|
||||
return
|
||||
try:
|
||||
await bot(GetParticipantRequest(join_chat, context.sender_id))
|
||||
redis.set(f'sub.chat_id.{context.chat_id}.{context.sender_id}', 'true')
|
||||
redis.expire(f'sub.chat_id.{context.chat_id}.{context.sender_id}', 3600)
|
||||
except UserNotParticipantError:
|
||||
try:
|
||||
await context.delete()
|
||||
await bot.send_message(context.chat_id,
|
||||
f'[{context.sender.first_name}](tg://user?id={context.sender_id}) '
|
||||
f'您需要先加入频道 @{join_chat} 才能发言。')
|
||||
except ChatAdminRequiredError:
|
||||
redis.delete(f"sub.chat_id.{context.chat_id}")
|
||||
except ChatAdminRequiredError:
|
||||
redis.delete(f"sub.chat_id.{context.chat_id}")
|
||||
|
||||
|
||||
@listener(is_plugin=False, outgoing=True, command=alias_command('forcesub'),
|
||||
description='自动删除未关注指定公开频道的用户的发言。',
|
||||
parameters="<username|false|status>")
|
||||
async def force_sub(context):
|
||||
if not redis_status():
|
||||
await context.edit(f"{lang('error_prefix')}{lang('redis_dis')}")
|
||||
return
|
||||
if len(context.parameter) != 1:
|
||||
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
||||
return
|
||||
myself = await context.client.get_me()
|
||||
self_user_id = myself.id
|
||||
if context.parameter[0] == "false":
|
||||
if context.chat_id == self_user_id:
|
||||
await context.edit(lang('ghost_e_mark'))
|
||||
return
|
||||
redis.delete(f"sub.chat_id.{context.chat_id}")
|
||||
await context.edit(f'成功关闭强制关注频道功能。')
|
||||
elif context.parameter[0] == "status":
|
||||
if redis.get(f"sub.chat_id.{context.chat_id}"):
|
||||
join_chat = redis.get(f"sub.chat_id.{context.chat_id}").decode()
|
||||
await context.edit(f'当前群组强制需要关注频道的频道为: @{join_chat} 。')
|
||||
else:
|
||||
await context.edit('当前群组未开启强制关注频道功能。')
|
||||
else:
|
||||
if context.chat_id == self_user_id:
|
||||
await context.edit(lang('ghost_e_mark'))
|
||||
return
|
||||
sub_channel = context.parameter[0].replace('@', '')
|
||||
redis.set(f"sub.chat_id.{context.chat_id}", sub_channel)
|
||||
await context.edit(f'已设置当前群组强制需要关注频道的频道为: @{sub_channel} 。')
|
10
list.json
10
list.json
@ -609,6 +609,16 @@
|
||||
"supported": true,
|
||||
"des-short": "查询/解除群组中被所回复用户所封禁的用户。",
|
||||
"des": "查询/解除群组中被所回复用户所封禁的用户。命令:unbanby 。"
|
||||
},
|
||||
{
|
||||
"name": "forcesubscribe",
|
||||
"version": "1.0",
|
||||
"section": "daily",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "4.2 kb",
|
||||
"supported": true,
|
||||
"des-short": "自动删除未关注指定公开频道的用户的发言。",
|
||||
"des": "自动删除未关注指定公开频道的用户的发言。命令:forcesub 。"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user