From 7a01d3a0d05910497f9cb19dc848e2c290673a78 Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Wed, 8 Dec 2021 13:34:41 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Support=20ban=20channel=20(#153)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ sb 命令支持在群组中封禁频道 --- languages/built-in/en.yml | 1 + languages/built-in/zh-cn.yml | 1 + languages/built-in/zh-tw.yml | 1 + pagermaid/modules/sb.py | 19 ++++++++++++++++--- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/languages/built-in/en.yml b/languages/built-in/en.yml index ac44201..771e6f2 100644 --- a/languages/built-in/en.yml +++ b/languages/built-in/en.yml @@ -514,3 +514,4 @@ sb_set: This group has been added to the automatic banned list. sb_remove: The automatic banned list has been removed this group. sb_exist: This group exists in the automatic banned list. sb_no_exist: This group does't exist in the automatic banned list. +sb_channel: Successfully blocked this channel in this group. diff --git a/languages/built-in/zh-cn.yml b/languages/built-in/zh-cn.yml index 8a8a8fb..e136d9b 100644 --- a/languages/built-in/zh-cn.yml +++ b/languages/built-in/zh-cn.yml @@ -530,3 +530,4 @@ sb_set: 已被添加到自动封禁列表中。 sb_remove: 已被移除自动封禁列表。 sb_exist: 此群组存在于自动封禁列表中。 sb_no_exist: 此群组不存在于自动封禁列表中。 +sb_channel: 成功在本群封禁此频道。 diff --git a/languages/built-in/zh-tw.yml b/languages/built-in/zh-tw.yml index 4647e47..bb8d9de 100644 --- a/languages/built-in/zh-tw.yml +++ b/languages/built-in/zh-tw.yml @@ -514,3 +514,4 @@ sb_set: 已被添加到自動封禁列表中。 sb_remove: 已被移除自動封禁列表。 sb_exist: 此群組存在於自動封禁列表中。 sb_no_exist: 此群組不存在於自動封禁列表中。 +sb_channel: 成功在本群封禁此頻道。 diff --git a/pagermaid/modules/sb.py b/pagermaid/modules/sb.py index 24799a1..9b35cd6 100644 --- a/pagermaid/modules/sb.py +++ b/pagermaid/modules/sb.py @@ -4,8 +4,9 @@ from pagermaid.utils import lang, alias_command from struct import error as StructError from telethon.tl.functions.messages import GetCommonChatsRequest from telethon.tl.functions.users import GetFullUserRequest -from telethon.tl.functions.channels import DeleteUserHistoryRequest -from telethon.tl.types import MessageEntityMentionName, ChannelParticipantsAdmins, MessageEntityPhone, PeerChannel +from telethon.tl.functions.channels import DeleteUserHistoryRequest, EditBannedRequest +from telethon.tl.types import MessageEntityMentionName, ChannelParticipantsAdmins, MessageEntityPhone, PeerChannel, \ + ChatBannedRights from telethon.errors.rpcerrorlist import UserAdminInvalidError, ChatAdminRequiredError, FloodWaitError from asyncio import sleep from random import uniform @@ -49,7 +50,19 @@ async def span_ban(context): await context.edit(lang('arg_error')) return if isinstance(user, PeerChannel): - return await context.edit(lang('arg_error')) + # 封禁频道 + try: + entity = await context.client.get_input_entity(context.chat_id) + user = await context.client.get_input_entity(reply_message.sender.id) + await context.client(EditBannedRequest( + channel=entity, + participant=user, + banned_rights=ChatBannedRights( + until_date=None, view_messages=True) + )) + except ChatAdminRequiredError: + return await context.edit(lang('sb_no_per')) + return await context.edit(lang('sb_channel')) elif not user: return await context.edit(lang('arg_error')) target_user = await context.client(GetFullUserRequest(user))