Skip to content

Commit eda70ae

Browse files
committed
feat: 0.1.0-RELEASE
1 parent e6b93fe commit eda70ae

File tree

2 files changed

+186
-1
lines changed

2 files changed

+186
-1
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,72 @@ openqq-java 是基于官方qq机器人协议的 java sdk 实现。本实现将
3838
- [ ] Media
3939
- [ ] Emotion
4040

41+
## Usage
42+
43+
```xml
44+
<dependency>
45+
<groupId>cn.byteforge.openqq</groupId>
46+
<artifactId>openqq-for-java</artifactId>
47+
<version>0.1.0</version>
48+
</dependency>
49+
```
50+
51+
```java
52+
public class TestMain {
53+
54+
private static BotContext context;
55+
56+
public static void main(String[] args) throws Exception {
57+
String appId = new String(Files.readAllBytes(Paths.get("secrets/appId.txt")));
58+
String clientSecret = new String(Files.readAllBytes(Paths.get("secrets/clientSecret.txt")));
59+
AccessToken token = OpenAPI.getAppAccessToken(appId, clientSecret);
60+
Certificate certificate = new Certificate(appId, clientSecret, token);
61+
context = BotContext.create(certificate);
62+
RecommendShard shard = OpenAPI.getRecommendShardWssUrls(certificate);
63+
String wssUrl = shard.getUrl();
64+
65+
Intent intent = Intent.register()
66+
.withCustom(1 << 25)
67+
.withCustom(1 << 26)
68+
.done();
69+
ChainHandler chainHandler = ChainHandler.defaultChainGroup(wssUrl, null,
70+
new EventListener<GroupAtMessageEvent>() {
71+
@Override
72+
public void onEvent(GroupAtMessageEvent event) {
73+
GroupAtMessageData data = event.getData();
74+
Message message = new MessageBuilder()
75+
.addTemplateMarkdownButton("")
76+
.setPassive(data.getId())
77+
.build();
78+
OpenAPI.sendGroupMessage(data.getGroupId(), message, certificate);
79+
}
80+
81+
@Override
82+
public Intent eventIntent() {
83+
return Intent.register().withCustom(1 << 25).done();
84+
}
85+
}, new EventListener<InteractionEvent>() {
86+
@Override
87+
public void onEvent(InteractionEvent event) {
88+
System.out.println("收到:" + event);
89+
}
90+
91+
@Override
92+
public Intent eventIntent() {
93+
return Intent.register().withInteraction().done();
94+
}
95+
});
96+
97+
QQConnection.connect(wssUrl, chainHandler, context,
98+
uuid -> WebSocketAPI.newStandaloneSession(intent, uuid, null, context),
99+
uuid -> {
100+
// do sth
101+
});
102+
}
103+
104+
}
105+
```
106+
41107
## Contributions
42108

43109
<a href="https://github.com/ByteForgeTech/openqq-java/graphs/contributors">

openqq-for-java/build.gradle

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
plugins {
22
id 'java'
3+
id 'java-library'
4+
id 'maven-publish'
5+
id 'signing'
36
}
47

58
group 'cn.byteforge.openqq'
6-
version '1.0.0-SNAPSHOT'
9+
version '0.1.0'
10+
11+
[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
12+
sourceCompatibility = 1.8
13+
targetCompatibility = 1.8
714

815
repositories {
916
mavenLocal()
@@ -27,4 +34,116 @@ dependencies {
2734

2835
test {
2936
useJUnitPlatform()
37+
}
38+
39+
task sourcesJar(type: Jar) {
40+
from sourceSets.main.allJava
41+
classifier = 'sources'
42+
}
43+
44+
task javadocJar(type: Jar) {
45+
from javadoc
46+
classifier = 'javadoc'
47+
}
48+
49+
tasks.withType(Jar).configureEach { task ->
50+
task.doLast {
51+
ant.checksum algorithm: 'md5', file: it.archivePath
52+
ant.checksum algorithm: 'sha1', file: it.archivePath
53+
}
54+
}
55+
56+
javadoc {
57+
description = "生成jar格式的javadoc。"
58+
// 只显示 protected 和 public 的类和成员
59+
options.memberLevel = JavadocMemberLevel.PROTECTED
60+
options.author = true
61+
options.version = true
62+
options.header = project.name
63+
// 静默javadoc检查(比如不支持@date会报错等),jdk 8+
64+
options.addStringOption('Xdoclint:none', '-quiet')
65+
/**
66+
* <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
67+
* 防止本地打开中文乱码
68+
*/
69+
options.addStringOption("charset", "UTF-8")
70+
// suppress warnings due to cross-module @see and @link references;
71+
// note that global 'api' task does display all warnings.
72+
logging.captureStandardError LogLevel.INFO
73+
// suppress "## warnings" message
74+
logging.captureStandardOutput LogLevel.INFO
75+
// 编码一定要配置否则直接出错
76+
options.encoding = "UTF-8"
77+
options.charSet = "UTF-8"
78+
}
79+
80+
publishing {
81+
publications {
82+
mavenJava(MavenPublication) {
83+
/** 默认使用项目的group/name/version信息 */
84+
/**
85+
groupId = ''
86+
artifactId = ''
87+
version = ''
88+
*/
89+
/**
90+
* 如果是war包填写components.web,
91+
* 如果是jar包填写components.java,
92+
* 不过该方法没有manifest信息(会自动附带pom依赖信息)
93+
*/
94+
from components.java
95+
artifact sourcesJar
96+
artifact javadocJar
97+
pom {
98+
name = project.name
99+
description = 'openqq-protocol 是在与官方qq机器人协议对接的基础上,额外onebot、satori等社区协议进行的适配sdk实现。'
100+
url = 'https://github.com/IUnlimit/openqq-protocol'
101+
licenses {
102+
license {
103+
name = 'AGPLv3'
104+
url = 'https://www.gnu.org/licenses/agpl-3.0'
105+
}
106+
}
107+
developers {
108+
developer {
109+
id = 'IllTamer'
110+
email = 'mail@illtamer.com'
111+
}
112+
}
113+
scm {
114+
url = 'https://github.com/IUnlimit/openqq-protocol'
115+
connection = 'scm:git:https://github.com/IUnlimit/openqq-protocol.git'
116+
}
117+
}
118+
}
119+
}
120+
121+
repositories {
122+
// 发布到oss sonatype,非SNAPSHOT版必须GPG签名
123+
maven {
124+
name = 'oss'
125+
url = oss_sonatype_maven_url
126+
credentials {
127+
username oss_sonatype_maven_username
128+
password oss_sonatype_maven_password
129+
}
130+
}
131+
// oss snapshot 仓库,必须携带 -SNAPSHOT 后缀
132+
maven {
133+
name = 'oss-snapshot'
134+
url = oss_sonatype_snapshot_maven_url
135+
credentials {
136+
username = oss_sonatype_maven_username
137+
password = oss_sonatype_maven_password
138+
}
139+
}
140+
}
141+
142+
/**
143+
* GPG 签名jar包配置,注意顺序,必须在 publishing 配置之后
144+
* (因为使用了 publishing 中定义的 mavenJava)
145+
*/
146+
signing {
147+
sign publishing.publications.mavenJava
148+
}
30149
}

0 commit comments

Comments
 (0)