Beispiel #1
0
        /// <summary>
        /// Use this method to set the score of the specified user in a game.
        /// </summary>
        /// <param name="disableEditMessage">Pass True, if the game message should not be automatically edited to include the current scoreboard</param>
        /// <param name="chatId">Required if inline_message_id is not specified. Unique identifier for the target chat</param>
        /// <param name="inlineMessageId">Required if chat_id and message_id are not specified. Identifier of the inline message</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of
        /// cancellation.</param>
        /// <param name="userId">User identifier</param>
        /// <param name="score">New score, must be non-negative</param>
        /// <param name="force">Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters</param>
        /// <param name="messageId">Required if inline_message_id is not specified. Identifier of the sent message</param>
        /// <returns>
        /// On success, if the message was sent by the bot, returns the edited <see cref="Message" />., otherwise returns True. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
        /// </returns>
        public Task <object> SetGameScoreAsync(long userId, long score, bool force = false, bool disableEditMessage = false, string chatId = null, long messageId = 0, string inlineMessageId = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotZero(userId, nameof(userId));
            Contracts.EnsureNotNegativeNumber(score, nameof(score));

            var parameters = new NameValueCollection();

            if (string.IsNullOrWhiteSpace(chatId) && messageId == 0)
            {
                Contracts.EnsureNotNull(inlineMessageId, nameof(inlineMessageId));
                parameters.Add("inline_message_id", inlineMessageId);
            }
            else if (string.IsNullOrWhiteSpace(inlineMessageId))
            {
                Contracts.EnsureNotNull(chatId, nameof(chatId));
                Contracts.EnsureNotZero(messageId, nameof(messageId));
                parameters.Add("chat_id", chatId);
                parameters.Add("message_id", messageId);
            }

            parameters.Add("user_id", userId);
            parameters.Add("score", score);
            parameters.AddIf(force == true, "force", force);
            parameters.AddIf(disableEditMessage == true, "disable_edit_message", disableEditMessage);

            return(this.CallTelegramMethodAsync <object>(cancellationToken, "setGameScore", parameters));
        }