Skip to content

Commit

Permalink
Merge pull request #262 from rubenlagus/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rubenlagus authored Jun 30, 2017
2 parents 383b48c + 356034f commit ebf02fd
Show file tree
Hide file tree
Showing 30 changed files with 1,788 additions and 336 deletions.
22 changes: 0 additions & 22 deletions Bots.ipr
Original file line number Diff line number Diff line change
Expand Up @@ -838,28 +838,6 @@
<root url="jar://$MAVEN_REPOSITORY$/org/mockito/mockito-all/2.0.2-beta/mockito-all-2.0.2-beta-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.telegram:telegrambots-meta:3.0.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots-meta/3.0.1/telegrambots-meta-3.0.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots-meta/3.0.1/telegrambots-meta-3.0.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots-meta/3.0.1/telegrambots-meta-3.0.1-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.telegram:telegrambots:3.0.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots/3.0.1/telegrambots-3.0.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots/3.0.1/telegrambots-3.0.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots/3.0.1/telegrambots-3.0.1-sources.jar!/" />
</SOURCES>
</library>
</component>
<component name="masterDetails">
<states>
Expand Down
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>3.0.2</version>
<version>3.1.0</version>
</dependency>
```

```gradle
compile "org.telegram:telegrambots:3.0.2"
compile "org.telegram:telegrambots:3.1.0"
```

2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/3.0.2)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/3.0.2)
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/3.1.0)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v3.1.0)

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

Expand Down
13 changes: 11 additions & 2 deletions TelegramBots.wiki/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@
### <a id="3.0.2"></a>3.0.2 ###
1. Bug Fixing: #250
2. Added new module `telegrambots-extensions` that should contains any extensions of the API such as CommandBot or TimedBot.
3. `TelegramLongPollingCommandBot` receives now the bot username as constructor parameters, all deprecated constructors will be removed in next mayor release.
4. `getUsername` method from `TelegramLongPollingCommandBot` can be considered `final` and will be so in next mayor release.
3. `TelegramLongPollingCommandBot` receives now the bot username as constructor parameters, all deprecated constructors will be removed in next major release.
4. `getUsername` method from `TelegramLongPollingCommandBot` can be considered `final` and will be so in next major release.

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

### <a id="3.1.0"></a>3.1.0 ###
1. Support for Api Version [3.1](https://core.telegram.org/bots/api-changelog#june-30-2017)
2. Simplified `DefaultAbsSender`
3. Added new abstract method `setChatPhoto` to AbsSender.
4. Added new method `execute` and `executeAsync` that can be used to send any api method that extends `BotApiMethod` class.
5. Added new constructors to `GetChat`, `GetChatAdministrators`, `GetChatMember`, `GetChatMemberCount`, `KickChatMember`, `LeaveChat` and `UnbanChatMember` with mandatory fields as parameters.

**[[How to update to version 3.1.0|How-To-Update#3.1.0]]**
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>3.0.2</version>
<version>3.1.0</version>
</dependency>
```
* With **Gradle**:

```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '3.0.2'
compile group: 'org.telegram', name: 'telegrambots', version: '3.1.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 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>3.0.2</version>
<version>3.1.0</version>

<modules>
<module>telegrambots</module>
Expand All @@ -25,6 +25,6 @@

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<bots.version>3.0.2</bots.version>
<bots.version>3.1.0</bots.version>
</properties>
</project>
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>3.0.2</version>
<version>3.1.0</version>
</dependency>
```

2. Using Gradle:

```gradle
compile "org.telegram:telegrambotsextensions:3.0.2"
compile "org.telegram:telegrambotsextensions:3.1.0"
```
4 changes: 2 additions & 2 deletions telegrambots-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>3.0.2</version>
<version>3.1.0</version>
<packaging>jar</packaging>

<name>Telegram Bots Extensions</name>
Expand Down Expand Up @@ -59,7 +59,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>3.0.2</bots.version>
<bots.version>3.1.0</bots.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion telegrambots-meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>3.0.2</version>
<version>3.1.0</version>
<packaging>jar</packaging>

<name>Telegram Bots Meta</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.telegram.telegrambots.api.methods.groupadministration;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.api.methods.BotApiMethod;
import org.telegram.telegrambots.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;

import java.io.IOException;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to delete a chat photo. Photos can't be changed for private chats.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Returns True on success.
*
* @apiNote In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.
*/
public class DeleteChatPhoto extends BotApiMethod<Boolean> {
public static final String PATH = "deleteChatPhoto";

private static final String CHATID_FIELD = "chat_id";

@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)

public DeleteChatPhoto() {
super();
}

public DeleteChatPhoto(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}

public DeleteChatPhoto(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}

public String getChatId() {
return chatId;
}

public DeleteChatPhoto setChatId(String chatId) {
this.chatId = chatId;
return this;
}

public DeleteChatPhoto setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}

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

@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error deleting chat photo", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}

@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null) {
throw new TelegramApiValidationException("ChatId can't be null", this);
}
}

@Override
public String toString() {
return "DeleteChatPhoto{" +
"chatId='" + chatId + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.telegram.telegrambots.api.methods.groupadministration;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.api.methods.BotApiMethod;
import org.telegram.telegrambots.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;

import java.io.IOException;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* @author Ruben Bermudez
* @version 3.1
* Use this method to export an invite link to a supergroup or a channel. The bot must be an administrator in the
* chat for this to work and must have the appropriate admin rights. Returns exported invite link as String on success.
*/
public class ExportChatInviteLink extends BotApiMethod<String> {
public static final String PATH = "exportChatInviteLink";

private static final String CHATID_FIELD = "chat_id";

@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)

public ExportChatInviteLink() {
super();
}

public ExportChatInviteLink(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}

public ExportChatInviteLink(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}

public String getChatId() {
return chatId;
}

public ExportChatInviteLink setChatId(String chatId) {
this.chatId = chatId;
return this;
}

public ExportChatInviteLink setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}

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

@Override
public String deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<String> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<String>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error exporting invite link", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}

@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}

@Override
public String toString() {
return "ExportChatInviteLink{" +
"chatId='" + chatId + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
import java.io.IOException;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to get information about the chat. Returns Chat object on success.
* @date 20 of May of 2016
* Use this method to get information about the chat. Returns Chat object on success.
*/
public class GetChat extends BotApiMethod<Chat> {
public static final String PATH = "getChat";
Expand All @@ -30,6 +31,16 @@ public GetChat() {
super();
}

public GetChat(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}

public GetChat(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}

public String getChatId() {
return chatId;
}
Expand Down Expand Up @@ -67,8 +78,8 @@ public Chat deserializeResponse(String answer) throws TelegramApiRequestExceptio

@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null) {
throw new TelegramApiValidationException("ChatId can't be null", this);
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public ArrayList<ChatMember> deserializeResponse(String answer) throws TelegramA

@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null) {
throw new TelegramApiValidationException("ChatId can't be null", this);
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public ChatMember deserializeResponse(String answer) throws TelegramApiRequestEx

@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null) {
throw new TelegramApiValidationException("ChatId can't be null", this);
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
if (userId == null) {
throw new TelegramApiValidationException("UserId can't be null", this);
Expand Down
Loading

0 comments on commit ebf02fd

Please sign in to comment.