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

don't reuse exception #1397

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
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
Expand Up @@ -27,7 +27,6 @@
import java.io.InputStream;
import java.io.Serializable;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
* Abstract client implementation which delegates all synchronous methods to the async methods. Preferable for implementations
Expand Down Expand Up @@ -223,14 +222,6 @@ public InputStream downloadFileAsStream(File file) throws TelegramApiException {
}

private TelegramApiException mapException(Exception e, String method) {
if (e instanceof ExecutionException) {
if (e.getCause() instanceof TelegramApiException) {
return (TelegramApiException) e.getCause();
} else {
return new TelegramApiException("Unable to execute" + method + "method", e.getCause());
}
} else {
return new TelegramApiException("Unable to execute" + method + "method", e.getCause());
}
return new TelegramApiException("Unable to execute " + method + " method", e.getCause());
}
}
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
5 changes: 3 additions & 2 deletions telegrambots-longpolling/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
</distributionManagement>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
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
Loading