Skip to content

Commit 4b9adff

Browse files
committed
Added Game, Animation objects. New method sendGame, new object InlineQueryResultGame, new field game in Message
1 parent 642c7ca commit 4b9adff

File tree

8 files changed

+215
-1
lines changed

8 files changed

+215
-1
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
/**
4+
* Stas Parshin
5+
* 03 October 2016
6+
*/
7+
public class Animation {
8+
9+
private String file_id;
10+
private PhotoSize thumb;
11+
private String file_name;
12+
private String mime_type;
13+
private Integer file_size;
14+
15+
public String fileId() {
16+
return file_id;
17+
}
18+
19+
public PhotoSize thumb() {
20+
return thumb;
21+
}
22+
23+
public String fileName() {
24+
return file_name;
25+
}
26+
27+
public String mimeType() {
28+
return mime_type;
29+
}
30+
31+
public Integer fileSize() {
32+
return file_size;
33+
}
34+
35+
@Override
36+
public boolean equals(Object o) {
37+
if (this == o) return true;
38+
if (o == null || getClass() != o.getClass()) return false;
39+
40+
Animation animation = (Animation) o;
41+
42+
if (file_id != null ? !file_id.equals(animation.file_id) : animation.file_id != null) return false;
43+
if (thumb != null ? !thumb.equals(animation.thumb) : animation.thumb != null) return false;
44+
if (file_name != null ? !file_name.equals(animation.file_name) : animation.file_name != null) return false;
45+
if (mime_type != null ? !mime_type.equals(animation.mime_type) : animation.mime_type != null) return false;
46+
return file_size != null ? file_size.equals(animation.file_size) : animation.file_size == null;
47+
}
48+
49+
@Override
50+
public int hashCode() {
51+
return file_id != null ? file_id.hashCode() : 0;
52+
}
53+
54+
@Override
55+
public String toString() {
56+
return "Animation{" +
57+
"file_id='" + file_id + '\'' +
58+
", thumb=" + thumb +
59+
", file_name='" + file_name + '\'' +
60+
", mime_type='" + mime_type + '\'' +
61+
", file_size=" + file_size +
62+
'}';
63+
}
64+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* Stas Parshin
7+
* 03 October 2016
8+
*/
9+
public class Game {
10+
11+
private String title;
12+
private String description;
13+
private PhotoSize[] photo;
14+
15+
private String text;
16+
private MessageEntity[] text_entities;
17+
private Animation animation;
18+
19+
public String title() {
20+
return title;
21+
}
22+
23+
public String description() {
24+
return description;
25+
}
26+
27+
public PhotoSize[] photo() {
28+
return photo;
29+
}
30+
31+
public String text() {
32+
return text;
33+
}
34+
35+
public MessageEntity[] textEntities() {
36+
return text_entities;
37+
}
38+
39+
public Animation animation() {
40+
return animation;
41+
}
42+
43+
@Override
44+
public boolean equals(Object o) {
45+
if (this == o) return true;
46+
if (o == null || getClass() != o.getClass()) return false;
47+
48+
Game game = (Game) o;
49+
50+
if (!title.equals(game.title)) return false;
51+
if (!description.equals(game.description)) return false;
52+
// Probably incorrect - comparing Object[] arrays with Arrays.equals
53+
if (!Arrays.equals(photo, game.photo)) return false;
54+
if (text != null ? !text.equals(game.text) : game.text != null) return false;
55+
// Probably incorrect - comparing Object[] arrays with Arrays.equals
56+
if (!Arrays.equals(text_entities, game.text_entities)) return false;
57+
if (animation != null ? !animation.equals(game.animation) : game.animation != null) return false;
58+
59+
return true;
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
int result = title.hashCode();
65+
result = 31 * result + description.hashCode();
66+
result = 31 * result + Arrays.hashCode(photo);
67+
result = 31 * result + (text != null ? text.hashCode() : 0);
68+
result = 31 * result + Arrays.hashCode(text_entities);
69+
result = 31 * result + (animation != null ? animation.hashCode() : 0);
70+
return result;
71+
}
72+
73+
@Override
74+
public String toString() {
75+
return "Game{" +
76+
"title='" + title + '\'' +
77+
", description='" + description + '\'' +
78+
", photo=" + Arrays.toString(photo) +
79+
", text='" + text + '\'' +
80+
", text_entities=" + Arrays.toString(text_entities) +
81+
", animation=" + animation +
82+
'}';
83+
}
84+
}

src/main/java/com/pengrad/telegrambot/model/Message.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Message {
2121
private MessageEntity[] entities;
2222
private Audio audio;
2323
private Document document;
24+
private Game game;
2425
private PhotoSize[] photo;
2526
private Sticker sticker;
2627
private Video video;
@@ -93,6 +94,10 @@ public Document document() {
9394
return document;
9495
}
9596

97+
public Game game() {
98+
return game;
99+
}
100+
96101
public PhotoSize[] photo() {
97102
return photo;
98103
}
@@ -192,6 +197,7 @@ public boolean equals(Object o) {
192197
if (!Arrays.equals(entities, message.entities)) return false;
193198
if (audio != null ? !audio.equals(message.audio) : message.audio != null) return false;
194199
if (document != null ? !document.equals(message.document) : message.document != null) return false;
200+
if (game != null ? !game.equals(message.game) : message.game != null) return false;
195201
// Probably incorrect - comparing Object[] arrays with Arrays.equals
196202
if (!Arrays.equals(photo, message.photo)) return false;
197203
if (sticker != null ? !sticker.equals(message.sticker) : message.sticker != null) return false;
@@ -246,6 +252,7 @@ public String toString() {
246252
", entities=" + Arrays.toString(entities) +
247253
", audio=" + audio +
248254
", document=" + document +
255+
", game=" + game +
249256
", photo=" + Arrays.toString(photo) +
250257
", sticker=" + sticker +
251258
", video=" + video +
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.pengrad.telegrambot.model.request;
2+
3+
/**
4+
* Stas Parshin
5+
* 03 October 2016
6+
*/
7+
public class InlineQueryResultGame extends InlineQueryResult<InlineQueryResultGame> {
8+
9+
private String game_short_name;
10+
11+
public InlineQueryResultGame(String id, String gameShortName) {
12+
super("game", id);
13+
game_short_name = gameShortName;
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.pengrad.telegrambot.request;
2+
3+
/**
4+
* Stas Parshin
5+
* 03 October 2016
6+
*/
7+
public class SendGame extends AbstractSendRequest<SendGame> {
8+
9+
public SendGame(Object chatId, String gameShortName) {
10+
super(chatId);
11+
add("game_short_name", gameShortName);
12+
}
13+
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.pengrad.telegrambot;
2+
3+
import com.pengrad.telegrambot.model.Game;
4+
5+
import static org.junit.Assert.assertNotNull;
6+
7+
/**
8+
* Stas Parshin
9+
* 03 October 2016
10+
*/
11+
public class GameTest {
12+
13+
public static void check(Game game) {
14+
assertNotNull(game.title());
15+
assertNotNull(game.description());
16+
PhotoSizeTest.checkPhotos(game.photo());
17+
}
18+
19+
}

src/test/java/com/pengrad/telegrambot/MessageTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ public static void checkLocationMessage(Message message) {
6363
checkMessage(message);
6464
LocationTest.check(message.location());
6565
}
66+
67+
public static void checkGameMessage(Message message) {
68+
checkMessage(message);
69+
GameTest.check(message.game());
70+
}
6671
}

src/test/java/com/pengrad/telegrambot/TelegramBotTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void answerInline() {
9595

9696
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup(
9797
new InlineKeyboardButton[]{
98-
new InlineKeyboardButton("inline game").callbackGame("pengrad_test_game"),
98+
// new InlineKeyboardButton("inline game").callbackGame("pengrad_test_game"),
9999
new InlineKeyboardButton("inline ok").callbackData("callback ok")
100100

101101
});
@@ -224,4 +224,10 @@ public void getWebhookInfo() {
224224
GetWebhookInfoResponse response = bot.execute(new GetWebhookInfo());
225225
WebhookInfoTest.check(response.webhookInfo());
226226
}
227+
228+
@Test
229+
public void sendGame() {
230+
SendResponse response = bot.execute(new SendGame(chatId, "pengrad_test_game"));
231+
MessageTest.checkGameMessage(response.message());
232+
}
227233
}

0 commit comments

Comments
 (0)