Skip to content

Commit 1345898

Browse files
committed
Implement mixed-format sticker packs & add ReplaceStickerInSet method
1 parent 12697dc commit 1345898

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

library/src/main/java/com/pengrad/telegrambot/model/StickerSet.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public Type stickerType() {
3535
return sticker_type;
3636
}
3737

38+
/**
39+
* @deprecated StickerSets can contain both animated and non-animated stickers since Bot API 7.2
40+
*/
41+
@Deprecated
3842
public Boolean isAnimated() {
3943
return is_animated;
4044
}
@@ -63,6 +67,10 @@ public PhotoSize thumb() {
6367
return thumbnail();
6468
}
6569

70+
/**
71+
* @deprecated StickerSets can contain both animated and non-animated stickers since Bot API 7.2
72+
*/
73+
@Deprecated
6674
public Boolean isVideo() {
6775
return is_video;
6876
}

library/src/main/java/com/pengrad/telegrambot/model/request/InputSticker.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.pengrad.telegrambot.model.request;
22

3+
import com.google.gson.annotations.SerializedName;
34
import com.pengrad.telegrambot.AttachName;
45
import com.pengrad.telegrambot.model.MaskPosition;
6+
import com.pengrad.telegrambot.model.Sticker;
57

68
import java.io.Serializable;
9+
import java.util.Arrays;
10+
import java.util.Objects;
711

812
public class InputSticker implements Serializable {
913

@@ -13,6 +17,7 @@ public class InputSticker implements Serializable {
1317
private String[] emoji_list;
1418
private MaskPosition mask_position;
1519
private String[] keywords;
20+
private Sticker.Format format;
1621
transient private String attachName;
1722
transient private Object attach;
1823

@@ -45,4 +50,43 @@ public InputSticker keywords(String[] keywords) {
4550
return this;
4651
}
4752

53+
public InputSticker format(Sticker.Format format) {
54+
this.format = format;
55+
return this;
56+
}
57+
58+
@Override
59+
public boolean equals(Object o) {
60+
if (this == o) return true;
61+
if (!(o instanceof InputSticker)) return false;
62+
InputSticker that = (InputSticker) o;
63+
return Objects.equals(sticker, that.sticker)
64+
&& Arrays.equals(emoji_list, that.emoji_list)
65+
&& Objects.equals(mask_position, that.mask_position)
66+
&& Arrays.equals(keywords, that.keywords)
67+
&& Objects.equals(format, that.format)
68+
&& Objects.equals(attachName, that.attachName)
69+
&& Objects.equals(attach, that.attach);
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
int result = Objects.hash(sticker, mask_position, format, attachName, attach);
75+
result = 31 * result + Arrays.hashCode(emoji_list);
76+
result = 31 * result + Arrays.hashCode(keywords);
77+
return result;
78+
}
79+
80+
@Override
81+
public String toString() {
82+
return "InputSticker{" +
83+
"sticker='" + sticker + '\'' +
84+
", emoji_list=" + Arrays.toString(emoji_list) +
85+
", mask_position=" + mask_position +
86+
", keywords=" + Arrays.toString(keywords) +
87+
", format=" + format +
88+
", attachName='" + attachName + '\'' +
89+
", attach=" + attach +
90+
'}';
91+
}
4892
}

library/src/main/java/com/pengrad/telegrambot/request/CreateNewStickerSet.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ private CreateNewStickerSet(Long userId, String name, String title, String emoji
5757
add("emojis", emojis);
5858
}
5959

60+
public CreateNewStickerSet(Long userId, String name, String title, InputSticker[] stickers) {
61+
super(BaseResponse.class);
62+
add("user_id", userId);
63+
add("name", name);
64+
add("title", title);
65+
add("stickers", stickers);
66+
for (InputSticker sticker : stickers) {
67+
if (sticker.getAttachment() != null) {
68+
add(sticker.getAttachName(), sticker.getAttachment());
69+
}
70+
}
71+
}
72+
73+
/**
74+
* @deprecated StickerSets can contain both animated and non-animated stickers since Bot API 7.2 so Sticker Format argument was removed
75+
*/
76+
@Deprecated
6077
public CreateNewStickerSet(Long userId, String name, String title, InputSticker[] stickers, Format stickerFormat) {
6178
super(BaseResponse.class);
6279
add("user_id", userId);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.pengrad.telegrambot.request;
2+
3+
import com.pengrad.telegrambot.model.request.InputSticker;
4+
import com.pengrad.telegrambot.response.BaseResponse;
5+
6+
public class ReplaceStickerInSet extends BaseRequest<ReplaceStickerInSet, BaseResponse> {
7+
8+
public ReplaceStickerInSet(Long userId, String name, String oldSticker, InputSticker sticker) {
9+
super(BaseResponse.class);
10+
add("user_id", userId);
11+
add("name", name);
12+
add("old_sticker", oldSticker);
13+
add("sticker", sticker);
14+
}
15+
16+
}

library/src/main/java/com/pengrad/telegrambot/request/SetStickerSetThumbnail.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.pengrad.telegrambot.request;
22

3+
import com.pengrad.telegrambot.model.Sticker;
34
import com.pengrad.telegrambot.response.BaseResponse;
45

56
/**
@@ -8,14 +9,36 @@
89
*/
910
public class SetStickerSetThumbnail extends AbstractUploadRequest<AddStickerToSet, BaseResponse> {
1011

12+
/**
13+
* @deprecated Format parameter is required since Bot API 7.2
14+
*/
15+
@Deprecated
1116
public SetStickerSetThumbnail(String name, Long userId, Object thumbnail) {
1217
super(BaseResponse.class, "thumbnail", thumbnail);
1318
add("name", name);
1419
add("user_id", userId);
1520
}
1621

22+
/**
23+
* @deprecated Format parameter is required since Bot API 7.2
24+
*/
25+
@Deprecated
1726
public SetStickerSetThumbnail(String name, Long userId) {
1827
super(BaseResponse.class, "name", name);
1928
add("user_id", userId);
2029
}
30+
31+
public SetStickerSetThumbnail(String name, Long userId, Object thumbnail, Sticker.Format format) {
32+
super(BaseResponse.class, "thumbnail", thumbnail);
33+
add("name", name);
34+
add("user_id", userId);
35+
add("format", format);
36+
}
37+
38+
public SetStickerSetThumbnail(String name, Long userId, Sticker.Format format) {
39+
super(BaseResponse.class, "name", name);
40+
add("user_id", userId);
41+
add("format", format);
42+
}
43+
2144
}

0 commit comments

Comments
 (0)