Skip to content

Commit

Permalink
Merge pull request #938 from rubenlagus/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rubenlagus committed Jul 4, 2021
2 parents 02fdbec + c8d4619 commit 247274a
Show file tree
Hide file tree
Showing 67 changed files with 2,201 additions and 212 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -27,18 +27,18 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</dependency>
```

2. Using Gradle:

```gradle
implementation 'org.telegram:telegrambots:5.2.0'
implementation 'org.telegram:telegrambots:5.3.0'
```

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

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

Expand Down
9 changes: 8 additions & 1 deletion TelegramBots.wiki/Changelog.md
@@ -1,5 +1,12 @@
### <a id="5.3.0"></a>5.3.0 ###
1. Update Api version [5.3](https://core.telegram.org/bots/api-changelog#june-25-2021)
2. `KeyboardRow` now support creation from a collection of buttons.
3. Bug fixing: #920, #931 and #937

**[[How to update to version 5.3.0|How-To-Update#5.3.0]]**

### <a id="5.2.0"></a>5.2.0 ###
1. Update Api version [5.2](https://core.telegram.org/bots/api#april-26-2021)
1. Update Api version [5.2](https://core.telegram.org/bots/api-changelog#april-26-2021)
2. Allow custom BackOff implementations
3. Spring version 2.4.5 in spring module
4. Bug fixing: #869, #888 and #892
Expand Down
40 changes: 40 additions & 0 deletions TelegramBots.wiki/FAQ.md
Expand Up @@ -225,6 +225,46 @@ Custom keyboards can be appended to messages using the `setReplyMarkup`. In this
}
```

[InlineKeyboardMarkup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) use list to capture the buttons instead of KeyboardRow.

```java
public void sendInlineKeyboard(String chatId) {
SendMessage message = new SendMessage();
message.setChatId(chatId);
message.setText("Inline model below.");

// Create InlineKeyboardMarkup object
InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup();
// Create the keyboard (list of InlineKeyboardButton list)
List<List<InlineKeyboardButton>> keyboard = new ArrayList<>();
// Create a list for buttons
List<InlineKeyboardButton> Buttons = new ArrayList<InlineKeyboardButton>();
// Initialize each button, the text must be written
InlineKeyboardButton youtube= new InlineKeyboardButton("youtube");
// Also must use exactly one of the optional fields,it can edit by set method
youtube.setUrl("https://www.youtube.com");
// Add button to the list
Buttons.add(youtube);
// Initialize each button, the text must be written
InlineKeyboardButton github= new InlineKeyboardButton("github");
// Also must use exactly one of the optional fields,it can edit by set method
github.setUrl("https://github.com");
// Add button to the list
Buttons.add(github);
keyboard.add(Buttons);
inlineKeyboardMarkup.setKeyboard(keyboard);
// Add it to the message
message.setReplyMarkup(inlineKeyboardMarkup);

try {
// Send the message
execute(message);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
```

## <a id="how_to_host"></a>How can I run my bot? ##

You don't need to spend a lot of money into hosting your own telegram bot. Basically, there are two options around how to host:
Expand Down
4 changes: 2 additions & 2 deletions TelegramBots.wiki/Getting-Started.md
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>5.2.0</version>
<version>5.3.0</version>
</dependency>
```
* With **Gradle**:

```gradle
implementation 'org.telegram:telegrambots:5.2.0'
implementation 'org.telegram:telegrambots:5.3.0'
```

2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
Expand Down
15 changes: 15 additions & 0 deletions TelegramBots.wiki/How-To-Update.md
@@ -1,3 +1,18 @@
### <a id="5.3.0"></a>To version 5.3.0 ###
1. As per API guidelines, ChatMember method has been divided in different classed.
Where used in your code, replace old import with new one
(GetChatAdministrators.java, GetChatMember.java, ChatMemberUpdated.java):

`import org.telegram.telegrambots.meta.api.objects.ChatMember;`

to

`import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;`
2. ChatMember is an interface now, you'll need to cast it to the corresponding implementation when using it.
3. `GetChatMembersCount` renamed to `GetChatMemberCount`, old version will still work until next major version.
4. `KickChatMember` renamed to `BanChatMember`, old version will still work until next major version.


### <a id="5.1.0"></a>To version 5.1.0 ###
1. All users IDs fields are now Long type as per API guidelines.

Expand Down
4 changes: 2 additions & 2 deletions TelegramBots.wiki/abilities/Simple-Example.md
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>5.2.0</version>
<version>5.3.0</version>
</dependency>
```
* **Gradle**
```gradle
implementation 'org.telegram:telegrambots-abilities:5.2.0'
implementation 'org.telegram:telegrambots-abilities:5.3.0'
```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -7,7 +7,7 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>5.2.0</version>
<version>5.3.0</version>

