Clear CallbackGame
This commit is contained in:
parent
8fdad42297
commit
238125879a
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots</artifactId>
|
<artifactId>telegrambots</artifactId>
|
||||||
<version>2.4.0.BETA3-SNAPSHOT</version>
|
<version>2.4.0.BETA4-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>Telegram Bots</name>
|
<name>Telegram Bots</name>
|
||||||
<url>https://github.com/rubenlagus/TelegramBots</url>
|
<url>https://github.com/rubenlagus/TelegramBots</url>
|
||||||
|
@ -17,80 +17,42 @@
|
|||||||
|
|
||||||
package org.telegram.telegrambots.api.objects.games;
|
package org.telegram.telegrambots.api.objects.games;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.telegram.telegrambots.api.interfaces.IBotApiObject;
|
import org.telegram.telegrambots.api.interfaces.IBotApiObject;
|
||||||
import org.telegram.telegrambots.api.interfaces.Validable;
|
|
||||||
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ruben Bermudez
|
* @author Ruben Bermudez
|
||||||
* @version 2.4
|
* @version 2.4
|
||||||
* @brief This object contains information about a game that will be returned as a response to a callback query.
|
* @brief This object contains information about a game that will be returned as a response to a
|
||||||
|
* callback query. It has no fields, use BotFather to setup your game,
|
||||||
|
* its short name will actt as an identifier.
|
||||||
* @date 16 of September of 2016
|
* @date 16 of September of 2016
|
||||||
*/
|
*/
|
||||||
public class CallbackGame implements IBotApiObject, Validable {
|
public class CallbackGame implements IBotApiObject {
|
||||||
private static final String TITLE_FIELD = "title";
|
private final JSONObject content;
|
||||||
private static final String ID_FIELD = "game_id";
|
|
||||||
private static final String START_PARAMETER_FIELD = "start_parameter";
|
|
||||||
|
|
||||||
@JsonProperty(TITLE_FIELD)
|
|
||||||
private String title; ///< Game title, aim at 128 characters or lower
|
|
||||||
@JsonProperty(ID_FIELD)
|
|
||||||
private Integer gameId; ///< Game identifier
|
|
||||||
@JsonProperty(START_PARAMETER_FIELD)
|
|
||||||
private String startParameter; ///< Start parameter for the bot URL when users share the game with others. See deep linking for more info.
|
|
||||||
|
|
||||||
public CallbackGame() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CallbackGame(JSONObject object) {
|
public CallbackGame(JSONObject object) {
|
||||||
super();
|
super();
|
||||||
title = object.getString(TITLE_FIELD);
|
content = object;
|
||||||
gameId = object.getInt(ID_FIELD);
|
|
||||||
startParameter = object.getString(START_PARAMETER_FIELD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public JSONObject getContent() {
|
||||||
return title;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getGameId() {
|
public String getContentText() {
|
||||||
return gameId;
|
return content.toString();
|
||||||
}
|
|
||||||
|
|
||||||
public String getStartParameter() {
|
|
||||||
return startParameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validate() throws TelegramApiValidationException {
|
|
||||||
if (title == null || title.isEmpty()) {
|
|
||||||
throw new TelegramApiValidationException("Title parameter can't be empty", this);
|
|
||||||
}
|
|
||||||
if (gameId == null) {
|
|
||||||
throw new TelegramApiValidationException("Id parameter can't be empty", this);
|
|
||||||
}
|
|
||||||
if (startParameter == null || startParameter.isEmpty()) {
|
|
||||||
throw new TelegramApiValidationException("StartParameter parameter can't be empty", this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||||
gen.writeStartObject();
|
gen.writeObject(content);
|
||||||
gen.writeStringField(TITLE_FIELD, title);
|
|
||||||
gen.writeNumberField(ID_FIELD, gameId);
|
|
||||||
gen.writeStringField(START_PARAMETER_FIELD, startParameter);
|
|
||||||
gen.writeEndObject();
|
|
||||||
gen.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,9 +63,7 @@ public class CallbackGame implements IBotApiObject, Validable {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CallbackGame{" +
|
return "CallbackGame{" +
|
||||||
"title='" + title + '\'' +
|
"content=" + content +
|
||||||
", gameId=" + gameId +
|
|
||||||
", startParameter='" + startParameter + '\'' +
|
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,9 +147,6 @@ public class InlineKeyboardButton implements IBotApiObject, IToJson, Validable {
|
|||||||
if (text == null || text.isEmpty()) {
|
if (text == null || text.isEmpty()) {
|
||||||
throw new TelegramApiValidationException("Text parameter can't be empty", this);
|
throw new TelegramApiValidationException("Text parameter can't be empty", this);
|
||||||
}
|
}
|
||||||
if (callbackGame != null) {
|
|
||||||
callbackGame.validate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user