Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #1458

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Dev #1458

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,20 @@ private long getUserIdSendError(String username, MessageContext ctx) {
}
}


private Optional<Message> send(String message, MessageContext ctx, String... args) {
return bot.silent.send(getLocalizedMessage(message, ctx.user().getLanguageCode(), args), ctx.chatId());
return bot.silent.send(getLocalizedMessage(message, ctx.user().getLanguageCode(), (Object[]) args), ctx.chatId());
}

private Optional<Message> sendMd(String message, MessageContext ctx, String... args) {
return bot.silent.sendMd(getLocalizedMessage(message, ctx.user().getLanguageCode(), args), ctx.chatId());
return bot.silent.sendMd(getLocalizedMessage(message, ctx.user().getLanguageCode(), (Object[]) args), ctx.chatId());
}

private Optional<Message> send(String message, Update upd) {
Long chatId = upd.getMessage().getChatId();
return bot.silent.send(getLocalizedMessage(message, AbilityUtils.getUser(upd).getLanguageCode()), chatId);
}

protected File downloadFileWithId(String fileId) throws TelegramApiException {
private File downloadFileWithId(String fileId) throws TelegramApiException {
return bot.telegramClient.downloadFile(bot.telegramClient.execute(GetFile.builder().fileId(fileId).build()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.telegram.telegrambots.client.okhttp;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.NonNull;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
Expand Down Expand Up @@ -50,7 +51,6 @@
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

public class OkHttpTelegramClient extends AbstractTelegramClient {
Expand All @@ -59,11 +59,11 @@ public class OkHttpTelegramClient extends AbstractTelegramClient {
private final TelegramUrl telegramUrl;
private final ObjectMapper objectMapper;

public OkHttpTelegramClient(ObjectMapper objectMapper, OkHttpClient client, String botToken, TelegramUrl telegramUrl) {
this.objectMapper = Objects.requireNonNull(objectMapper);
this.client = Objects.requireNonNull(client);
this.botToken = Objects.requireNonNull(botToken);
this.telegramUrl = Objects.requireNonNull(telegramUrl);
public OkHttpTelegramClient(@NonNull ObjectMapper objectMapper, @NonNull OkHttpClient client, @NonNull String botToken, @NonNull TelegramUrl telegramUrl) {
this.objectMapper = objectMapper;
this.client = client;
this.botToken = botToken;
this.telegramUrl = telegramUrl;
}

public OkHttpTelegramClient(OkHttpClient client, String botToken, TelegramUrl telegramUrl) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.telegram.telegrambots.extensions.bots.commandbot.commands.helpCommand;

import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand;
import org.telegram.telegrambots.extensions.bots.commandbot.commands.ICommandRegistry;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
Expand All @@ -17,6 +18,7 @@
* @version 1.0.0
*
*/
@Slf4j
public class HelpCommand extends ManCommand {

private static final String COMMAND_IDENTIFIER = "help";
Expand Down Expand Up @@ -100,14 +102,14 @@ public void execute(TelegramClient telegramClient, User user, Chat chat, String[
try {
telegramClient.execute(SendMessage.builder().chatId(chat.getId()).text(reply).parseMode("HTML").build());
} catch (TelegramApiException e) {
e.printStackTrace();
log.error(e.getLocalizedMessage(), e);
}
} else {
String reply = getHelpText(registry);
try {
telegramClient.execute(SendMessage.builder().chatId(chat.getId()).text(reply).parseMode("HTML").build());
} catch (TelegramApiException e) {
e.printStackTrace();
log.error(e.getLocalizedMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,4 @@ public OkHttpClient get() {
return okHttpClientBuilder.build();
}
}

/**
* @deprecated Use {@link HttpProxyOkHttpClientCreator} instead
*/
@Deprecated
public static class ProxyOkHttpClientCreator extends HttpProxyOkHttpClientCreator {
public ProxyOkHttpClientCreator(Supplier<Proxy> proxySupplier, Supplier<Authenticator> authenticatorSupplier) {
super(proxySupplier, authenticatorSupplier);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
@JacksonAnnotationsInside
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public @interface BotApiMethodJsonAnnotated {
public @interface BotApiJsonAnnotated {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.telegram.telegrambots.meta.api.interfaces;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.telegram.telegrambots.meta.annotations.BotApiJsonAnnotated;

import java.io.Serializable;

Expand All @@ -10,7 +9,6 @@
* @version 1.0
* An object from the Bots API received from Telegram Servers
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@BotApiJsonAnnotated
public interface BotApiObject extends Serializable {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -32,7 +31,6 @@
@AllArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class AnswerCallbackQuery extends BotApiMethodBoolean {
public static final String PATH = "answercallbackquery";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -32,7 +31,6 @@
@AllArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class AnswerInlineQuery extends BotApiMethodBoolean {
public static final String PATH = "answerInlineQuery";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -32,7 +31,6 @@
@AllArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class AnswerPreCheckoutQuery extends BotApiMethodBoolean {
public static final String PATH = "answerPreCheckoutQuery";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -35,7 +34,6 @@
@AllArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class AnswerShippingQuery extends BotApiMethodBoolean {
public static final String PATH = "answerShippingQuery";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -41,7 +40,6 @@
@AllArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class CopyMessage extends BotApiMethod<MessageId> {
public static final String PATH = "copyMessage";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -43,7 +42,6 @@
@AllArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class CopyMessages extends BotApiMethod<ArrayList<MessageId>> {
public static final String PATH = "copyMessages";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand All @@ -19,7 +18,6 @@
* @author Ruben Bermudez
* @version 1.0
* Use this method to forward messages of any kind.
*
* Service messages and messages with protected content can't be forwarded.
*
* On success, the Message sent is returned.
Expand All @@ -32,7 +30,6 @@
@AllArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class ForwardMessage extends BotApiMethodMessage {
public static final String PATH = "forwardmessage";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -39,7 +38,6 @@
@AllArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class ForwardMessages extends BotApiMethod<ArrayList<MessageId>> {
public static final String PATH = "forwardMessages";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down Expand Up @@ -32,7 +31,6 @@
@RequiredArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class GetFile extends BotApiMethod<File> {
public static final String PATH = "getFile";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -28,7 +27,6 @@
@AllArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class GetUserProfilePhotos extends BotApiMethod<UserProfilePhotos> {
public static final String PATH = "getuserprofilephotos";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down Expand Up @@ -31,7 +30,6 @@
@RequiredArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class SetPassportDataErrors extends BotApiMethodBoolean {
public static final String PATH = "setPassportDataErrors";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.telegram.telegrambots.meta.api.methods;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;

/**
* @author Ruben Bermudez
* @version 8.0
* Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the
* Mini App method requestEmojiStatusAccess.
*
* Returns True on success.
*/
@SuppressWarnings("unused")
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Jacksonized
public class SetUserEmojiStatus extends BotApiMethodBoolean {
public static final String PATH = "setUserEmojiStatus";

private static final String USER_ID_FIELD = "user_id";
private static final String EMOJI_STATUS_CUSTOM_EMOJI_ID_FIELD = "emoji_status_custom_emoji_id";
private static final String EMOJI_STATUS_EXPIRATION_DATE_FIELD = "emoji_status_expiration_date";


/**
* Unique identifier of the target user
*/
@JsonProperty(USER_ID_FIELD)
@NonNull
private Integer userId;
/**
* Optional
* Custom emoji identifier of the emoji status to set.
* Pass an empty string to remove the status.
*/
@JsonProperty(EMOJI_STATUS_CUSTOM_EMOJI_ID_FIELD)
private String emojiStatusCustomEmojiId;
/**
* Optional
* Expiration date of the emoji status, if any
*/
@JsonProperty(EMOJI_STATUS_EXPIRATION_DATE_FIELD)
private Integer emojiStatusExpirationDate;

@Override
public String getMethod() {
return PATH;
}

@Override
public void validate() throws TelegramApiValidationException {
if (userId == 0) {
throw new TelegramApiValidationException("UserId parameter can't be empty", this);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.telegram.telegrambots.meta.api.methods.botapimethods;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
Expand All @@ -13,8 +11,6 @@
*
* A method of Telegram Bots Api that is fully supported in json format
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SuperBuilder
public abstract class BotApiMethodBoolean extends BotApiMethod<Boolean> {
Expand Down
Loading