Skip to content

Commit 74244fd

Browse files
committed
initial
1 parent f8cefe3 commit 74244fd

File tree

101 files changed

+6942
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+6942
-2
lines changed

README.md

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,107 @@
1-
# onebot-sdk
2-
基于java开发的onebot协议客户端sdk
1+
2+
<div align="center">
3+
4+
# OneBot SDK
5+
6+
_✨ 基于java开发的 [OneBot](https://github.com/howmanybots/onebot/blob/master/README.md)协议客户端sdk✨_
7+
8+
</div>
9+
<hr>
10+
<p align="center">
11+
<a href="https://github.com/cnlimiter/onebot-sdk/issues"><img src="https://img.shields.io/github/issues/cnlimiter/onebot-sdk?style=flat" alt="issues" /></a>
12+
<a href="https://github.com/cnlimiter/onebot-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-GPLV3-green" alt="License"></a>
13+
<a href="https://github.com/howmanybots/onebot"><img src="https://img.shields.io/badge/OneBot-v11-blue?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg=="></a>
14+
</p>
15+
<p align="center">
16+
<a href="#">文档</a> |
17+
<a href="#">QuickStart</a>
18+
</p>
19+
20+
21+
# QuickStart
22+
23+
### 使用api进行请求
24+
```java
25+
public class WebSocketClientTest {
26+
public static void sendApi(String[] args) throws Exception {
27+
LinkedBlockingQueue<String> blockingQueue = new LinkedBlockingQueue<>();//使用队列传输数据
28+
ModWebSocketClient service = ConnectFactory.createWebsocketClient(new BotConfig("ws://127.0.0.1:8080"),blockingQueue);
29+
service.create();//创建websocket客户端
30+
Bot bot = service.createBot();//创建机器人实例,以调用api
31+
bot.sendGroupMsg(123456, MsgUtils.builder().text("123").build(), true);//发送群消息
32+
GroupMemberInfoResp sender = bot.getGroupMemberInfo(123456, 123456, false).getData();//获取响应的群成员信息
33+
System.out.println(sender.toString());//打印
34+
}
35+
}
36+
```
37+
38+
### 事件监听示例
39+
```java
40+
public class WebSocketClientTest {
41+
public static void eventListener(String[] args) throws Exception {
42+
LinkedBlockingQueue<String> blockingQueue = new LinkedBlockingQueue<>();//使用队列传输数据
43+
ModWebSocketClient service = ConnectFactory.createWebsocketClient(new BotConfig("ws://127.0.0.1:8080"),blockingQueue);
44+
service.create();//创建websocket客户端
45+
EventDispatchers dispatchers = new EventDispatchers(blockingQueue);//创建事件分发器
46+
GroupMessageListener groupMessageListener = new GroupMessageListener();//自定义监听规则
47+
groupMessageListener.addHandler("天气", new Handler<GroupMessageEvent>() {
48+
@Override
49+
public void handle(GroupMessageEvent groupMessage) {
50+
System.out.println(groupMessage);
51+
52+
}
53+
});//匹配关键字监听
54+
dispatchers.addListener(groupMessageListener);//注册监听
55+
dispatchers.addListener(new SimpleListener<PrivateMessageEvent>() {//私聊监听
56+
@Override
57+
public void onMessage(PrivateMessageEvent privateMessage) {
58+
System.out.println(privateMessage);
59+
}
60+
});//快速监听
61+
62+
dispatchers.start(10);//线程组处理任务
63+
64+
}
65+
}
66+
```
67+
68+
# Client
69+
70+
OneBot-SDK 以 [OneBot-v11](https://github.com/howmanybots/onebot/tree/master/v11/specs) 标准协议进行开发,兼容所有支持正向WebSocket的OneBot协议客户端
71+
72+
| 项目地址 | 平台 | 核心作者 | 备注 |
73+
| --- |-----------------------------------------------| --- | --- |
74+
| [koishijs/koishi](https://github.com/koishijs/koishi) | [koishi](https://koishi.js.org/) | shigma | |
75+
| [onebot-walle/walle-q](https://github.com/onebot-walle/walle-q) | | abrahum | |
76+
| [Yiwen-Chan/OneBot-YaYa](https://github.com/Yiwen-Chan/OneBot-YaYa) | [先驱](https://www.xianqubot.com/) | kanri | |
77+
| [richardchien/coolq-http-api](https://github.com/richardchien/coolq-http-api) | CKYU | richardchien | 可在 Mirai 平台使用 [mirai-native](https://github.com/iTXTech/mirai-native) 加载 |
78+
| [Mrs4s/go-cqhttp](https://github.com/Mrs4s/go-cqhttp) | [MiraiGo](https://github.com/Mrs4s/MiraiGo) | Mrs4s | |
79+
| [yyuueexxiinngg/OneBot-Mirai](https://github.com/yyuueexxiinngg/onebot-kotlin) | [Mirai](https://github.com/mamoe/mirai) | yyuueexxiinngg | |
80+
| [takayama-lily/onebot](https://github.com/takayama-lily/onebot) | [OICQ](https://github.com/takayama-lily/oicq) | takayama | |
81+
82+
83+
# Credits
84+
85+
* [OneBot](https://github.com/botuniverse/onebot)
86+
87+
# License
88+
89+
This product is licensed under the GNU General Public License version 3. The license is as published by the Free
90+
Software Foundation published at https://www.gnu.org/licenses/gpl-3.0.html.
91+
92+
Alternatively, this product is licensed under the GNU Lesser General Public License version 3 for non-commercial use.
93+
The license is as published by the Free Software Foundation published at https://www.gnu.org/licenses/lgpl-3.0.html.
94+
95+
Feel free to contact us if you have any questions about licensing or want to use the library in a commercial closed
96+
source product.
97+
98+
# Thanks
99+
100+
Thanks [JetBrains](https://www.jetbrains.com/?from=Shiro) Provide Free License Support OpenSource Project
101+
102+
[<img src="https://mikuac.com/images/jetbrains-variant-3.png" width="200"/>](https://www.jetbrains.com/?from=mirai)
103+
104+
## Stargazers over time
105+
106+
[![Stargazers over time](https://starchart.cc/cnlimiter/onebot-sdk.svg)](https://starchart.cc/cnlimiter/onebot-sdk)
107+

build.gradle

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group 'cn.evolvefield.bot.onebot-sdk'
6+
version '0.1.0'
7+
8+
java {
9+
archivesBaseName = 'OneBot-SDK'
10+
toolchain.languageVersion = JavaLanguageVersion.of(17)
11+
}
12+
13+
repositories {
14+
mavenCentral()
15+
}
16+
17+
dependencies {
18+
implementation 'org.projectlombok:lombok:1.18.24'
19+
implementation 'com.google.code.gson:gson:2.9.0'
20+
implementation 'org.slf4j:slf4j-api:1.8.0-beta4'
21+
implementation 'org.jetbrains:annotations:20.1.0'
22+
implementation 'org.slf4j:slf4j-simple:1.7.30'
23+
implementation 'org.java-websocket:Java-WebSocket:1.5.1'
24+
25+
annotationProcessor 'org.projectlombok:lombok:1.18.24'
26+
annotationProcessor 'com.google.code.gson:gson:2.9.0'
27+
annotationProcessor 'org.slf4j:slf4j-api:1.8.0-beta4'
28+
annotationProcessor 'org.jetbrains:annotations:20.1.0'
29+
annotationProcessor 'org.slf4j:slf4j-simple:1.7.30'
30+
annotationProcessor 'org.java-websocket:Java-WebSocket:1.5.1'
31+
32+
}
33+
34+
test {
35+
useJUnitPlatform()
36+
}
37+
38+
tasks.withType(JavaCompile).configureEach {
39+
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
40+
}
41+

gradle/wrapper/gradle-wrapper.jar

58.4 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

gradlew

Lines changed: 234 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)