<modules>
<module>telegrambots</module>
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-abilities/README.md
Expand Up @@ -18,14 +18,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</dependency>
```

**Gradle**

```gradle
implementation 'org.telegram:telegrambots-abilities:5.2.0'
implementation 'org.telegram:telegrambots-abilities:5.3.0'
```

**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1)
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-abilities/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>

<artifactId>telegrambots-abilities</artifactId>
Expand Down Expand Up @@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Expand Up @@ -21,6 +21,8 @@
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberAdministrator;
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberOwner;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -260,8 +262,17 @@ public boolean isGroupAdmin(Update update, long id) {
public boolean isGroupAdmin(long chatId, long id) {
GetChatAdministrators admins = GetChatAdministrators.builder().chatId(Long.toString(chatId)).build();
return silent.execute(admins)
.orElse(new ArrayList<>()).stream()
.anyMatch(member -> member.getUser().getId() == id);
.orElse(new ArrayList<>())
.stream()
.map(member -> {
if (member instanceof ChatMemberAdministrator) {
return ((ChatMemberAdministrator) member).getUser().getId();
} else if (member instanceof ChatMemberOwner) {
return ((ChatMemberOwner) member).getUser().getId();
}
return 0L;
})
.anyMatch(member -> member == id);
}

public boolean isCreator(long id) {
Expand Down
Expand Up @@ -39,7 +39,10 @@ public Optional<Message> forceReply(String message, long id) {
SendMessage msg = new SendMessage();
msg.setText(message);
msg.setChatId(Long.toString(id));
msg.setReplyMarkup(new ForceReplyKeyboard());
ForceReplyKeyboard kb = new ForceReplyKeyboard();
kb.setForceReply(true);
kb.setSelective(true);
msg.setReplyMarkup(kb);

return execute(msg);
}
Expand Down
Expand Up @@ -10,14 +10,23 @@
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.telegram.abilitybots.api.db.DBContext;
import org.telegram.abilitybots.api.objects.*;
import org.telegram.abilitybots.api.objects.Ability;
import org.telegram.abilitybots.api.objects.Flag;
import org.telegram.abilitybots.api.objects.Locality;
import org.telegram.abilitybots.api.objects.MessageContext;
import org.telegram.abilitybots.api.objects.Privacy;
import org.telegram.abilitybots.api.sender.MessageSender;
import org.telegram.abilitybots.api.sender.SilentSender;
import org.telegram.abilitybots.api.util.AbilityUtils;
import org.telegram.abilitybots.api.util.Pair;
import org.telegram.abilitybots.api.util.Trio;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators;
import org.telegram.telegrambots.meta.api.objects.*;
import org.telegram.telegrambots.meta.api.objects.Document;
import org.telegram.telegrambots.meta.api.objects.File;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberAdministrator;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

import java.io.BufferedWriter;
Expand All @@ -37,19 +46,32 @@
import static org.apache.commons.io.FileUtils.deleteQuietly;
import static org.apache.commons.lang3.ArrayUtils.addAll;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.internal.verification.VerificationModeFactory.times;
import static org.telegram.abilitybots.api.bot.DefaultBot.*;
import static org.telegram.abilitybots.api.bot.DefaultBot.FIRST_REPLY_KEY_MESSAGE;
import static org.telegram.abilitybots.api.bot.DefaultBot.SECOND_REPLY_KEY_MESSAGE;
import static org.telegram.abilitybots.api.bot.DefaultBot.getDefaultBuilder;
import static org.telegram.abilitybots.api.bot.TestUtils.CREATOR;
import static org.telegram.abilitybots.api.bot.TestUtils.*;
import static org.telegram.abilitybots.api.bot.TestUtils.USER;
import static org.telegram.abilitybots.api.bot.TestUtils.mockContext;
import static org.telegram.abilitybots.api.bot.TestUtils.mockFullUpdate;
import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance;
import static org.telegram.abilitybots.api.objects.Flag.DOCUMENT;
import static org.telegram.abilitybots.api.objects.Flag.MESSAGE;
import static org.telegram.abilitybots.api.objects.Locality.ALL;
import static org.telegram.abilitybots.api.objects.Locality.GROUP;
import static org.telegram.abilitybots.api.objects.MessageContext.newContext;
import static org.telegram.abilitybots.api.objects.Privacy.*;
import static org.telegram.abilitybots.api.objects.Privacy.ADMIN;
import static org.telegram.abilitybots.api.objects.Privacy.GROUP_ADMIN;
import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC;

public class AbilityBotTest {
// Messages
Expand Down Expand Up @@ -431,7 +453,7 @@ void canValidateGroupAdminPrivacy() {
mockUser(update, message, user);
when(message.isGroupMessage()).thenReturn(true);

ChatMember member = mock(ChatMember.class);
ChatMemberAdministrator member = mock(ChatMemberAdministrator.class);
when(member.getUser()).thenReturn(user);
when(member.getUser()).thenReturn(user);

Expand Down
4 changes: 2 additions & 2 deletions telegrambots-chat-session-bot/README.md
Expand Up @@ -15,14 +15,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-chat-session-bot</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</dependency>
```

**Gradle**

```gradle
implementation 'org.telegram:telegrambots-chat-session-bot:5.2.0'
implementation 'org.telegram:telegrambots-chat-session-bot:5.3.0'
```

Motivation
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-chat-session-bot/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>

<artifactId>telegrambots-chat-session-bot</artifactId>
Expand Down Expand Up @@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-extensions/README.md
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>5.2.0</version>
<version>5.3.0</version>
</dependency>
```

2. Using Gradle:

```gradle
implementation 'org.telegram:telegrambotsextensions:5.2.0'
implementation 'org.telegram:telegrambotsextensions:5.3.0'
```
4 changes: 2 additions & 2 deletions telegrambots-extensions/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>

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

Expand Down
2 changes: 1 addition & 1 deletion telegrambots-meta/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>

<artifactId>telegrambots-meta</artifactId>
Expand Down

0 comments on commit 247274a

Please sign in to comment.