Support ban channel (#153)

 sb 命令支持在群组中封禁频道
This commit is contained in:
Xtao_dada 2021-12-08 13:34:41 +08:00 committed by GitHub
parent 5c339af0b6
commit 7a01d3a0d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View File

@ -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_remove: The automatic banned list has been removed this group.
sb_exist: This group exists in the automatic banned list. sb_exist: This group exists in the automatic banned list.
sb_no_exist: This group does't exist 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.

View File

@ -530,3 +530,4 @@ sb_set: 已被添加到自动封禁列表中。
sb_remove: 已被移除自动封禁列表。 sb_remove: 已被移除自动封禁列表。
sb_exist: 此群组存在于自动封禁列表中。 sb_exist: 此群组存在于自动封禁列表中。
sb_no_exist: 此群组不存在于自动封禁列表中。 sb_no_exist: 此群组不存在于自动封禁列表中。
sb_channel: 成功在本群封禁此频道。

View File

@ -514,3 +514,4 @@ sb_set: 已被添加到自動封禁列表中。
sb_remove: 已被移除自動封禁列表。 sb_remove: 已被移除自動封禁列表。
sb_exist: 此群組存在於自動封禁列表中。 sb_exist: 此群組存在於自動封禁列表中。
sb_no_exist: 此群組不存在於自動封禁列表中。 sb_no_exist: 此群組不存在於自動封禁列表中。
sb_channel: 成功在本群封禁此頻道。

View File

@ -4,8 +4,9 @@ from pagermaid.utils import lang, alias_command
from struct import error as StructError from struct import error as StructError
from telethon.tl.functions.messages import GetCommonChatsRequest from telethon.tl.functions.messages import GetCommonChatsRequest
from telethon.tl.functions.users import GetFullUserRequest from telethon.tl.functions.users import GetFullUserRequest
from telethon.tl.functions.channels import DeleteUserHistoryRequest from telethon.tl.functions.channels import DeleteUserHistoryRequest, EditBannedRequest
from telethon.tl.types import MessageEntityMentionName, ChannelParticipantsAdmins, MessageEntityPhone, PeerChannel from telethon.tl.types import MessageEntityMentionName, ChannelParticipantsAdmins, MessageEntityPhone, PeerChannel, \
ChatBannedRights
from telethon.errors.rpcerrorlist import UserAdminInvalidError, ChatAdminRequiredError, FloodWaitError from telethon.errors.rpcerrorlist import UserAdminInvalidError, ChatAdminRequiredError, FloodWaitError
from asyncio import sleep from asyncio import sleep
from random import uniform from random import uniform
@ -49,7 +50,19 @@ async def span_ban(context):
await context.edit(lang('arg_error')) await context.edit(lang('arg_error'))
return return
if isinstance(user, PeerChannel): 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: elif not user:
return await context.edit(lang('arg_error')) return await context.edit(lang('arg_error'))
target_user = await context.client(GetFullUserRequest(user)) target_user = await context.client(GetFullUserRequest(user))