Skip to content

Commit

Permalink
Merge pull request #127 from yvasyliev/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
yvasyliev committed Aug 28, 2022
2 parents 2471a73 + 46c272c commit 3516b06
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 110 deletions.
111 changes: 57 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ This library keeps on improving. Feel free to create issues or pull requests.

## Third-party dependencies
This library uses the next third-party dependencies:
* Gson
* SLF4J
* `Gson`
* `SLF4J`

## Requirements
1. Java 8+
2. Maven (or other build tool)
1. `Java 8` or higher
2. `Maven` or other build tool

## Quickstart
1. Create VK Community.
2. Go to `Manage` - `API usage` - `Access tokens` and create `access_token`.
3. Add the library to your Maven project:
3. Add the library to your `Maven` project:
```xml
<dependency>
<groupId>com.github.yvasyliev</groupId>
<artifactId>java-vk-bots-longpoll-api</artifactId>
<version>3.4.4</version>
<version>3.4.5</version>
</dependency>
```
4. Extend `LongPollBot` class and override necessary methods:
Expand Down Expand Up @@ -82,7 +82,7 @@ public void onMessageNew(MessageNew messageNew) {
}
```
## More Examples
Find more examples of bot usage [here](https://github.com/yvasyliev/java-vk-bots-long-poll-api-examples)
Find more examples of bot usage [here](https://github.com/yvasyliev/java-vk-bots-long-poll-api-examples).
## Async execution
Each API method can be executed asynchronously:
```java
Expand All @@ -91,54 +91,57 @@ CompletableFuture<Send.Response> future = vk.messages.send()
.setMessage("Sending message asynchronously...")
.executeAsync();
```
## Bot capabilities
`LongPollBot` supports the next event handlers:
* `onAppPayload(AppPayload appPayload)`
* `onAudioNew(Audio audio)`
* `onBoardPostDelete(BoardPostDelete boardPostDelete)`
* `onBoardPostEdit(BoardPost boardPost)`
* `onBoardPostNew(BoardPost boardPost)`
* `onBoardPostRestore(BoardPost boardPost)`
* `onGroupChangePhoto(GroupChangePhoto groupChangePhoto)`
* `onGroupChangeSettings(GroupChangeSettings groupChangeSettings)`
* `onGroupJoin(GroupJoin groupJoin)`
* `onGroupLeave(GroupLeave groupLeave)`
* `onLikeAdd(Like like)`
* `onLikeRemove(Like like)`
* `onMarketCommentDelete(MarketCommentDelete marketCommentDelete)`
* `onMarketCommentEdit(MarketComment marketComment)`
* `onMarketCommentNew(MarketComment marketComment)`
* `onMarketCommentRestore(MarketComment marketComment)`
* `onMarketOrderEdit(MarketOrder marketOrder)`
* `onMarketOrderNew(MarketOrder marketOrder)`
* `onMessageAllow(MessageAllow messageAllow)`
* `onMessageDeny(MessageDeny messageDeny)`
* `onMessageEdit(Message message)`
* `onMessageEvent(MessageEvent messageEvent)`
* `onMessageNew(MessageNew messageNew)`
* `onMessageReply(Message message)`
* `onMessageTypingState(MessageTypingState messageTypingState)`
* `onPhotoCommentDelete(PhotoCommentDelete photoCommentDelete)`
* `onPhotoCommentEdit(PhotoComment photoComment)`
* `onPhotoCommentNew(PhotoComment photoComment)`
* `onPhotoCommentRestore(PhotoComment photoComment)`
* `onPhotoNew(Photo photo)`
* `onUserBlock(UserBlock userBlock)`
* `onUserUnblock(UserUnblock userUnblock)`
* `onVideoCommentDelete(VideoCommentDelete videoCommentDelete)`
* `onVideoCommentEdit(VideoComment videoComment)`
* `onVideoCommentNew(VideoComment videoComment)`
* `onVideoCommentRestore(VideoComment videoComment)`
* `onVideoNew(Video video)`
* `onVkpayTransaction(VkpayTransaction vkpayTransaction)`
* `onWallPostNew(WallPost wallPost)`
* `onWallReplyDelete(WallReplyDelete wallReplyDelete)`
* `onWallReplyEdit(WallReply wallReply)`
* `onWallReplyNew(WallReply wallReply)`
* `onWallReplyRestore(WallReply wallReply)`
* `onWallRepost(WallPost wallPost)`
## Bot events
`LongPollBot` can handle the next events:

| VK event | Handler method |
|--------------------------:|:------------------------------------------------------------------------------|
| `app_payload` | `public void onAppPayload(AppPayload appPayload)` |
| `audio_new` | `public void onAudioNew(Audio audio)` |
| `board_post_delete` | `public void onBoardPostDelete(BoardPostDelete boardPostDelete)` |
| `board_post_edit` | `public void onBoardPostEdit(BoardPost boardPost)` |
| `board_post_new` | `public void onBoardPostNew(BoardPost boardPost)` |
| `board_post_restore` | `public void onBoardPostRestore(BoardPost boardPost)` |
| `group_change_photo` | `public void onGroupChangePhoto(GroupChangePhoto groupChangePhoto)` |
| `group_change_settings` | `public void onGroupChangeSettings(GroupChangeSettings groupChangeSettings)` |
| `group_join` | `public void onGroupJoin(GroupJoin groupJoin)` |
| `group_leave` | `public void onGroupLeave(GroupLeave groupLeave)` |
| `like_add` | `public void onLikeAdd(Like like)` |
| `like_remove` | `public void onLikeRemove(Like like)` |
| `market_comment_delete` | `public void onMarketCommentDelete(MarketCommentDelete marketCommentDelete)` |
| `market_comment_edit` | `public void onMarketCommentEdit(MarketComment marketComment)` |
| `market_comment_new` | `public void onMarketCommentNew(MarketComment marketComment)` |
| `market_comment_restore` | `public void onMarketCommentRestore(MarketComment marketComment)` |
| `market_order_edit` | `public void onMarketOrderEdit(MarketOrder marketOrder)` |
| `market_order_new` | `public void onMarketOrderNew(MarketOrder marketOrder)` |
| `message_allow` | `public void onMessageAllow(MessageAllow messageAllow)` |
| `message_deny` | `public void onMessageDeny(MessageDeny messageDeny)` |
| `message_edit` | `public void onMessageEdit(Message message)` |
| `message_event` | `public void onMessageEvent(MessageEvent messageEvent)` |
| `message_new` | `public void onMessageNew(MessageNew messageNew)` |
| `message_reply` | `public void onMessageReply(Message message)` |
| `message_typing_state` | `public void onMessageTypingState(MessageTypingState messageTypingState)` |
| `photo_comment_delete` | `public void onPhotoCommentDelete(PhotoCommentDelete photoCommentDelete)` |
| `photo_comment_edit` | `public void onPhotoCommentEdit(PhotoComment photoComment)` |
| `photo_comment_new` | `public void onPhotoCommentNew(PhotoComment photoComment)` |
| `photo_comment_restore` | `public void onPhotoCommentRestore(PhotoComment photoComment)` |
| `photo_comment_new` | `public void onPhotoNew(Photo photo)` |
| `user_block` | `public void onUserBlock(UserBlock userBlock)` |
| `user_unblock` | `public void onUserUnblock(UserUnblock userUnblock)` |
| `video_comment_delete` | `public void onVideoCommentDelete(VideoCommentDelete videoCommentDelete)` |
| `video_comment_edit` | `public void onVideoCommentEdit(VideoComment videoComment)` |
| `video_comment_new` | `public void onVideoCommentNew(VideoComment videoComment)` |
| `video_comment_restore` | `public void onVideoCommentRestore(VideoComment videoComment)` |
| `video_new` | `public void onVideoNew(Video video)` |
| `vkpay_transaction` | `public void onVkpayTransaction(VkpayTransaction vkpayTransaction)` |
| `wall_post_new` | `public void onWallPostNew(WallPost wallPost)` |
| `wall_reply_delete` | `public void onWallReplyDelete(WallReplyDelete wallReplyDelete)` |
| `wall_reply_edit` | `public void onWallReplyEdit(WallReply wallReply)` |
| `wall_reply_new` | `public void onWallReplyNew(WallReply wallReply)` |
| `wall_reply_restore` | `public void onWallReplyRestore(WallReply wallReply)` |
| `wall_repost` | `public void onWallRepost(WallPost wallPost)` |

## Logging
This library uses SLF4J API to log all events. You can add any SLF4J binding to your project to register events the way you want.
This library uses `SLF4J` API to log all events. You can add any `SLF4J` binding to your project to register events the way you want.

It is highly recommended enabling `DEBUG` log level to see sent and received data.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.github.yvasyliev</groupId>
<artifactId>java-vk-bots-longpoll-api</artifactId>
<packaging>jar</packaging>
<version>3.4.4</version>
<version>3.4.5</version>
<name>Java VK Bots Long Poll API</name>
<description>A Java library to create VK bots using Bots Long Poll API</description>
<url>https://github.com/yvasyliev/java-vk-bots-long-poll-api</url>
Expand All @@ -29,12 +29,12 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/api/longpoll/bots/methods/impl/messages/Edit.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import api.longpoll.bots.model.objects.additional.Template;
import api.longpoll.bots.model.objects.additional.UploadedFile;
import api.longpoll.bots.model.response.IntegerResponseBody;
import api.longpoll.bots.suppliers.PeerIdSupplier;

import java.io.File;
import java.io.InputStream;
Expand All @@ -34,9 +33,9 @@ public class Edit extends VkMethod<IntegerResponseBody> {
private final List<UploadableFile> uploadableFiles = new ArrayList<>();

/**
* Supplies {@code peer_id}.
* Message {@code peer_id}.
*/
private final PeerIdSupplier peerIdSupplier = new PeerIdSupplier();
private int peerId;

public Edit(String accessToken) {
super(accessToken);
Expand Down Expand Up @@ -71,7 +70,7 @@ public Edit addPhoto(File photo) {
public Edit addPhoto(Path photo) {
uploadableFiles.add(new PathUploadableMessagePhoto(
photo,
peerIdSupplier,
() -> peerId,
getAccessToken()
));
return this;
Expand All @@ -81,7 +80,7 @@ public Edit addPhoto(InputStream photo, String extension) {
uploadableFiles.add(new InputStreamUploadableMessagePhoto(
photo,
extension,
peerIdSupplier,
() -> peerId,
getAccessToken()
));
return this;
Expand All @@ -94,7 +93,7 @@ public Edit addDoc(File doc) {
public Edit addDoc(Path doc) {
uploadableFiles.add(new PathUploadableMessageDoc(
doc,
peerIdSupplier,
() -> peerId,
getAccessToken()
));
return this;
Expand All @@ -104,7 +103,7 @@ public Edit addDoc(InputStream doc, String extension) {
uploadableFiles.add(new InputStreamUploadableMessageDoc(
doc,
extension,
peerIdSupplier,
() -> peerId,
getAccessToken()
));
return this;
Expand All @@ -123,7 +122,7 @@ public Edit setAttachment(String attachment) {
}

public Edit setPeerId(int peerId) {
peerIdSupplier.setPeerId(peerId);
this.peerId = peerId;
return addParam("peer_id", peerId);
}

Expand Down
17 changes: 8 additions & 9 deletions src/main/java/api/longpoll/bots/methods/impl/messages/Send.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import api.longpoll.bots.model.objects.additional.Template;
import api.longpoll.bots.model.objects.additional.UploadedFile;
import api.longpoll.bots.model.response.GenericResponseBody;
import api.longpoll.bots.suppliers.PeerIdSupplier;
import com.google.gson.JsonElement;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
Expand All @@ -39,9 +38,9 @@ public class Send extends VkMethod<Send.ResponseBody> {
private final List<UploadableFile> uploadableFiles = new ArrayList<>();

/**
* Supplies {@code peer_id}.
* Message {@code peer_id}.
*/
private final PeerIdSupplier peerIdSupplier = new PeerIdSupplier();
private int peerId;

public Send(String accessToken) {
super(accessToken);
Expand Down Expand Up @@ -77,7 +76,7 @@ public Send addPhoto(File photo) {
public Send addPhoto(Path photo) {
uploadableFiles.add(new PathUploadableMessagePhoto(
photo,
peerIdSupplier,
() -> peerId,
getAccessToken()
));
return this;
Expand All @@ -87,7 +86,7 @@ public Send addPhoto(InputStream photo, String extension) {
uploadableFiles.add(new InputStreamUploadableMessagePhoto(
photo,
extension,
peerIdSupplier,
() -> peerId,
getAccessToken()
));
return this;
Expand All @@ -100,7 +99,7 @@ public Send addDoc(File doc) {
public Send addDoc(Path doc) {
uploadableFiles.add(new PathUploadableMessageDoc(
doc,
peerIdSupplier,
() -> peerId,
getAccessToken()
));
return this;
Expand All @@ -110,7 +109,7 @@ public Send addDoc(InputStream doc, String extension) {
uploadableFiles.add(new InputStreamUploadableMessageDoc(
doc,
extension,
peerIdSupplier,
() -> peerId,
getAccessToken()
));
return this;
Expand All @@ -129,7 +128,7 @@ public Send setAttachment(String attachment) {
}

public Send setUserId(int userId) {
peerIdSupplier.setPeerId(userId);
this.peerId = userId;
return addParam("user_id", userId);
}

Expand All @@ -138,7 +137,7 @@ public Send setRandomId(int randomId) {
}

public Send setPeerId(int peerId) {
peerIdSupplier.setPeerId(peerId);
this.peerId = peerId;
return addParam("peer_id", peerId);
}

Expand Down
32 changes: 0 additions & 32 deletions src/main/java/api/longpoll/bots/suppliers/PeerIdSupplier.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/api/longpoll/bots/suppliers/package-info.java

This file was deleted.

0 comments on commit 3516b06

Please sign in to comment.