1. Games
This commit is contained in:
parent
07e0090d49
commit
0996580574
@ -17,6 +17,10 @@ import java.io.IOException;
|
||||
* @brief Use this method to send answers to callback queries sent from inline keyboards. The answer
|
||||
* will be displayed to the user as a notification at the top of the chat screen or as an alert. On
|
||||
* success, True is returned.
|
||||
*
|
||||
* @note Alternatively, the user can be redirected to the specified URL. For this option to work,
|
||||
* you must enable /setcustomurls for your bot via BotFather and accept the terms.
|
||||
*
|
||||
* @date 10 of April of 2016
|
||||
*/
|
||||
public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
|
||||
|
@ -33,25 +33,28 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 2.4
|
||||
* @brief Use this method to get game high score with a score of the specified user and some
|
||||
* of its neighbours in the game.
|
||||
* On success, Array of GameHighScore is returned.
|
||||
* @brief Use this method to get data for high score tables.
|
||||
* Will return the score of the specified user and several of his neighbors in a game.
|
||||
* On success, returns an Array of GameHighScore objects.
|
||||
* This method will currently return scores for the target user,
|
||||
* plus two of his closest neighbors on each side. Will also return the top three users
|
||||
* if he is not among the top three.
|
||||
*
|
||||
* Please note that this behavior is subject to change.
|
||||
* @date 16 of September of 2016
|
||||
*/
|
||||
public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
public static final String PATH = "setGameScore";
|
||||
public static final String PATH = "getGameHighScores";
|
||||
|
||||
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";
|
||||
private static final String GAME_ID_FIELD = "game_id";
|
||||
|
||||
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)
|
||||
private Integer messageId; ///< Optional Required if inline_message_id is not specified. Unique identifier of the sent message
|
||||
private String inlineMessageId; ///< Optional Required if chat_id and message_id are not specified. Identifier of the inline message
|
||||
private Integer userId; ///< User identifier
|
||||
private Integer gameId; ///< Game identifier
|
||||
private Integer userId; ///<Target user id
|
||||
|
||||
public GetGameHighScores() {
|
||||
}
|
||||
@ -72,10 +75,6 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public Integer getGameId() {
|
||||
return gameId;
|
||||
}
|
||||
|
||||
public GetGameHighScores setChatId(String chatId) {
|
||||
this.chatId = chatId;
|
||||
return this;
|
||||
@ -96,11 +95,6 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetGameHighScores setGameId(Integer gameId) {
|
||||
this.gameId = gameId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return PATH;
|
||||
@ -124,9 +118,6 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
if (userId == null) {
|
||||
throw new TelegramApiValidationException("UserId parameter can't be empty", this);
|
||||
}
|
||||
if (gameId == null) {
|
||||
throw new TelegramApiValidationException("GameId parameter can't be empty", this);
|
||||
}
|
||||
if (inlineMessageId == null) {
|
||||
if (chatId == null) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this);
|
||||
@ -155,7 +146,6 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
gen.writeStringField(INLINE_MESSAGE_ID_FIELD, inlineMessageId);
|
||||
}
|
||||
gen.writeNumberField(USER_ID_FIELD, userId);
|
||||
gen.writeNumberField(GAME_ID_FIELD, gameId);
|
||||
gen.writeEndObject();
|
||||
gen.flush();
|
||||
}
|
||||
@ -176,7 +166,6 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
jsonObject.put(INLINE_MESSAGE_ID_FIELD, inlineMessageId);
|
||||
}
|
||||
jsonObject.put(USER_ID_FIELD, userId);
|
||||
jsonObject.put(GAME_ID_FIELD, gameId);
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
@ -188,7 +177,6 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
", messageId=" + messageId +
|
||||
", inlineMessageId='" + inlineMessageId + '\'' +
|
||||
", userId=" + userId +
|
||||
", gameId=" + gameId +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -33,30 +33,28 @@ import java.io.Serializable;
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 2.4
|
||||
* @brief Use this method to set game score of the specified user in the game.
|
||||
* On success, if edited message is sent by the bot, the edited Message is returned,
|
||||
* otherwise True is returned.
|
||||
* If score is not greater than current users score in the chat,
|
||||
* an error with description “BOT_SCORE_NOT_MODIFIED” will be returned.
|
||||
* @brief Use this method to set the score of the specified user in a game.
|
||||
* On success, if the message was sent by the bot, returns the edited Message,
|
||||
* otherwise returns True.
|
||||
* If the new score is not greater than the user's current score in the chat,
|
||||
* returns an error with the description “BOT_SCORE_NOT_MODIFIED”.
|
||||
* @date 16 of September of 2016
|
||||
*/
|
||||
public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
public static final String PATH = "setGameScore";
|
||||
|
||||
private static final String USER_ID_FIELD = "user_id";
|
||||
private static final String SCORE_FIELD = "score";
|
||||
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 EDIT_MESSAGE_FIELD = "edit_message";
|
||||
private static final String USER_ID_FIELD = "user_id";
|
||||
private static final String GAME_ID_FIELD = "game_id";
|
||||
private static final String SCORE_FIELD = "score";
|
||||
|
||||
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)
|
||||
private Integer messageId; ///< Optional Required if inline_message_id is not specified. Unique identifier of the sent message
|
||||
private String inlineMessageId; ///< Optional Required if chat_id and message_id are not specified. Identifier of the inline message
|
||||
private Boolean editMessage; ///< Optional Pass True, if the message should be edited to include the current scoreboard
|
||||
private Integer userId; ///< User identifier
|
||||
private Integer gameId; ///< Game identifier
|
||||
private Integer score; ///< New score, must be positive
|
||||
|
||||
public SetGameScore() {
|
||||
@ -82,10 +80,6 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public Integer getGameId() {
|
||||
return gameId;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return score;
|
||||
}
|
||||
@ -115,11 +109,6 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetGameScore setGameId(Integer gameId) {
|
||||
this.gameId = gameId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetGameScore setScore(Integer score) {
|
||||
this.score = score;
|
||||
return this;
|
||||
@ -149,9 +138,6 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
if (userId == null) {
|
||||
throw new TelegramApiValidationException("UserId parameter can't be empty", this);
|
||||
}
|
||||
if (gameId == null) {
|
||||
throw new TelegramApiValidationException("GameId parameter can't be empty", this);
|
||||
}
|
||||
if (score == null) {
|
||||
throw new TelegramApiValidationException("Score parameter can't be empty", this);
|
||||
}
|
||||
@ -186,7 +172,6 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
gen.writeBooleanField(EDIT_MESSAGE_FIELD, editMessage);
|
||||
}
|
||||
gen.writeNumberField(USER_ID_FIELD, userId);
|
||||
gen.writeNumberField(GAME_ID_FIELD, gameId);
|
||||
gen.writeNumberField(SCORE_FIELD, score);
|
||||
gen.writeEndObject();
|
||||
gen.flush();
|
||||
@ -211,7 +196,6 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
jsonObject.put(EDIT_MESSAGE_FIELD, editMessage);
|
||||
}
|
||||
jsonObject.put(USER_ID_FIELD, userId);
|
||||
jsonObject.put(GAME_ID_FIELD, gameId);
|
||||
jsonObject.put(SCORE_FIELD, score);
|
||||
|
||||
return jsonObject;
|
||||
@ -225,7 +209,6 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
", inlineMessageId='" + inlineMessageId + '\'' +
|
||||
", editMessage=" + editMessage +
|
||||
", userId=" + userId +
|
||||
", gameId=" + gameId +
|
||||
", score=" + score +
|
||||
'}';
|
||||
}
|
||||
|
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* This file is part of TelegramBots.
|
||||
*
|
||||
* Foobar is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* Foobar is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.telegram.telegrambots.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.telegram.telegrambots.Constants;
|
||||
import org.telegram.telegrambots.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.api.objects.Message;
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* @brief Use this method to send a game. On success, the sent Message is returned.
|
||||
* @date 27 of September of 2016
|
||||
*/
|
||||
public class SendGame extends BotApiMethod<Message> {
|
||||
public static final String PATH = "sendGame";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
private static final String GAMESHORTNAME_FIELD = "game_short_name";
|
||||
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
|
||||
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
|
||||
private static final String REPLYMARKUP_FIELD = "reply_markup";
|
||||
|
||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||
private String gameShortName; ///< Short name of the game
|
||||
/**
|
||||
* Optional. Sends the message silently. iOS users will not receive a notification, Android
|
||||
* users will receive a notification with no sound. Other apps coming soon
|
||||
*/
|
||||
private Boolean disableNotification;
|
||||
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
|
||||
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
|
||||
|
||||
public SendGame() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
public SendGame setChatId(String chatId) {
|
||||
this.chatId = chatId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getReplyToMessageId() {
|
||||
return replyToMessageId;
|
||||
}
|
||||
|
||||
public SendGame setReplyToMessageId(Integer replyToMessageId) {
|
||||
this.replyToMessageId = replyToMessageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReplyKeyboard getReplyMarkup() {
|
||||
return replyMarkup;
|
||||
}
|
||||
|
||||
public SendGame setReplyMarkup(ReplyKeyboard replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getDisableNotification() {
|
||||
return disableNotification;
|
||||
}
|
||||
|
||||
public SendGame enableNotification() {
|
||||
this.disableNotification = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendGame disableNotification() {
|
||||
this.disableNotification = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getGameShortName() {
|
||||
return gameShortName;
|
||||
}
|
||||
|
||||
public SendGame setGameShortName(String gameShortName) {
|
||||
this.gameShortName = gameShortName;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put(CHATID_FIELD, chatId);
|
||||
jsonObject.put(GAMESHORTNAME_FIELD, gameShortName);
|
||||
if (disableNotification != null) {
|
||||
jsonObject.put(DISABLENOTIFICATION_FIELD, disableNotification);
|
||||
}
|
||||
if (replyToMessageId != null) {
|
||||
jsonObject.put(REPLYTOMESSAGEID_FIELD, replyToMessageId);
|
||||
}
|
||||
if (replyMarkup != null) {
|
||||
jsonObject.put(REPLYMARKUP_FIELD, replyMarkup.toJson());
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(JSONObject answer) {
|
||||
if (answer.getBoolean(Constants.RESPONSEFIELDOK)) {
|
||||
return new Message(answer.getJSONObject(Constants.RESPONSEFIELDRESULT));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (gameShortName == null || gameShortName.isEmpty()) {
|
||||
throw new TelegramApiValidationException("GameShortName parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeStartObject();
|
||||
gen.writeStringField(METHOD_FIELD, PATH);
|
||||
gen.writeStringField(CHATID_FIELD, chatId);
|
||||
gen.writeStringField(GAMESHORTNAME_FIELD, gameShortName);
|
||||
if (disableNotification != null) {
|
||||
gen.writeBooleanField(DISABLENOTIFICATION_FIELD, disableNotification);
|
||||
}
|
||||
if (replyToMessageId != null) {
|
||||
gen.writeNumberField(REPLYTOMESSAGEID_FIELD, replyToMessageId);
|
||||
}
|
||||
if (replyMarkup != null) {
|
||||
gen.writeObjectField(REPLYMARKUP_FIELD, replyMarkup);
|
||||
}
|
||||
gen.writeEndObject();
|
||||
gen.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
|
||||
serialize(gen, serializers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SendGame{" +
|
||||
"chatId='" + chatId + '\'' +
|
||||
", gameShortName='" + gameShortName + '\'' +
|
||||
", disableNotification=" + disableNotification +
|
||||
", replyToMessageId=" + replyToMessageId +
|
||||
", replyMarkup=" + replyMarkup +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -13,10 +13,12 @@ import java.io.IOException;
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* @brief This object represents an incoming callback query from a callback button in an inline
|
||||
* keyboard. If the button that originated the query was attached to a message sent by the bot, the
|
||||
* field message will be presented. If the button was attached to a message sent via the bot (in
|
||||
* inline mode), the field inline_message_id will be presented.
|
||||
* @brief This object represents an incoming callback query from a
|
||||
* callback button in an inline keyboard.
|
||||
* If the button that originated the query was attached to a message sent by the bot,
|
||||
* the field message will be present. If the button was attached to a message sent via the bot
|
||||
* (in inline mode), the field inline_message_id will be present.
|
||||
* @note Exactly one of the fields data or game_short_name will be present.
|
||||
* @date 10 of April of 2016
|
||||
*/
|
||||
public class CallbackQuery implements IBotApiObject {
|
||||
@ -26,7 +28,7 @@ public class CallbackQuery implements IBotApiObject {
|
||||
private static final String MESSAGE_FIELD = "message";
|
||||
private static final String INLINE_MESSAGE_ID_FIELD = "inline_message_id";
|
||||
private static final String DATA_FIELD = "data";
|
||||
private static final String GAMEID_FIELD = "game_id";
|
||||
private static final String GAMESHORTNAME_FIELD = "game_short_name";
|
||||
private static final String CHAT_INSTANCE_FIELD = "chat_instance";
|
||||
|
||||
@JsonProperty(ID_FIELD)
|
||||
@ -50,8 +52,8 @@ public class CallbackQuery implements IBotApiObject {
|
||||
* @note Be aware that a bad client can send arbitrary data in this field
|
||||
*/
|
||||
private String data;
|
||||
@JsonProperty(GAMEID_FIELD)
|
||||
private Integer gameId; ///< Optional. Game identifier as specified in the callback game button. Be aware that a bad client can send an arbitrary identifier in this field.
|
||||
@JsonProperty(GAMESHORTNAME_FIELD)
|
||||
private String gameShortName; ///< Optional. Game short name.
|
||||
@JsonProperty(CHAT_INSTANCE_FIELD)
|
||||
private String chatInstance; ///< Identifier, uniquely corresponding to the chat a message with the callback button was sent to
|
||||
|
||||
@ -73,8 +75,8 @@ public class CallbackQuery implements IBotApiObject {
|
||||
if (jsonObject.has(DATA_FIELD)) {
|
||||
data = jsonObject.getString(DATA_FIELD);
|
||||
}
|
||||
if (jsonObject.has(GAMEID_FIELD)) {
|
||||
gameId = jsonObject.getInt(GAMEID_FIELD);
|
||||
if (jsonObject.has(GAMESHORTNAME_FIELD)) {
|
||||
gameShortName = jsonObject.getString(GAMESHORTNAME_FIELD);
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,8 +100,8 @@ public class CallbackQuery implements IBotApiObject {
|
||||
return data;
|
||||
}
|
||||
|
||||
public Integer getGameId() {
|
||||
return gameId;
|
||||
public String getGameShortName() {
|
||||
return gameShortName;
|
||||
}
|
||||
|
||||
public String getChatInstance() {
|
||||
@ -121,8 +123,8 @@ public class CallbackQuery implements IBotApiObject {
|
||||
if (data != null) {
|
||||
gen.writeStringField(DATA_FIELD, data);
|
||||
}
|
||||
if (gameId != null) {
|
||||
gen.writeNumberField(GAMEID_FIELD, gameId);
|
||||
if (gameShortName != null) {
|
||||
gen.writeStringField(GAMESHORTNAME_FIELD, gameShortName);
|
||||
}
|
||||
gen.writeEndObject();
|
||||
gen.flush();
|
||||
@ -141,7 +143,7 @@ public class CallbackQuery implements IBotApiObject {
|
||||
", message=" + message +
|
||||
", inlineMessageId='" + inlineMessageId + '\'' +
|
||||
", data='" + data + '\'' +
|
||||
", gameId=" + gameId +
|
||||
", gameShortName='" + gameShortName + '\'' +
|
||||
", chatInstance='" + chatInstance + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.telegram.telegrambots.api.interfaces.IBotApiObject;
|
||||
import org.telegram.telegrambots.api.objects.games.Game;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -52,6 +53,8 @@ public class Message implements IBotApiObject {
|
||||
private static final String MIGRATETOCHAT_FIELD = "migrate_to_chat_id";
|
||||
private static final String MIGRATEFROMCHAT_FIELD = "migrate_from_chat_id";
|
||||
private static final String EDITDATE_FIELD = "edit_date";
|
||||
private static final String GAME_FIELD = "game";
|
||||
|
||||
@JsonProperty(MESSAGEID_FIELD)
|
||||
private Integer messageId; ///< Integer Unique message identifier
|
||||
@JsonProperty(FROM_FIELD)
|
||||
@ -148,6 +151,8 @@ public class Message implements IBotApiObject {
|
||||
private Long migrateFromChatId; ///< Optional. The chat has been migrated from a chat with specified identifier, not exceeding 1e13 by absolute value
|
||||
@JsonProperty(EDITDATE_FIELD)
|
||||
private Integer editDate; ///< Optional. Date the message was last edited in Unix time
|
||||
@JsonProperty(GAME_FIELD)
|
||||
private Game game; ///< Optional. Message is a game, information about the game
|
||||
|
||||
public Message() {
|
||||
super();
|
||||
@ -259,7 +264,9 @@ public class Message implements IBotApiObject {
|
||||
if (jsonObject.has(EDITDATE_FIELD)) {
|
||||
editDate = jsonObject.getInt(EDITDATE_FIELD);
|
||||
}
|
||||
|
||||
if (jsonObject.has(GAME_FIELD)) {
|
||||
game = new Game(jsonObject.getJSONObject(GAME_FIELD));
|
||||
}
|
||||
if (hasText() && entities != null) {
|
||||
entities.forEach(x -> x.computeText(text));
|
||||
}
|
||||
@ -441,6 +448,14 @@ public class Message implements IBotApiObject {
|
||||
return editDate;
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
private boolean hasGame() {
|
||||
return game != null;
|
||||
}
|
||||
|
||||
public boolean hasEntities() {
|
||||
return entities != null && !entities.isEmpty();
|
||||
}
|
||||
@ -542,6 +557,9 @@ public class Message implements IBotApiObject {
|
||||
if (editDate != null) {
|
||||
gen.writeNumberField(EDITDATE_FIELD, editDate);
|
||||
}
|
||||
if (game != null) {
|
||||
gen.writeObjectField(GAME_FIELD, game);
|
||||
}
|
||||
gen.writeEndObject();
|
||||
gen.flush();
|
||||
}
|
||||
@ -562,6 +580,7 @@ public class Message implements IBotApiObject {
|
||||
", forwardFromChat=" + forwardFromChat +
|
||||
", forwardDate=" + forwardDate +
|
||||
", text='" + text + '\'' +
|
||||
", entities=" + entities +
|
||||
", audio=" + audio +
|
||||
", document=" + document +
|
||||
", photo=" + photo +
|
||||
@ -570,6 +589,7 @@ public class Message implements IBotApiObject {
|
||||
", contact=" + contact +
|
||||
", location=" + location +
|
||||
", venue=" + venue +
|
||||
", pinnedMessage=" + pinnedMessage +
|
||||
", newChatMember=" + newChatMember +
|
||||
", leftChatMember=" + leftChatMember +
|
||||
", newChatTitle='" + newChatTitle + '\'' +
|
||||
@ -578,12 +598,13 @@ public class Message implements IBotApiObject {
|
||||
", groupchatCreated=" + groupchatCreated +
|
||||
", replyToMessage=" + replyToMessage +
|
||||
", voice=" + voice +
|
||||
", caption=" + caption +
|
||||
", caption='" + caption + '\'' +
|
||||
", superGroupCreated=" + superGroupCreated +
|
||||
", channelChatCreated=" + channelChatCreated +
|
||||
", migrateToChatId=" + migrateToChatId +
|
||||
", migrateFromChatId=" + migrateFromChatId +
|
||||
", editDate=" + editDate +
|
||||
", game=" + game +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of TelegramBots.
|
||||
*
|
||||
* TelegramBots is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* Foobar is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.telegram.telegrambots.api.objects.games;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.telegram.telegrambots.api.interfaces.IBotApiObject;
|
||||
import org.telegram.telegrambots.api.objects.PhotoSize;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 2.4
|
||||
* @brief This object represents an animation file.
|
||||
* @date 27 of September of 2016
|
||||
*/
|
||||
public class Animation implements IBotApiObject {
|
||||
private static final String FILEID_FIELD = "file_id";
|
||||
private static final String THUMB_FIELD = "thumb";
|
||||
private static final String FILENAME_FIELD = "file_name";
|
||||
private static final String MIMETYPE_FIELD = "mime_type";
|
||||
private static final String FILESIZE_FIELD = "file_size";
|
||||
|
||||
@JsonProperty(FILEID_FIELD)
|
||||
private String fileId; ///< Unique file identifier
|
||||
@JsonProperty(THUMB_FIELD)
|
||||
private PhotoSize thumb; ///< Optional. Animation thumbnail as defined by sender
|
||||
@JsonProperty(FILENAME_FIELD)
|
||||
private String fileName; ///< Optional. Original animation filename as defined by sender
|
||||
@JsonProperty(MIMETYPE_FIELD)
|
||||
private String mimetype; ///< Optional. MIME type of the file as defined by sender
|
||||
@JsonProperty(FILESIZE_FIELD)
|
||||
private Integer fileSize; ///< Optional. File size
|
||||
|
||||
public Animation() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Animation(JSONObject object) {
|
||||
super();
|
||||
fileId = object.getString(FILEID_FIELD);
|
||||
if (object.has(THUMB_FIELD)) {
|
||||
thumb = new PhotoSize(object.getJSONObject(THUMB_FIELD));
|
||||
}
|
||||
if (object.has(FILENAME_FIELD)) {
|
||||
fileName = object.getString(FILENAME_FIELD);
|
||||
}
|
||||
if (object.has(MIMETYPE_FIELD)) {
|
||||
mimetype = object.getString(MIMETYPE_FIELD);
|
||||
}
|
||||
if (object.has(FILESIZE_FIELD)) {
|
||||
fileSize = object.getInt(FILESIZE_FIELD);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public PhotoSize getThumb() {
|
||||
return thumb;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public String getMimetype() {
|
||||
return mimetype;
|
||||
}
|
||||
|
||||
public Integer getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeStartObject();
|
||||
gen.writeStringField(FILEID_FIELD, fileId);
|
||||
if (thumb != null) {
|
||||
gen.writeObjectField(THUMB_FIELD, thumb);
|
||||
}
|
||||
if (fileName != null) {
|
||||
gen.writeStringField(FILENAME_FIELD, fileName);
|
||||
}
|
||||
if (mimetype != null) {
|
||||
gen.writeStringField(MIMETYPE_FIELD, mimetype);
|
||||
}
|
||||
if (fileSize != null) {
|
||||
gen.writeNumberField(FILESIZE_FIELD, fileSize);
|
||||
}
|
||||
gen.writeEndObject();
|
||||
gen.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
|
||||
serialize(gen, serializers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Animation{" +
|
||||
"fileId='" + fileId + '\'' +
|
||||
", thumb=" + thumb +
|
||||
", fileName='" + fileName + '\'' +
|
||||
", mimetype='" + mimetype + '\'' +
|
||||
", fileSize=" + fileSize +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is part of TelegramBots.
|
||||
*
|
||||
* Foobar is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* Foobar is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.telegram.telegrambots.api.objects.games;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.telegram.telegrambots.api.interfaces.IBotApiObject;
|
||||
import org.telegram.telegrambots.api.objects.PhotoSize;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 2.4
|
||||
* @brief This object represents a game.
|
||||
* @date 27 of September of 2016
|
||||
*/
|
||||
public class Game implements IBotApiObject {
|
||||
private static final String TITLE_FIELD = "title";
|
||||
private static final String DESCRIPTION_FIELD = "description";
|
||||
private static final String PHOTO_FIELD = "photo";
|
||||
private static final String ANIMATION_FIELD = "animation";
|
||||
|
||||
@JsonProperty(TITLE_FIELD)
|
||||
private String title; ///< Title of the game
|
||||
@JsonProperty(DESCRIPTION_FIELD)
|
||||
private String description; ///< Description of the game
|
||||
@JsonProperty(PHOTO_FIELD)
|
||||
private PhotoSize photo; ///< Photo
|
||||
@JsonProperty(ANIMATION_FIELD)
|
||||
private Animation animation; ///< Optional. Animation
|
||||
|
||||
public Game() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Game(JSONObject object) {
|
||||
super();
|
||||
title = object.getString(TITLE_FIELD);
|
||||
description = object.getString(DESCRIPTION_FIELD);
|
||||
photo = new PhotoSize(object.getJSONObject(PHOTO_FIELD));
|
||||
animation = new Animation(object.getJSONObject(ANIMATION_FIELD));
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public PhotoSize getPhoto() {
|
||||
return photo;
|
||||
}
|
||||
|
||||
public Animation getAnimation() {
|
||||
return animation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeStartObject();
|
||||
gen.writeStringField(TITLE_FIELD, title);
|
||||
gen.writeStringField(DESCRIPTION_FIELD, description);
|
||||
gen.writeObjectField(PHOTO_FIELD, photo);
|
||||
gen.writeObjectField(ANIMATION_FIELD, animation);
|
||||
gen.writeEndObject();
|
||||
gen.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
|
||||
serialize(gen, serializers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Game{" +
|
||||
"title='" + title + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", photo=" + photo +
|
||||
", animation=" + animation +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* This file is part of TelegramBots.
|
||||
*
|
||||
* Foobar is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* Foobar is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.telegram.telegrambots.api.objects.inlinequery.result;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* @brief Represents a Game
|
||||
* @note This will only work in Telegram versions released after 1 October, 2016. Older clients will ignore them.
|
||||
* @date 27 of September 2016
|
||||
*/
|
||||
public class InlineQueryResultGame implements InlineQueryResult {
|
||||
|
||||
private static final String TYPE_FIELD = "type";
|
||||
@JsonProperty(TYPE_FIELD)
|
||||
private static final String type = "game"; ///< Type of the result, must be "game"
|
||||
private static final String ID_FIELD = "id";
|
||||
private static final String GAMESHORTNAME_FIELD = "game_short_name";
|
||||
private static final String REPLY_MARKUP_FIELD = "reply_markup";
|
||||
|
||||
@JsonProperty(ID_FIELD)
|
||||
private String id; ///< Unique identifier of this result, 1-64 bytes
|
||||
@JsonProperty(GAMESHORTNAME_FIELD)
|
||||
private String gameShortName; ///< Short name of the game
|
||||
@JsonProperty(REPLY_MARKUP_FIELD)
|
||||
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
|
||||
|
||||
public static String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public InlineQueryResultGame setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public InlineKeyboardMarkup getReplyMarkup() {
|
||||
return replyMarkup;
|
||||
}
|
||||
|
||||
public InlineQueryResultGame setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getGameShortName() {
|
||||
return gameShortName;
|
||||
}
|
||||
|
||||
public void setGameShortName(String gameShortName) {
|
||||
this.gameShortName = gameShortName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (id == null || id.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ID parameter can't be empty", this);
|
||||
}
|
||||
if (gameShortName == null || gameShortName.isEmpty()) {
|
||||
throw new TelegramApiValidationException("GameShortName parameter can't be empty", this);
|
||||
}
|
||||
if (replyMarkup != null) {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
jsonObject.put(TYPE_FIELD, type);
|
||||
jsonObject.put(ID_FIELD, id);
|
||||
jsonObject.put(GAMESHORTNAME_FIELD, gameShortName);
|
||||
if (replyMarkup != null) {
|
||||
jsonObject.put(REPLY_MARKUP_FIELD, replyMarkup.toJson());
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeStartObject();
|
||||
gen.writeStringField(TYPE_FIELD, type);
|
||||
gen.writeStringField(ID_FIELD, id);
|
||||
gen.writeStringField(GAMESHORTNAME_FIELD, gameShortName);
|
||||
if (replyMarkup != null) {
|
||||
gen.writeObjectField(REPLY_MARKUP_FIELD, replyMarkup);
|
||||
}
|
||||
gen.writeEndObject();
|
||||
gen.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
|
||||
serialize(gen, serializers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InlineQueryResultGame{" +
|
||||
"id='" + id + '\'' +
|
||||
", gameShortName='" + gameShortName + '\'' +
|
||||
", replyMarkup=" + replyMarkup +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -38,14 +38,19 @@ public class InlineKeyboardButton implements IBotApiObject, IToJson, IValidable
|
||||
@JsonProperty(CALLBACK_DATA_FIELD)
|
||||
private String callbackData; ///< Optional. Data to be sent in a callback query to the bot when button is pressed
|
||||
@JsonProperty(CALLBACK_GAME_FIELD)
|
||||
private CallbackGame callbackGame; ///< Optional. Description of the game that will be launched when the user presses the button
|
||||
/**
|
||||
* Optional. Description of the game that will be launched when the user presses the button.
|
||||
*
|
||||
* @note This type of button must always be the first button in the first row.
|
||||
*/
|
||||
private CallbackGame callbackGame;
|
||||
@JsonProperty(SWITCH_INLINE_QUERY_FIELD)
|
||||
/**
|
||||
* Optional.
|
||||
* If set, pressing the button will prompt the user to select one of their chats,
|
||||
* open that chat and insert the bot‘s username and the specified inline query in the input field.
|
||||
* Can be empty, in which case just the bot’s username will be inserted.
|
||||
* @Note: This offers an easy way for users to start using your bot in inline mode when
|
||||
* @note: This offers an easy way for users to start using your bot in inline mode when
|
||||
* they are currently in a private chat with it.
|
||||
* Especially useful when combined with switch_pm… actions – in this case the user will
|
||||
* be automatically returned to the chat they switched from, skipping the chat selection screen.
|
||||
|
@ -39,6 +39,7 @@ import org.telegram.telegrambots.api.methods.send.SendAudio;
|
||||
import org.telegram.telegrambots.api.methods.send.SendChatAction;
|
||||
import org.telegram.telegrambots.api.methods.send.SendContact;
|
||||
import org.telegram.telegrambots.api.methods.send.SendDocument;
|
||||
import org.telegram.telegrambots.api.methods.send.SendGame;
|
||||
import org.telegram.telegrambots.api.methods.send.SendLocation;
|
||||
import org.telegram.telegrambots.api.methods.send.SendMessage;
|
||||
import org.telegram.telegrambots.api.methods.send.SendPhoto;
|
||||
@ -319,6 +320,13 @@ public abstract class AbsSender {
|
||||
return sendApiMethod(getGameHighScores);
|
||||
}
|
||||
|
||||
public final Message sendGame(SendGame sendGame) throws TelegramApiException {
|
||||
if(sendGame == null){
|
||||
throw new TelegramApiException("Parameter sendGame can not be null");
|
||||
}
|
||||
return sendApiMethod(sendGame);
|
||||
}
|
||||
|
||||
// Send Requests Async
|
||||
|
||||
public final void sendMessageAsync(SendMessage sendMessage, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||
@ -580,6 +588,16 @@ public abstract class AbsSender {
|
||||
sendApiMethodAsync(getGameHighScores, sentCallback);
|
||||
}
|
||||
|
||||
public final void sendGameAsync(SendGame sendGame, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||
if (sendGame == null) {
|
||||
throw new TelegramApiException("Parameter sendGame can not be null");
|
||||
}
|
||||
if (sentCallback == null) {
|
||||
throw new TelegramApiException("Parameter sentCallback can not be null");
|
||||
}
|
||||
sendApiMethodAsync(sendGame, sentCallback);
|
||||
}
|
||||
|
||||
public final void downloadFileAsync(File file, DownloadFileCallback callback) throws TelegramApiException {
|
||||
if(file == null){
|
||||
throw new TelegramApiException("Parameter file can not be null");
|
||||
|
Loading…
Reference in New Issue
Block a user