Skip to content

Commit

Permalink
Remove deprecated methods of AddStickerToSet, CreateNewStickerSet, Up…
Browse files Browse the repository at this point in the history
…loadStickerFile
  • Loading branch information
pengrad committed Apr 7, 2024
1 parent 977a08f commit 37bca93
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class StickerSet implements Serializable {
private String name;
private String title;
private Type sticker_type;
private Boolean is_animated;
private Boolean is_video;
private Boolean contains_masks;
private Sticker[] stickers;
private PhotoSize thumbnail;
Expand All @@ -40,7 +38,7 @@ public Type stickerType() {
*/
@Deprecated
public Boolean isAnimated() {
return is_animated;
return false;
}

/**
Expand Down Expand Up @@ -72,27 +70,20 @@ public PhotoSize thumb() {
*/
@Deprecated
public Boolean isVideo() {
return is_video;
return false;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StickerSet that = (StickerSet) o;
return Objects.equals(name, that.name) &&
Objects.equals(title, that.title) &&
Objects.equals(sticker_type, that.sticker_type) &&
Objects.equals(is_animated, that.is_animated) &&
Objects.equals(is_video, that.is_video) &&
Objects.equals(contains_masks, that.contains_masks) &&
Arrays.equals(stickers, that.stickers) &&
Objects.equals(thumbnail, that.thumbnail);
return Objects.equals(name, that.name) && Objects.equals(title, that.title) && sticker_type == that.sticker_type && Objects.equals(contains_masks, that.contains_masks) && Arrays.equals(stickers, that.stickers) && Objects.equals(thumbnail, that.thumbnail);
}

@Override
public int hashCode() {
int result = Objects.hash(name, title, sticker_type, is_animated, is_video, thumbnail);
int result = Objects.hash(name, title, sticker_type, contains_masks, thumbnail);
result = 31 * result + Arrays.hashCode(stickers);
return result;
}
Expand All @@ -102,9 +93,7 @@ public String toString() {
return "StickerSet{" +
"name='" + name + '\'' +
", title='" + title + '\'' +
", sticker_type='" + sticker_type + '\'' +
", is_animated=" + is_animated +
", is_video=" + is_video +
", sticker_type=" + sticker_type +
", contains_masks=" + contains_masks +
", stickers=" + Arrays.toString(stickers) +
", thumbnail=" + thumbnail +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.pengrad.telegrambot.model.request;

import com.google.gson.annotations.SerializedName;
import com.pengrad.telegrambot.AttachName;
import com.pengrad.telegrambot.model.MaskPosition;
import com.pengrad.telegrambot.model.Sticker;
Expand All @@ -21,7 +20,8 @@ public class InputSticker implements Serializable {
transient private String attachName;
transient private Object attach;

public InputSticker(Object sticker, String[] emojiList) {
public InputSticker(Object sticker, Sticker.Format format, String[] emojiList) {
this.format = format;
this.emoji_list = emojiList;
if (sticker instanceof String) {
this.sticker = (String) sticker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,6 @@
*/
public class AddStickerToSet extends AbstractUploadRequest<AddStickerToSet, BaseResponse> {

/**
* @deprecated Use constructor with the InputSticker type (since API v6.6)
*/
@Deprecated
public static AddStickerToSet tgsSticker(Long userId, String name, String emojis, Object tgsSticker) {
return new AddStickerToSet(userId, name, emojis, "tgs_sticker", tgsSticker);
}

/**
* @deprecated Use constructor with the InputSticker type (since API v6.6)
*/
@Deprecated
public static AddStickerToSet pngSticker(Long userId, String name, String emojis, Object pngSticker) {
return new AddStickerToSet(userId, name, emojis, "png_sticker", pngSticker);
}

/**
* @deprecated Use constructor with the InputSticker type (since API v6.6)
*/
@Deprecated
public static AddStickerToSet webmSticker(Long userId, String name, String emojis, Object webmSticker) {
return new AddStickerToSet(userId, name, emojis, "webm_sticker", webmSticker);
}

/**
* @deprecated Use static methods according to sticker set type - {@link #pngSticker(Long, String, String, Object) for png}, {@link #tgsSticker(Long, String, String, Object) for tgs} and {@link #webmSticker(Long, String, String, Object) for webm}
*/
@Deprecated
public AddStickerToSet(Long userId, String name, Object pngSticker, String emojis) {
this(userId, name, emojis, "png_sticker", pngSticker);
}

/**
* @deprecated Use constructor with the InputSticker type (since API v6.6)
*/
@Deprecated
private AddStickerToSet(Long userId, String name, String emojis, String stickerParam, Object sticker) {
super(BaseResponse.class, stickerParam, sticker);
add("user_id", userId);
add("name", name);
add("emojis", emojis);
}

public AddStickerToSet(Long userId, String name, InputSticker sticker) {
super(BaseResponse.class, attachName(sticker), attachment(sticker));
add("user_id", userId);
Expand All @@ -68,6 +25,10 @@ private static Object attachment(InputSticker sticker) {
return sticker.getAttachment() != null ? sticker.getAttachment() : "sticker_id";
}

/**
* @deprecated Use maskPosition on InputSticker (since API v6.6)
*/
@Deprecated
public AddStickerToSet maskPosition(MaskPosition maskPosition) {
return add("mask_position", maskPosition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,6 @@
*/
public class CreateNewStickerSet extends BaseRequest<CreateNewStickerSet, BaseResponse> {

/**
* @deprecated Use constructor with the InputSticker type (since API v6.6)
*/
@Deprecated
public static CreateNewStickerSet tgsSticker(Long userId, String name, String title, String emojis, Object tgsSticker) {
return new CreateNewStickerSet(userId, name, title, emojis, "tgs_sticker", tgsSticker);
}

/**
* @deprecated Use constructor with the InputSticker type (since API v6.6)
*/
@Deprecated
public static CreateNewStickerSet pngSticker(Long userId, String name, String title, String emojis, Object pngSticker) {
return new CreateNewStickerSet(userId, name, title, emojis, "png_sticker", pngSticker);
}

/**
* @deprecated Use constructor with the InputSticker type (since API v6.6)
*/
@Deprecated
public static CreateNewStickerSet webmSticker(Long userId, String name, String title, String emojis, Object webmSticker) {
return new CreateNewStickerSet(userId, name, title, emojis, "webm_sticker", webmSticker);
}

/**
* @deprecated Use static methods according to sticker set type - {@link #pngSticker(Long, String, String, String, Object) for png}, {@link #tgsSticker(Long, String, String, String, Object) for tgs} and {@link #webmSticker(Long, String, String, String, Object) for webm}
*/
@Deprecated
public CreateNewStickerSet(Long userId, String name, String title, Object pngSticker, String emojis) {
this(userId, name, title, emojis, "png_sticker", pngSticker);
}

/**
* @deprecated Use constructor with the InputSticker type (since API v6.6)
*/
@Deprecated
private CreateNewStickerSet(Long userId, String name, String title, String emojis, String stickerParam, Object sticker) {
super(BaseResponse.class);
add(stickerParam, sticker);
add("user_id", userId);
add("name", name);
add("title", title);
add("emojis", emojis);
}

public CreateNewStickerSet(Long userId, String name, String title, InputSticker[] stickers) {
super(BaseResponse.class);
add("user_id", userId);
Expand All @@ -75,40 +30,14 @@ public CreateNewStickerSet(Long userId, String name, String title, InputSticker[
*/
@Deprecated
public CreateNewStickerSet(Long userId, String name, String title, InputSticker[] stickers, Format stickerFormat) {
super(BaseResponse.class);
add("user_id", userId);
add("name", name);
add("title", title);
add("stickers", stickers);
add("sticker_format", stickerFormat.name().toLowerCase());
for (InputSticker sticker : stickers) {
if (sticker.getAttachment() != null) {
add(sticker.getAttachName(), sticker.getAttachment());
}
}
this(userId, name, title, stickers);
}

@Override
public boolean isMultipart() {
return true;
}

/**
* @deprecated Use stickerType(Type.mask) instead
*/
@Deprecated
public CreateNewStickerSet containsMasks(boolean containsMasks) {
return add("contains_masks", containsMasks);
}

/**
* @deprecated Invalid when the new constructor with InputSticker type is used (since API v6.6)
*/
@Deprecated
public CreateNewStickerSet maskPosition(MaskPosition maskPosition) {
return add("mask_position", maskPosition);
}


/**
* Type of stickers in the set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
*/
public class UploadStickerFile extends AbstractUploadRequest<UploadStickerFile, GetFileResponse> {

/**
* @deprecated Use constructor with the InputFile type (since API v6.6)
*/
@Deprecated
public UploadStickerFile(Long userId, Object pngSticker) {
super(GetFileResponse.class, "png_sticker", pngSticker);
add("user_id", userId);
}

/**
* @param stickerFormat must be one of “static”, “animated”, “video”.
*/
Expand Down
50 changes: 23 additions & 27 deletions library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1374,60 +1374,56 @@ public void getStickerSet() {
@Test
public void uploadStickerFile() throws IOException {
byte[] bytes = Files.readAllBytes(stickerFile.toPath());
GetFileResponse response = bot.execute(new UploadStickerFile(chatId, bytes));
GetFileResponse response = bot.execute(new UploadStickerFile(chatId, bytes, Sticker.Format.Static));
FileTest.check(response.file(), false);

response = bot.execute(new UploadStickerFile(chatId, bytes, Sticker.Format.Static));
FileTest.check(response.file(), false);
}

@Test
public void createNewPngStickerSet() {
public void createNewPngStickerSetAndAddSticker() {
String name = "test" + System.currentTimeMillis() + "_by_pengrad_test_bot";
String[] emojis = new String[]{"\uD83D\uDE00"};
InputSticker[] stickers = new InputSticker[]{new InputSticker(stickerFile, Sticker.Format.Static, emojis)};
BaseResponse response = bot.execute(
CreateNewStickerSet.pngSticker(chatId, name, "test1", "\uD83D\uDE00", stickerFile)
.stickerType(Sticker.Type.mask)
.maskPosition(new MaskPosition(MaskPosition.Point.forehead, 0f, 0f, 1f)));
new CreateNewStickerSet(chatId, name, "test1", stickers)
.stickerType(Sticker.Type.mask));
assertTrue(response.isOk());

response = bot.execute(new AddStickerToSet(chatId, name,
new InputSticker(stickerId, new String[]{"\uD83D\uDE00"}))
.maskPosition(new MaskPosition("eyes", 0f, 0f, 1f)));
new InputSticker(stickerId, Sticker.Format.Static, emojis)
.maskPosition(new MaskPosition("eyes", 0f, 0f, 1f))));
assertTrue(response.isOk());
}

@Test
public void createNewWebmStickerSetAndAddSticker() {
String setName = "test" + System.currentTimeMillis() + "_by_pengrad_test_bot";
String[] emojis = new String[]{"\uD83D\uDE00"};
InputSticker[] stickers = new InputSticker[]{new InputSticker(stickerFileVid, Sticker.Format.video, emojis)};
BaseResponse response = bot.execute(
CreateNewStickerSet.webmSticker(chatId, setName,
"test1", "\uD83D\uDE00", stickerFileVid)
.stickerType(Sticker.Type.mask)
.maskPosition(new MaskPosition(MaskPosition.Point.forehead, 0f, 0f, 1f)));
assertTrue(response.isOk());

response = bot.execute(
AddStickerToSet.webmSticker(chatId, setName, "\uD83D\uDE15", stickerFileVid));
new CreateNewStickerSet(chatId, setName, "test1", stickers)
.stickerType(Sticker.Type.regular)
);
assertTrue(response.isOk());
}

@Test
public void addStickerToSet() {
BaseResponse response = bot.execute(
AddStickerToSet.pngSticker(chatId, stickerSet, "\uD83D\uDE15", "BQADAgADuAAD7yupS4eB23UmZhGuAg")
.maskPosition(new MaskPosition("eyes", 0f, 0f, 1f)));
new AddStickerToSet(chatId, stickerSet,
new InputSticker("BQADAgADuAAD7yupS4eB23UmZhGuAg", Sticker.Format.Static, new String[]{"\uD83D\uDE15"})
.maskPosition(new MaskPosition("eyes", 0f, 0f, 1f))));
assertTrue(response.isOk());
}

@Test
public void createSetAndAddStickerTgs() {
String setName = "test" + System.currentTimeMillis() + "_by_pengrad_test_bot";
InputSticker[] stickers = new InputSticker[]{new InputSticker(stickerFileAnim, Sticker.Format.animated, new String[]{"\uD83D\uDE00"})};
BaseResponse response = bot.execute(
CreateNewStickerSet.tgsSticker(chatId, setName, "test1", "\uD83D\uDE00", stickerFileAnim));
assertTrue(response.isOk());

response = bot.execute(
AddStickerToSet.tgsSticker(chatId, setName, "\uD83D\uDE15", stickerFileAnim));
new CreateNewStickerSet(chatId, setName, "test1", stickers));
assertTrue(response.isOk());
}

Expand All @@ -1437,11 +1433,10 @@ public void createNewStickerSet() {
String title = "test112312312";
BaseResponse response = bot.execute(
new CreateNewStickerSet(chatId, setName, title, new InputSticker[]{
new InputSticker(stickerFile, new String[]{"\uD83D\uDE00"})
new InputSticker(stickerFile, Sticker.Format.Static, new String[]{"\uD83D\uDE00"})
.keywords(new String[]{"yes", "no"})
.maskPosition(new MaskPosition(MaskPosition.Point.forehead, 10f, 20f, 1f))
}, Sticker.Format.Static)
.containsMasks(false)
.needsRepainting(false));
assertTrue(response.isOk());

Expand Down Expand Up @@ -1487,7 +1482,8 @@ public void setStickerPositionInSet() {

@Test
public void deleteStickerFromSet() {
BaseResponse response = bot.execute(AddStickerToSet.pngSticker(chatId, stickerSet, "\uD83D\uDE15", stickerFile));
InputSticker inputSticker = new InputSticker("BQADAgADuAAD7yupS4eB23UmZhGuAg", Sticker.Format.Static, new String[]{"\uD83D\uDE15"});
BaseResponse response = bot.execute(new AddStickerToSet(chatId, stickerSet, inputSticker));
assertTrue(response.isOk());

GetStickerSetResponse setResponse = bot.execute(new GetStickerSet(stickerSet));
Expand All @@ -1511,7 +1507,7 @@ public void setStickerSetThumb() {
assertTrue(response.isOk());

StickerSet set = bot.execute(new GetStickerSet(stickerSetAnim)).stickerSet();
assertTrue(set.isAnimated());
assertFalse(set.isAnimated());
PhotoSize thumb = set.thumb();
PhotoSizeTest.checkPhotos(thumb);
assertEquals(Integer.valueOf(100), thumb.width());
Expand All @@ -1538,7 +1534,7 @@ public void setCustomEmojiStickerSetThumbnail() {
String setName = "custom_emoji_set_by_pengrad_test_bot";
BaseResponse response = bot.execute(
new CreateNewStickerSet(chatId, setName, "title",
new InputSticker[]{new InputSticker(stickerFileAnim, new String[]{"\uD83D\uDE15"})},
new InputSticker[]{new InputSticker(stickerFileAnim, Sticker.Format.animated, new String[]{"\uD83D\uDE15"})},
Sticker.Format.animated
).stickerType(Sticker.Type.custom_emoji)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void checkTextMessage(Message message) {
assertNull(message.messageThreadId());
assertFalse(message.isTopicMessage());
assertNull(message.isAutomaticForward());
assertNull(message.hasMediaSpoiler());
assertFalse(message.hasMediaSpoiler());
assertNull(message.messageAutoDeleteTimerChanged());
assertNull(message.chatShared());
assertNull(message.proximityAlertTriggered());
Expand Down

0 comments on commit 37bca93

Please sign in to comment.