feat(client): editAdminRights method
This commit is contained in:
parent
32ef1c59ad
commit
633f1fdf4d
2 changed files with 58 additions and 0 deletions
|
@ -34,6 +34,7 @@ import { deleteChatPhoto } from './methods/chats/delete-chat-photo'
|
|||
import { deleteGroup } from './methods/chats/delete-group'
|
||||
import { deleteHistory } from './methods/chats/delete-history'
|
||||
import { deleteUserHistory } from './methods/chats/delete-user-history'
|
||||
import { editAdminRights } from './methods/chats/edit-admin-rights'
|
||||
import { getChatEventLog } from './methods/chats/get-chat-event-log'
|
||||
import { getChatMember } from './methods/chats/get-chat-member'
|
||||
import { getChatMembers } from './methods/chats/get-chat-members'
|
||||
|
@ -823,6 +824,20 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
chatId: InputPeerLike,
|
||||
userId: InputPeerLike
|
||||
): Promise<void>
|
||||
/**
|
||||
* Edit supergroup/channel admin rights of a user.
|
||||
*
|
||||
* @param chatId Chat ID
|
||||
* @param userId User ID
|
||||
* @param rights New admin rights
|
||||
* @param rank (default: `''`) Custom admin rank
|
||||
*/
|
||||
editAdminRights(
|
||||
chatId: InputPeerLike,
|
||||
userId: InputPeerLike,
|
||||
rights: Omit<tl.RawChatAdminRights, '_'>,
|
||||
rank?: string
|
||||
): Promise<void>
|
||||
/**
|
||||
* Get chat event log ("Recent actions" in official
|
||||
* clients).
|
||||
|
@ -3014,6 +3029,7 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
deleteGroup = deleteGroup
|
||||
deleteHistory = deleteHistory
|
||||
deleteUserHistory = deleteUserHistory
|
||||
editAdminRights = editAdminRights
|
||||
getChatEventLog = getChatEventLog
|
||||
getChatMember = getChatMember
|
||||
getChatMembers = getChatMembers
|
||||
|
|
42
packages/client/src/methods/chats/edit-admin-rights.ts
Normal file
42
packages/client/src/methods/chats/edit-admin-rights.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { normalizeToInputChannel, normalizeToInputUser } from '../../utils/peer-utils'
|
||||
|
||||
/**
|
||||
* Edit supergroup/channel admin rights of a user.
|
||||
*
|
||||
* @param chatId Chat ID
|
||||
* @param userId User ID
|
||||
* @param rights New admin rights
|
||||
* @param rank Custom admin rank
|
||||
* @internal
|
||||
*/
|
||||
export async function editAdminRights(
|
||||
this: TelegramClient,
|
||||
chatId: InputPeerLike,
|
||||
userId: InputPeerLike,
|
||||
rights: Omit<tl.RawChatAdminRights, '_'>,
|
||||
rank = ''
|
||||
): Promise<void> {
|
||||
const chat = normalizeToInputChannel(await this.resolvePeer(chatId))
|
||||
if (!chat)
|
||||
throw new MtCuteInvalidPeerTypeError(chatId, 'channel')
|
||||
|
||||
const user = normalizeToInputUser(await this.resolvePeer(userId))
|
||||
if (!user)
|
||||
throw new MtCuteInvalidPeerTypeError(userId, 'user')
|
||||
|
||||
const res = await this.call({
|
||||
_: 'channels.editAdmin',
|
||||
channel: chat,
|
||||
userId: user,
|
||||
adminRights: {
|
||||
_: 'chatAdminRights',
|
||||
...rights
|
||||
},
|
||||
rank
|
||||
})
|
||||
|
||||
this._handleUpdate(res)
|
||||
}
|
Loading…
Reference in a new issue