Skip to content

Commit

Permalink
Add new bot methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aNNiMON committed Aug 20, 2023
1 parent b317877 commit 2d35c6b
Show file tree
Hide file tree
Showing 28 changed files with 652 additions and 512 deletions.
2 changes: 1 addition & 1 deletion module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.annimon'
version '6.5.1-SNAPSHOT'
version '6.8.0-SNAPSHOT'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

sourceCompatibility = 11
Expand Down
127 changes: 86 additions & 41 deletions module/src/main/java/com/annimon/tgbotsmodule/api/methods/Methods.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.media.InputMedia;
import org.telegram.telegrambots.meta.api.objects.passport.dataerror.PassportElementError;
import org.telegram.telegrambots.meta.api.objects.stickers.InputSticker;

@SuppressWarnings("unused")
public final class Methods {
Expand Down Expand Up @@ -482,6 +483,19 @@ public static UnpinAllForumTopicMessagesMethod unpinAllForumTopicMessages(@NotNu
public static UnpinAllForumTopicMessagesMethod unpinAllForumTopicMessages(long chatId) {
return new UnpinAllForumTopicMessagesMethod().setChatId(chatId);
}


public static UnpinAllGeneralForumTopicMessagesMethod unpinAllGeneralForumTopicMessages() {
return new UnpinAllGeneralForumTopicMessagesMethod();
}

public static UnpinAllGeneralForumTopicMessagesMethod unpinAllGeneralForumTopicMessages(@NotNull String chatId) {
return unpinAllGeneralForumTopicMessages().setChatId(chatId);
}

public static UnpinAllGeneralForumTopicMessagesMethod unpinAllGeneralForumTopicMessages(long chatId) {
return unpinAllGeneralForumTopicMessages().setChatId(chatId);
}
}

public static class Games {
Expand Down Expand Up @@ -601,24 +615,8 @@ public static AddStickerToSetMethod addStickerToSet() {
return new AddStickerToSetMethod();
}

public static AddStickerToSetMethod addStickerToSet(long userId, @NotNull String name, @NotNull String emojis) {
return new AddStickerToSetMethod().setUserId(userId).setName(name).setEmojis(emojis);
}

public static AddAnimatedStickerToSetMethod addAnimatedStickerToSet() {
return new AddAnimatedStickerToSetMethod();
}

public static AddAnimatedStickerToSetMethod addAnimatedStickerToSet(long userId, @NotNull String name, @NotNull String emojis) {
return new AddAnimatedStickerToSetMethod().setUserId(userId).setName(name).setEmojis(emojis);
}

public static AddWebmStickerToSetMethod addWebmStickerToSet() {
return new AddWebmStickerToSetMethod();
}

public static AddWebmStickerToSetMethod addWebmStickerToSet(long userId, @NotNull String name, @NotNull String emojis) {
return new AddWebmStickerToSetMethod().setUserId(userId).setName(name).setEmojis(emojis);
public static AddStickerToSetMethod addStickerToSet(long userId, @NotNull String name, @NotNull InputSticker sticker) {
return new AddStickerToSetMethod().setUserId(userId).setName(name).setSticker(sticker);
}


Expand All @@ -627,29 +625,8 @@ public static CreateNewStickerSetMethod createNewStickerSet() {
}

public static CreateNewStickerSetMethod createNewStickerSet(
long userId, @NotNull String name,
@NotNull String title, @NotNull String emojis) {
return new CreateNewStickerSetMethod().setUserId(userId).setName(name).setTitle(title).setEmojis(emojis);
}

public static CreateNewAnimatedStickerSetMethod createNewAnimatedStickerSet() {
return new CreateNewAnimatedStickerSetMethod();
}

public static CreateNewAnimatedStickerSetMethod createNewAnimatedStickerSet(
long userId, @NotNull String name,
@NotNull String title, @NotNull String emojis) {
return new CreateNewAnimatedStickerSetMethod().setUserId(userId).setName(name).setTitle(title).setEmojis(emojis);
}

public static CreateNewWebmStickerSetMethod createNewWebmStickerSet() {
return new CreateNewWebmStickerSetMethod();
}

public static CreateNewWebmStickerSetMethod createNewWebmStickerSet(
long userId, @NotNull String name,
@NotNull String title, @NotNull String emojis) {
return new CreateNewWebmStickerSetMethod().setUserId(userId).setName(name).setTitle(title).setEmojis(emojis);
long userId, @NotNull String name, @NotNull String title) {
return new CreateNewStickerSetMethod().setUserId(userId).setName(name).setTitle(title);
}


Expand Down Expand Up @@ -709,6 +686,11 @@ public static UploadStickerFileMethod uploadStickerFile() {
public static UploadStickerFileMethod uploadStickerFile(long userId) {
return new UploadStickerFileMethod().setUserId(userId);
}


public static SetCustomEmojiStickerSetThumbnailMethod setCustomEmojiStickerSetThumbnail() {
return new SetCustomEmojiStickerSetThumbnailMethod();
}
}

public static class Updates {
Expand Down Expand Up @@ -798,6 +780,69 @@ public static GetMeMethod getMe() {
}


public static GetMyNameMethod getMyName() {
return new GetMyNameMethod();
}

public static GetMyNameMethod getMyName(@NotNull String languageCode) {
return new GetMyNameMethod().setLanguageCode(languageCode);
}

public static SetMyNameMethod setMyName() {
return new SetMyNameMethod();
}

public static SetMyNameMethod setMyName(@NotNull String name) {
return new SetMyNameMethod().setName(name);
}

public static SetMyNameMethod setMyName(@NotNull String name, @NotNull String languageCode) {
return new SetMyNameMethod().setName(name).setLanguageCode(languageCode);
}


public static GetMyDescriptionMethod getMyDescription() {
return new GetMyDescriptionMethod();
}

public static GetMyDescriptionMethod getMyDescription(@NotNull String languageCode) {
return new GetMyDescriptionMethod().setLanguageCode(languageCode);
}

public static SetMyDescriptionMethod setMyDescription() {
return new SetMyDescriptionMethod();
}

public static SetMyDescriptionMethod setMyDescription(@NotNull String description) {
return new SetMyDescriptionMethod().setDescription(description);
}

public static SetMyDescriptionMethod setMyDescription(@NotNull String description, @NotNull String languageCode) {
return new SetMyDescriptionMethod().setDescription(description).setLanguageCode(languageCode);
}


public static GetMyShortDescriptionMethod getMyShortDescription() {
return new GetMyShortDescriptionMethod();
}

public static GetMyShortDescriptionMethod getMyShortDescription(@NotNull String languageCode) {
return new GetMyShortDescriptionMethod().setLanguageCode(languageCode);
}

public static SetMyShortDescriptionMethod setMyShortDescription() {
return new SetMyShortDescriptionMethod();
}

public static SetMyShortDescriptionMethod setMyShortDescription(@NotNull String shortDescription) {
return new SetMyShortDescriptionMethod().setShortDescription(shortDescription);
}

public static SetMyShortDescriptionMethod setMyShortDescription(@NotNull String shortDescription, @NotNull String languageCode) {
return new SetMyShortDescriptionMethod().setShortDescription(shortDescription).setLanguageCode(languageCode);
}


public static GetUserProfilePhotosMethod getUserProfilePhotos() {
return new GetUserProfilePhotosMethod();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.jetbrains.annotations.Nullable;
import org.telegram.telegrambots.meta.api.methods.AnswerInlineQuery;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResultsButton;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

public class AnswerInlineQueryMethod implements Method<Boolean> {
Expand Down Expand Up @@ -58,24 +59,49 @@ public AnswerInlineQueryMethod setPersonal(Boolean isPersonal) {
return this;
}

/**
* @deprecated Use {@link #getButton()}
*/
@Deprecated
public String getSwitchPmText() {
return method.getSwitchPmText();
}

/**
* @deprecated Use {@link #setButton(InlineQueryResultsButton)}
*/
@Deprecated
public AnswerInlineQueryMethod setSwitchPmText(String switchPmText) {
method.setSwitchPmText(switchPmText);
return this;
}

/**
* @deprecated Use {@link #getButton()}
*/
@Deprecated
public String getSwitchPmParameter() {
return method.getSwitchPmParameter();
}

/**
* @deprecated Use {@link #setButton(InlineQueryResultsButton)}
*/
@Deprecated
public AnswerInlineQueryMethod setSwitchPmParameter(String switchPmParameter) {
method.setSwitchPmParameter(switchPmParameter);
return this;
}

public InlineQueryResultsButton getButton() {
return method.getButton();
}

public AnswerInlineQueryMethod setButton(@Nullable InlineQueryResultsButton button) {
method.setButton(button);
return this;
}

public List<InlineQueryResult> getResults() {
return method.getResults();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.annimon.tgbotsmodule.api.methods.forum;

import com.annimon.tgbotsmodule.api.methods.interfaces.ChatMethod;
import com.annimon.tgbotsmodule.services.CommonAbsSender;
import java.util.function.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.telegram.telegrambots.meta.api.methods.forum.UnpinAllGeneralForumTopicMessages;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

public class UnpinAllGeneralForumTopicMessagesMethod implements ChatMethod<UnpinAllGeneralForumTopicMessagesMethod, Boolean> {

private final UnpinAllGeneralForumTopicMessages method;

public UnpinAllGeneralForumTopicMessagesMethod() {
this(new UnpinAllGeneralForumTopicMessages());
}

public UnpinAllGeneralForumTopicMessagesMethod(@NotNull UnpinAllGeneralForumTopicMessages method) {
this.method = method;
}

@Override
public String getChatId() {
return method.getChatId();
}

@Override
public UnpinAllGeneralForumTopicMessagesMethod setChatId(@NotNull String chatId) {
method.setChatId(chatId);
return this;
}

@Override
public Boolean call(@NotNull CommonAbsSender sender) {
return sender.call(method);
}

@Override
public void callAsync(@NotNull CommonAbsSender sender,
@Nullable Consumer<? super Boolean> responseConsumer,
@Nullable Consumer<TelegramApiException> apiExceptionConsumer,
@Nullable Consumer<Exception> exceptionConsumer) {
sender.callAsync(method, responseConsumer, apiExceptionConsumer, exceptionConsumer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.annimon.tgbotsmodule.api.methods.info;

import com.annimon.tgbotsmodule.api.methods.interfaces.Method;
import com.annimon.tgbotsmodule.services.CommonAbsSender;
import java.util.function.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.telegram.telegrambots.meta.api.methods.description.GetMyDescription;
import org.telegram.telegrambots.meta.api.objects.description.BotDescription;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

public class GetMyDescriptionMethod implements Method<BotDescription> {

private final GetMyDescription method;

public GetMyDescriptionMethod() {
this(new GetMyDescription());
}

public GetMyDescriptionMethod(@NotNull GetMyDescription method) {
this.method = method;
}

public String getLanguageCode() {
return method.getLanguageCode();
}

public GetMyDescriptionMethod setLanguageCode(@NotNull String languageCode) {
method.setLanguageCode(languageCode);
return this;
}

@Override
public BotDescription call(@NotNull CommonAbsSender sender) {
return sender.call(method);
}

@Override
public void callAsync(@NotNull CommonAbsSender sender,
@Nullable Consumer<? super BotDescription> responseConsumer,
@Nullable Consumer<TelegramApiException> apiExceptionConsumer,
@Nullable Consumer<Exception> exceptionConsumer) {
sender.callAsync(method, responseConsumer, apiExceptionConsumer, exceptionConsumer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.annimon.tgbotsmodule.api.methods.info;

import com.annimon.tgbotsmodule.api.methods.interfaces.Method;
import com.annimon.tgbotsmodule.services.CommonAbsSender;
import java.util.function.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.telegram.telegrambots.meta.api.methods.name.GetMyName;
import org.telegram.telegrambots.meta.api.objects.name.BotName;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

public class GetMyNameMethod implements Method<BotName> {

private final GetMyName method;

public GetMyNameMethod() {
this(new GetMyName() {
@Override
public String getMethod() {
return "getMyName"; // TODO: remove when will be fixed in telegrambots
}
});
}

public GetMyNameMethod(@NotNull GetMyName method) {
this.method = method;
}

public String getLanguageCode() {
return method.getLanguageCode();
}

public GetMyNameMethod setLanguageCode(@NotNull String languageCode) {
method.setLanguageCode(languageCode);
return this;
}

@Override
public BotName call(@NotNull CommonAbsSender sender) {
return sender.call(method);
}

@Override
public void callAsync(@NotNull CommonAbsSender sender,
@Nullable Consumer<? super BotName> responseConsumer,
@Nullable Consumer<TelegramApiException> apiExceptionConsumer,
@Nullable Consumer<Exception> exceptionConsumer) {
sender.callAsync(method, responseConsumer, apiExceptionConsumer, exceptionConsumer);
}
}
Loading

0 comments on commit 2d35c6b

Please sign in to comment.