From d41bec9c73c7ca60a1a1434ecc9da709e8354935 Mon Sep 17 00:00:00 2001 From: teidesu <86301490+teidesu@users.noreply.github.com> Date: Sun, 8 May 2022 23:34:28 +0300 Subject: [PATCH] feat(client): support setBot*DefaultAdminRights methods --- packages/client/src/client.ts | 12 ++++++++++ .../src/methods/bots/set-my-default-rights.ts | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 packages/client/src/methods/bots/set-my-default-rights.ts diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index a43cca7c..1f1bcaed 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -88,6 +88,7 @@ import { getMyCommands } from './methods/bots/get-my-commands' import { _normalizeCommandScope } from './methods/bots/normalize-command-scope' import { setGameScore, setInlineGameScore } from './methods/bots/set-game-score' import { setMyCommands } from './methods/bots/set-my-commands' +import { setMyDefaultRights } from './methods/bots/set-my-default-rights' import { addChatMembers } from './methods/chats/add-chat-members' import { archiveChats } from './methods/chats/archive-chats' import { banChatMember } from './methods/chats/ban-chat-member' @@ -968,6 +969,16 @@ export interface TelegramClient extends BaseTelegramClient { */ langCode?: string }): Promise + /** + * Sets the default chat permissions for the bot in the supergroup or channel. + * + * @param target Whether to target groups or channels. + * @param rights The default chat permissions. + */ + setMyDefaultRights( + target: 'channel' | 'group', + rights: Omit + ): Promise /** * Add new members to a group, supergroup or channel. * @@ -3695,6 +3706,7 @@ export class TelegramClient extends BaseTelegramClient { setGameScore = setGameScore setInlineGameScore = setInlineGameScore setMyCommands = setMyCommands + setMyDefaultRights = setMyDefaultRights addChatMembers = addChatMembers archiveChats = archiveChats banChatMember = banChatMember diff --git a/packages/client/src/methods/bots/set-my-default-rights.ts b/packages/client/src/methods/bots/set-my-default-rights.ts new file mode 100644 index 00000000..37898f6f --- /dev/null +++ b/packages/client/src/methods/bots/set-my-default-rights.ts @@ -0,0 +1,23 @@ +import { TelegramClient } from '../../client' +import { tl } from '@mtcute/tl' + +/** + * Sets the default chat permissions for the bot in the supergroup or channel. + * + * @param target Whether to target groups or channels. + * @param rights The default chat permissions. + * @internal + */ +export async function setMyDefaultRights( + this: TelegramClient, + target: 'channel' | 'group', + rights: Omit +): Promise { + await this.call({ + _: target === 'group' ? 'bots.setBotGroupDefaultAdminRights' : 'bots.setBotBroadcastDefaultAdminRights', + adminRights: { + _: 'chatAdminRights', + ...rights + }, + }) +}