TDLightTelegramBots/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/GetGameHighScores.java

119 lines
4.6 KiB
Java
Raw Normal View History

2016-09-25 15:33:20 +02:00
/*
* This file is part of TelegramBots.
*
2016-09-28 00:31:34 +02:00
* TelegramBots is free software: you can redistribute it and/or modify
2016-09-25 15:33:20 +02:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
2016-09-28 00:31:34 +02:00
* TelegramBots is distributed in the hope that it will be useful,
2016-09-25 15:33:20 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2016-09-28 00:31:34 +02:00
* along with TelegramBots. If not, see <http://www.gnu.org/licenses/>.
2016-09-25 15:33:20 +02:00
*/
2018-07-08 01:41:21 +02:00
package org.telegram.telegrambots.meta.api.methods.games;
2016-09-25 15:33:20 +02:00
import com.fasterxml.jackson.annotation.JsonProperty;
2020-11-01 23:46:36 +01:00
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
2022-06-14 22:20:22 +02:00
import lombok.experimental.Tolerate;
2018-07-08 01:41:21 +02:00
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
2022-06-14 22:20:22 +02:00
import org.telegram.telegrambots.meta.api.objects.games.GameHighScore;
2018-07-08 01:41:21 +02:00
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
2016-09-25 15:33:20 +02:00
import java.util.ArrayList;
/**
* @author Ruben Bermudez
* @version 2.4
2019-06-08 21:33:28 +02:00
* Use this method to get data for high score tables.
2016-09-28 00:29:44 +02:00
* Will return the score of the specified user and several of his neighbors in a game.
* On success, returns an Array of GameHighScore objects.
*
2020-11-01 23:46:36 +01:00
* @apiNote This method will currently return scores for the target user,
2016-09-29 00:44:03 +02:00
* plus two of his closest neighbors on each side. Will also return the top three users
* if the user and his neighbors are not among them.
2016-09-28 00:29:44 +02:00
* Please note that this behavior is subject to change.
2016-09-29 00:44:03 +02:00
*
2016-09-25 15:33:20 +02:00
*/
2020-11-01 23:46:36 +01:00
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
2023-05-30 03:33:18 +02:00
@NoArgsConstructor(force = true)
2020-11-01 23:46:36 +01:00
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
2016-09-25 15:33:20 +02:00
public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
2016-09-28 00:29:44 +02:00
public static final String PATH = "getGameHighScores";
2016-09-25 15:33:20 +02:00
private static final String CHATID_FIELD = "chat_id";
private static final String MESSAGEID_FIELD = "message_id";
private static final String INLINE_MESSAGE_ID_FIELD = "inline_message_id";
private static final String USER_ID_FIELD = "user_id";
@JsonProperty(CHATID_FIELD)
2022-08-15 02:42:50 +02:00
private String chatId; ///< Optional. Required if inline_message_id is not specified. Unique identifier for the target chat (or username of the target channel in the format @channelusername)
@JsonProperty(MESSAGEID_FIELD)
2022-08-15 02:42:50 +02:00
private Integer messageId; ///< Optional. Required if inline_message_id is not specified. Unique identifier of the sent message
@JsonProperty(INLINE_MESSAGE_ID_FIELD)
2022-08-15 02:42:50 +02:00
private String inlineMessageId; ///< Optional. Required if chat_id and message_id are not specified. Identifier of the inline message
@JsonProperty(USER_ID_FIELD)
2020-11-01 23:46:36 +01:00
@NonNull
2021-03-09 11:59:28 +01:00
private Long userId; ///<Target user id
2016-09-25 15:33:20 +02:00
2022-06-14 22:20:22 +02:00
@Tolerate
public void setChatId(Long chatId) {
this.chatId = chatId == null ? null : chatId.toString();
}
2016-09-25 15:33:20 +02:00
@Override
public String getMethod() {
2016-09-25 15:33:20 +02:00
return PATH;
}
@Override
public ArrayList<GameHighScore> deserializeResponse(String answer) throws TelegramApiRequestException {
2022-06-16 19:36:20 +02:00
return deserializeResponseArray(answer, GameHighScore.class);
2016-09-25 15:33:20 +02:00
}
@Override
public void validate() throws TelegramApiValidationException {
if (inlineMessageId == null) {
2021-04-26 21:55:00 +02:00
if (chatId == null || chatId.isEmpty()) {
2016-09-25 15:33:20 +02:00
throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this);
}
if (messageId == null) {
throw new TelegramApiValidationException("MessageId parameter can't be empty if inlineMessageId is not present", this);
}
} else {
if (chatId != null) {
throw new TelegramApiValidationException("ChatId parameter must be empty if inlineMessageId is provided", this);
}
if (messageId != null) {
throw new TelegramApiValidationException("MessageId parameter must be empty if inlineMessageId is provided", this);
}
}
}
2022-06-14 22:20:22 +02:00
public static class GetGameHighScoresBuilder {
@Tolerate
public GetGameHighScoresBuilder chatId(Long chatId) {
this.chatId = chatId == null ? null : chatId.toString();
return this;
}
}
2016-09-25 15:33:20 +02:00
}