Skip to content

Commit

Permalink
Implement mixed-format sticker packs & add ReplaceStickerInSet method
Browse files Browse the repository at this point in the history
  • Loading branch information
anfanik committed Apr 5, 2024
1 parent 12697dc commit 1345898
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public Type stickerType() {
return sticker_type;
}

/**
* @deprecated StickerSets can contain both animated and non-animated stickers since Bot API 7.2
*/
@Deprecated
public Boolean isAnimated() {
return is_animated;
}
Expand Down Expand Up @@ -63,6 +67,10 @@ public PhotoSize thumb() {
return thumbnail();
}

/**
* @deprecated StickerSets can contain both animated and non-animated stickers since Bot API 7.2
*/
@Deprecated
public Boolean isVideo() {
return is_video;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
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;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Objects;

public class InputSticker implements Serializable {

Expand All @@ -13,6 +17,7 @@ public class InputSticker implements Serializable {
private String[] emoji_list;
private MaskPosition mask_position;
private String[] keywords;
private Sticker.Format format;
transient private String attachName;
transient private Object attach;

Expand Down Expand Up @@ -45,4 +50,43 @@ public InputSticker keywords(String[] keywords) {
return this;
}

public InputSticker format(Sticker.Format format) {
this.format = format;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof InputSticker)) return false;
InputSticker that = (InputSticker) o;
return Objects.equals(sticker, that.sticker)
&& Arrays.equals(emoji_list, that.emoji_list)
&& Objects.equals(mask_position, that.mask_position)
&& Arrays.equals(keywords, that.keywords)
&& Objects.equals(format, that.format)
&& Objects.equals(attachName, that.attachName)
&& Objects.equals(attach, that.attach);
}

@Override
public int hashCode() {
int result = Objects.hash(sticker, mask_position, format, attachName, attach);
result = 31 * result + Arrays.hashCode(emoji_list);
result = 31 * result + Arrays.hashCode(keywords);
return result;
}

@Override
public String toString() {
return "InputSticker{" +
"sticker='" + sticker + '\'' +
", emoji_list=" + Arrays.toString(emoji_list) +
", mask_position=" + mask_position +
", keywords=" + Arrays.toString(keywords) +
", format=" + format +
", attachName='" + attachName + '\'' +
", attach=" + attach +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ private CreateNewStickerSet(Long userId, String name, String title, String emoji
add("emojis", emojis);
}

public CreateNewStickerSet(Long userId, String name, String title, InputSticker[] stickers) {
super(BaseResponse.class);
add("user_id", userId);
add("name", name);
add("title", title);
add("stickers", stickers);
for (InputSticker sticker : stickers) {
if (sticker.getAttachment() != null) {
add(sticker.getAttachName(), sticker.getAttachment());
}
}
}

/**
* @deprecated StickerSets can contain both animated and non-animated stickers since Bot API 7.2 so Sticker Format argument was removed
*/
@Deprecated
public CreateNewStickerSet(Long userId, String name, String title, InputSticker[] stickers, Format stickerFormat) {
super(BaseResponse.class);
add("user_id", userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pengrad.telegrambot.request;

import com.pengrad.telegrambot.model.request.InputSticker;
import com.pengrad.telegrambot.response.BaseResponse;

public class ReplaceStickerInSet extends BaseRequest<ReplaceStickerInSet, BaseResponse> {

public ReplaceStickerInSet(Long userId, String name, String oldSticker, InputSticker sticker) {
super(BaseResponse.class);
add("user_id", userId);
add("name", name);
add("old_sticker", oldSticker);
add("sticker", sticker);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pengrad.telegrambot.request;

import com.pengrad.telegrambot.model.Sticker;
import com.pengrad.telegrambot.response.BaseResponse;

/**
Expand All @@ -8,14 +9,36 @@
*/
public class SetStickerSetThumbnail extends AbstractUploadRequest<AddStickerToSet, BaseResponse> {

/**
* @deprecated Format parameter is required since Bot API 7.2
*/
@Deprecated
public SetStickerSetThumbnail(String name, Long userId, Object thumbnail) {
super(BaseResponse.class, "thumbnail", thumbnail);
add("name", name);
add("user_id", userId);
}

/**
* @deprecated Format parameter is required since Bot API 7.2
*/
@Deprecated
public SetStickerSetThumbnail(String name, Long userId) {
super(BaseResponse.class, "name", name);
add("user_id", userId);
}

public SetStickerSetThumbnail(String name, Long userId, Object thumbnail, Sticker.Format format) {
super(BaseResponse.class, "thumbnail", thumbnail);
add("name", name);
add("user_id", userId);
add("format", format);
}

public SetStickerSetThumbnail(String name, Long userId, Sticker.Format format) {
super(BaseResponse.class, "name", name);
add("user_id", userId);
add("format", format);
}

}

0 comments on commit 1345898

Please sign in to comment.