refactor: improved api of set-game-score function
This commit is contained in:
parent
81ce550604
commit
22d8b815d3
2 changed files with 60 additions and 64 deletions
|
@ -975,59 +975,55 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
/**
|
/**
|
||||||
* Set a score of a user in a game
|
* Set a score of a user in a game
|
||||||
*
|
*
|
||||||
* @param chatId Chat where the game was found
|
|
||||||
* @param message ID of the message where the game was found
|
|
||||||
* @param userId ID of the user who has scored
|
|
||||||
* @param score The new score (must be >0)
|
|
||||||
* @param params
|
* @param params
|
||||||
* @returns The modified message
|
* @returns The modified message
|
||||||
*/
|
*/
|
||||||
setGameScore(
|
setGameScore(params: {
|
||||||
chatId: InputPeerLike,
|
/** Chat where the game was found */
|
||||||
message: number,
|
chatId: InputPeerLike
|
||||||
userId: InputPeerLike,
|
/** ID of the message where the game was found */
|
||||||
score: number,
|
message: number
|
||||||
params?: {
|
/** ID of the user who has scored */
|
||||||
/**
|
userId: InputPeerLike
|
||||||
* When `true`, the game message will not be modified
|
/** The new score (must be >0) */
|
||||||
* to include the new score
|
score: number
|
||||||
*/
|
/**
|
||||||
noEdit?: boolean
|
* When `true`, the game message will not be modified
|
||||||
|
* to include the new score
|
||||||
|
*/
|
||||||
|
noEdit?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to allow user's score to decrease.
|
* Whether to allow user's score to decrease.
|
||||||
* This can be useful when fixing mistakes or banning cheaters
|
* This can be useful when fixing mistakes or banning cheaters
|
||||||
*/
|
*/
|
||||||
force?: boolean
|
force?: boolean
|
||||||
}
|
}): Promise<Message>
|
||||||
): Promise<Message>
|
|
||||||
/**
|
/**
|
||||||
* Set a score of a user in a game contained in
|
* Set a score of a user in a game contained in
|
||||||
* an inline message
|
* an inline message
|
||||||
*
|
*
|
||||||
* @param messageId ID of the inline message
|
|
||||||
* @param userId ID of the user who has scored
|
|
||||||
* @param score The new score (must be >0)
|
|
||||||
* @param params
|
* @param params
|
||||||
*/
|
*/
|
||||||
setInlineGameScore(
|
setInlineGameScore(params: {
|
||||||
messageId: string | tl.TypeInputBotInlineMessageID,
|
/** ID of the inline message */
|
||||||
userId: InputPeerLike,
|
messageId: string | tl.TypeInputBotInlineMessageID
|
||||||
score: number,
|
/** ID of the user who has scored */
|
||||||
params?: {
|
userId: InputPeerLike
|
||||||
/**
|
/** The new score (must be >0) */
|
||||||
* When `true`, the game message will not be modified
|
score: number
|
||||||
* to include the new score
|
/**
|
||||||
*/
|
* When `true`, the game message will not be modified
|
||||||
noEdit?: boolean
|
* to include the new score
|
||||||
|
*/
|
||||||
|
noEdit?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to allow user's score to decrease.
|
* Whether to allow user's score to decrease.
|
||||||
* This can be useful when fixing mistakes or banning cheaters
|
* This can be useful when fixing mistakes or banning cheaters
|
||||||
*/
|
*/
|
||||||
force?: boolean
|
force?: boolean
|
||||||
}
|
}): Promise<void>
|
||||||
): Promise<void>
|
|
||||||
/**
|
/**
|
||||||
* Set or delete commands for the current bot and the given scope
|
* Set or delete commands for the current bot and the given scope
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,21 +8,21 @@ import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
/**
|
/**
|
||||||
* Set a score of a user in a game
|
* Set a score of a user in a game
|
||||||
*
|
*
|
||||||
* @param chatId Chat where the game was found
|
|
||||||
* @param message ID of the message where the game was found
|
|
||||||
* @param userId ID of the user who has scored
|
|
||||||
* @param score The new score (must be >0)
|
|
||||||
* @param params
|
* @param params
|
||||||
* @returns The modified message
|
* @returns The modified message
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export async function setGameScore(
|
export async function setGameScore(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
chatId: InputPeerLike,
|
params: {
|
||||||
message: number,
|
/** Chat where the game was found */
|
||||||
userId: InputPeerLike,
|
chatId: InputPeerLike
|
||||||
score: number,
|
/** ID of the message where the game was found */
|
||||||
params?: {
|
message: number
|
||||||
|
/** ID of the user who has scored */
|
||||||
|
userId: InputPeerLike
|
||||||
|
/** The new score (must be >0) */
|
||||||
|
score: number
|
||||||
/**
|
/**
|
||||||
* When `true`, the game message will not be modified
|
* When `true`, the game message will not be modified
|
||||||
* to include the new score
|
* to include the new score
|
||||||
|
@ -36,7 +36,7 @@ export async function setGameScore(
|
||||||
force?: boolean
|
force?: boolean
|
||||||
},
|
},
|
||||||
): Promise<Message> {
|
): Promise<Message> {
|
||||||
if (!params) params = {}
|
const { chatId, message, userId, score, noEdit, force } = params
|
||||||
|
|
||||||
const user = normalizeToInputUser(await this.resolvePeer(userId), userId)
|
const user = normalizeToInputUser(await this.resolvePeer(userId), userId)
|
||||||
const chat = await this.resolvePeer(chatId)
|
const chat = await this.resolvePeer(chatId)
|
||||||
|
@ -47,8 +47,8 @@ export async function setGameScore(
|
||||||
id: message,
|
id: message,
|
||||||
userId: user,
|
userId: user,
|
||||||
score,
|
score,
|
||||||
editMessage: !params.noEdit,
|
editMessage: !noEdit,
|
||||||
force: params.force,
|
force,
|
||||||
})
|
})
|
||||||
|
|
||||||
return this._findMessageInUpdate(res, true)
|
return this._findMessageInUpdate(res, true)
|
||||||
|
@ -58,18 +58,18 @@ export async function setGameScore(
|
||||||
* Set a score of a user in a game contained in
|
* Set a score of a user in a game contained in
|
||||||
* an inline message
|
* an inline message
|
||||||
*
|
*
|
||||||
* @param messageId ID of the inline message
|
|
||||||
* @param userId ID of the user who has scored
|
|
||||||
* @param score The new score (must be >0)
|
|
||||||
* @param params
|
* @param params
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export async function setInlineGameScore(
|
export async function setInlineGameScore(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
messageId: string | tl.TypeInputBotInlineMessageID,
|
params: {
|
||||||
userId: InputPeerLike,
|
/** ID of the inline message */
|
||||||
score: number,
|
messageId: string | tl.TypeInputBotInlineMessageID
|
||||||
params?: {
|
/** ID of the user who has scored */
|
||||||
|
userId: InputPeerLike
|
||||||
|
/** The new score (must be >0) */
|
||||||
|
score: number
|
||||||
/**
|
/**
|
||||||
* When `true`, the game message will not be modified
|
* When `true`, the game message will not be modified
|
||||||
* to include the new score
|
* to include the new score
|
||||||
|
@ -83,7 +83,7 @@ export async function setInlineGameScore(
|
||||||
force?: boolean
|
force?: boolean
|
||||||
},
|
},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!params) params = {}
|
const { messageId, userId, score, noEdit, force } = params
|
||||||
|
|
||||||
const user = normalizeToInputUser(await this.resolvePeer(userId), userId)
|
const user = normalizeToInputUser(await this.resolvePeer(userId), userId)
|
||||||
|
|
||||||
|
@ -95,8 +95,8 @@ export async function setInlineGameScore(
|
||||||
id,
|
id,
|
||||||
userId: user,
|
userId: user,
|
||||||
score,
|
score,
|
||||||
editMessage: !params.noEdit,
|
editMessage: !noEdit,
|
||||||
force: params.force,
|
force: force,
|
||||||
},
|
},
|
||||||
{ dcId: id.dcId },
|
{ dcId: id.dcId },
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue