Skip to content

Commit

Permalink
Update 5.0 and lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenlagus committed Nov 3, 2020
1 parent 3275c10 commit 447c9d3
Show file tree
Hide file tree
Showing 213 changed files with 4,729 additions and 10,398 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</dependency>
```

```gradle
compile "org.telegram:telegrambots:4.9.2"
compile "org.telegram:telegrambots:5.0.0"
```

2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.9.2)
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.9.2)
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.0.0)
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.0.0)

In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

Expand Down
9 changes: 9 additions & 0 deletions TelegramBots.wiki/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### <a id="5.0.0"></a>5.0.0 ###
1. Update Api version [5.0](https://core.telegram.org/bots/api-changelog#june-4-2020)
2. Added Builders for many of the API methods and objects
3. Some setters/getters may have change name. They no longer return a refence to itself, use Builder for that.
4. Simplified methods to set files in methods. Only InputFile is available now (this class contains constructors for all the cases)
5. Locations now use Double instead of Float to avoid rounding.
6. When registering a Webhook Bot, a SetWebhook object must be provided.
7. When using Webhook with Spring, extends class SpringWebhookBot instead of WebhookBot

### <a id="4.9.2"></a>4.9.2 ###
1. Bug fixing: #792, #801, #804, #810, #812, #813, #820 and #814

Expand Down
4 changes: 2 additions & 2 deletions TelegramBots.wiki/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</dependency>
```
* With **Gradle**:

```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '4.9.2'
compile group: 'org.telegram', name: 'telegrambots', version: '5.0.0'
```

2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
Expand Down
4 changes: 2 additions & 2 deletions TelegramBots.wiki/abilities/Simple-Example.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</dependency>
```
* **Gradle**
```groovy
implementation group: 'org.telegram', name: 'telegrambots-abilities', version: '4.9.2'
implementation group: 'org.telegram', name: 'telegrambots-abilities', version: '5.0.0'
```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)

Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>4.9.2</version>
<version>5.0.0</version>

<modules>
<module>telegrambots</module>
Expand Down Expand Up @@ -67,12 +67,12 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

<junit.version>5.6.2</junit.version>
<mockito.version>3.1.0</mockito.version>
<mockitojupiter.version>3.1.0</mockitojupiter.version>
<jacksonbase.version>2.10.1</jacksonbase.version>
<jackson.version>2.10.1</jackson.version>
<slf4j.version>1.7.29</slf4j.version>
<junit.version>5.7.0</junit.version>
<mockito.version>3.6.0</mockito.version>
<mockitojupiter.version>3.6.0</mockitojupiter.version>
<jacksonbase.version>2.11.3</jacksonbase.version>
<jackson.version>2.11.3</jackson.version>
<slf4j.version>1.7.30</slf4j.version>
<jakarta.annotation.version>1.3.5</jakarta.annotation.version>
<lombok.version>1.18.16</lombok.version>
</properties>
Expand Down
8 changes: 4 additions & 4 deletions telegrambots-abilities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</dependency>
```

**Gradle**

```gradle
compile "org.telegram:telegrambots-abilities:4.9.2"
compile "org.telegram:telegrambots-abilities:5.0.0"
```

**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.9.2)
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.0)

**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.9.2)
**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v5.0.0)

Motivation
----------
Expand Down
8 changes: 4 additions & 4 deletions telegrambots-abilities/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</parent>

<artifactId>telegrambots-abilities</artifactId>
Expand Down Expand Up @@ -76,15 +76,15 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<commonslang.version>3.9</commonslang.version>
<mapdb.version>3.0.7</mapdb.version>
<commonslang.version>3.11</commonslang.version>
<mapdb.version>3.0.8</mapdb.version>
</properties>

<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import org.telegram.abilitybots.api.db.DBContext;
import org.telegram.abilitybots.api.toggle.AbilityToggle;
import org.telegram.abilitybots.api.toggle.DefaultToggle;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramWebhookBot;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.generics.WebhookBot;
import org.telegram.telegrambots.util.WebhookUtils;

Expand Down Expand Up @@ -63,8 +64,8 @@ public BotApiMethod onWebhookUpdateReceived(Update update) {
}

@Override
public void setWebhook(String url, String publicCertificatePath) throws TelegramApiRequestException {
WebhookUtils.setWebhook(this, url, publicCertificatePath);
public void setWebhook(SetWebhook setWebhook) throws TelegramApiException {
WebhookUtils.setWebhook(this, setWebhook);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public boolean isGroupAdmin(Update update, int id) {
}

public boolean isGroupAdmin(long chatId, int id) {
GetChatAdministrators admins = new GetChatAdministrators().setChatId(chatId);
GetChatAdministrators admins = GetChatAdministrators.builder().chatId(Long.toString(chatId)).build();
return silent.execute(admins)
.orElse(new ArrayList<>()).stream()
.anyMatch(member -> member.getUser().getId() == id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.telegram.abilitybots.api.util.Pair;
import org.telegram.telegrambots.meta.api.methods.GetFile;
import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
Expand Down Expand Up @@ -221,9 +222,10 @@ public Ability backupDB() {

try (PrintStream printStream = new PrintStream(backup)) {
printStream.print(bot.db.backup());
bot.sender.sendDocument(new SendDocument()
.setDocument(backup)
.setChatId(ctx.chatId())
bot.sender.sendDocument(SendDocument.builder()
.document(new InputFile(backup))
.chatId(ctx.chatId().toString())
.build()
);
} catch (FileNotFoundException e) {
log.error("Error while fetching backup", e);
Expand Down Expand Up @@ -472,6 +474,6 @@ private Optional<Message> send(String message, Update upd) {
}

protected File downloadFileWithId(String fileId) throws TelegramApiException {
return bot.sender.downloadFile(bot.sender.execute(new GetFile().setFileId(fileId)));
return bot.sender.downloadFile(bot.sender.execute(GetFile.builder().fileId(fileId).build()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Optional<Message> sendMd(String message, long id) {
public Optional<Message> forceReply(String message, long id) {
SendMessage msg = new SendMessage();
msg.setText(message);
msg.setChatId(id);
msg.setChatId(Long.toString(id));
msg.setReplyMarkup(new ForceReplyKeyboard());

return execute(msg);
Expand All @@ -64,7 +64,7 @@ public <T extends Serializable, Method extends BotApiMethod<T>> Optional<T> exec

private Optional<Message> doSendMessage(String txt, long groupId, boolean format) {
SendMessage smsg = new SendMessage();
smsg.setChatId(groupId);
smsg.setChatId(Long.toString(groupId));
smsg.setText(txt);
smsg.enableMarkdown(format);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ private Update mockBackupUpdate() {
Message botMessage = mock(Message.class);
Document document = mock(Document.class);

when(document.getFileId()).thenReturn("FAKEFILEID");
when(message.getFrom()).thenReturn(CREATOR);
when(update.getMessage()).thenReturn(message);
when(message.getDocument()).thenReturn(document);
Expand Down
2 changes: 1 addition & 1 deletion telegrambots-chat-session-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-chat-session-bot</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions telegrambots-chat-session-bot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</parent>

<artifactId>telegrambots-chat-session-bot</artifactId>
Expand Down Expand Up @@ -76,15 +76,15 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<shiro.version>1.4.2</shiro.version>
<shiro.version>1.7.0</shiro.version>
</properties>

<dependencies>

<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</dependency>
```

2. Using Gradle:

```gradle
compile "org.telegram:telegrambotsextensions:4.9.2"
compile "org.telegram:telegrambotsextensions:5.0.0"
```
4 changes: 2 additions & 2 deletions telegrambots-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</parent>

<artifactId>telegrambotsextensions</artifactId>
Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public void execute(AbsSender absSender, User user, Chat chat, String[] argument
IBotCommand command = registry.getRegisteredCommand(arguments[0]);
String reply = getManText(command);
try {
absSender.execute(new SendMessage(chat.getId(), reply).setParseMode("HTML"));
absSender.execute(SendMessage.builder().chatId(chat.getId().toString()).text(reply).parseMode("HTML").build());
} catch (TelegramApiException e) {
e.printStackTrace();
}
} else {
String reply = getHelpText(registry);
try {
absSender.execute(new SendMessage(chat.getId(), reply).setParseMode("HTML"));
absSender.execute(SendMessage.builder().chatId(chat.getId().toString()).text(reply).parseMode("HTML").build());
} catch (TelegramApiException e) {
e.printStackTrace();
}
Expand Down
6 changes: 3 additions & 3 deletions telegrambots-meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.9.2</version>
<version>5.0.0</version>
</parent>

<artifactId>telegrambots-meta</artifactId>
Expand Down Expand Up @@ -70,8 +70,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<guice.version>4.2.3</guice.version>
<jackson.version>2.10.1</jackson.version>
<jacksonanotation.version>2.10.1</jacksonanotation.version>
<jackson.version>2.11.3</jackson.version>
<jacksonanotation.version>2.11.3</jacksonanotation.version>
<json.version>20180813</json.version>
<guava.version>30.0-jre</guava.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.telegram.telegrambots.meta;

import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.generics.BotSession;
import org.telegram.telegrambots.meta.generics.LongPollingBot;
Expand All @@ -11,8 +13,7 @@
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Bots manager
* @date 14 of January of 2016
* Bots manager
*/
public class TelegramBotsApi {
private static final String webhookUrlFormat = "{0}callback/";
Expand Down Expand Up @@ -130,12 +131,13 @@ public BotSession registerBot(LongPollingBot bot) throws TelegramApiRequestExcep
/**
* Register a bot in the api that will receive updates using webhook method
* @param bot Bot to register
* @param setWebhook Set webhook request to initialize the bot
*/
public void registerBot(WebhookBot bot) throws TelegramApiRequestException {
public void registerBot(WebhookBot bot, SetWebhook setWebhook) throws TelegramApiException {
if (useWebhook) {
bot.onRegister();
webhook.registerWebhook(bot);
bot.setWebhook(externalUrl + bot.getBotPath(), pathToCertificate);
bot.setWebhook(setWebhook);
}
}

Expand Down
Loading

0 comments on commit 447c9d3

Please sign in to comment.