Skip to content

Commit 74a77d7

Browse files
committed
fix #26: support switching sandbox and formal environment
1 parent 704e2e1 commit 74a77d7

14 files changed

+40
-30
lines changed

docs/readme.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ _**待完善..**_
3232
#### 启动方式
3333

3434
```java
35-
//启动类新建
35+
// 启动类新建
3636
Starter starter = new Starter("appid", "token");
3737
// 私域推荐Intents.PRIVATE_INTENTS 公域机器人推荐 Intents.PUBLIC_INTENTS
3838
starter.getConfig().setCode(Intents.PRIVATE_INTENTS.getCode());
39-
//启动
39+
// 切换沙箱与正式环境
40+
starter.getConfig().sandbox();
41+
// 启动
4042
starter.run();
4143
```
4244
#### 事件注册

pom.xml

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.kloping</groupId>
88
<artifactId>bot-qqpd-java</artifactId>
9-
<version>1.5.1-L2</version>
9+
<version>1.5.1-R2</version>
1010

1111
<packaging>jar</packaging>
1212
<name>bot-qqpd-java</name>
@@ -49,7 +49,7 @@
4949
<dependency>
5050
<groupId>io.github.Kloping</groupId>
5151
<artifactId>SpringTool</artifactId>
52-
<version>0.6.3-R1</version>
52+
<version>0.6.3-L1</version>
5353
<exclusions>
5454
<exclusion>
5555
<groupId>io.github.Kloping</groupId>
@@ -154,12 +154,12 @@
154154
</execution>
155155
</executions>
156156
<!--非手动签名配置-->
157-
<!-- <configuration>-->
158-
<!-- <gpgArguments>-->
159-
<!-- <arg>&#45;&#45;pinentry-mode</arg>-->
160-
<!-- <arg>loopback</arg>-->
161-
<!-- </gpgArguments>-->
162-
<!-- </configuration>-->
157+
<configuration>
158+
<gpgArguments>
159+
<arg>--pinentry-mode</arg>
160+
<arg>loopback</arg>
161+
</gpgArguments>
162+
</configuration>
163163
</plugin>
164164
</plugins>
165165
</build>

src/main/java/io/github/kloping/qqbot/Starter.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package io.github.kloping.qqbot;
22

3-
import io.github.kloping.spt.StarterObjectApplication;
4-
import io.github.kloping.spt.annotations.Entity;
5-
import io.github.kloping.spt.interfaces.component.ContextManager;
6-
import io.github.kloping.spt.interfaces.component.HttpClientManager;
73
import io.github.kloping.common.Public;
84
import io.github.kloping.judge.Judge;
95
import io.github.kloping.qqbot.entities.Bot;
@@ -13,9 +9,12 @@
139
import io.github.kloping.qqbot.network.WebSocketListener;
1410
import io.github.kloping.qqbot.network.WssWorker;
1511
import io.github.kloping.qqbot.utils.LoggerImpl;
12+
import io.github.kloping.spt.StarterObjectApplication;
13+
import io.github.kloping.spt.annotations.Entity;
14+
import io.github.kloping.spt.interfaces.component.ContextManager;
15+
import io.github.kloping.spt.interfaces.component.HttpClientManager;
1616
import lombok.Data;
1717
import lombok.Getter;
18-
import org.java_websocket.client.WebSocketClient;
1918

2019
import java.util.HashSet;
2120
import java.util.Set;
@@ -67,7 +66,10 @@
6766
* @author github.kloping
6867
*/
6968
public class Starter implements Runnable {
69+
public static final String SANDBOX_NET_MAIN = "https://sandbox.api.sgroup.qq.com/";
7070
public static final String NET_MAIN = "https://api.sgroup.qq.com/";
71+
public String net = NET_MAIN;
72+
public static final String NET_POINT = "{io.github.kloping.qqbot.Starter.net}";
7173
public static final String APPID_ID = "appid";
7274
public static final String TOKEN_ID = "token";
7375
public static final String SECRET_ID = "secret";
@@ -130,6 +132,7 @@ protected void after() {
130132
String appid = getConfig().getAppid();
131133
String token = getConfig().getToken();
132134
String secret = getConfig().getSecret();
135+
net = getConfig().sandbox ? SANDBOX_NET_MAIN : NET_MAIN;
133136
contextManager = APPLICATION.INSTANCE.getContextManager();
134137
contextManager.append(this);
135138
contextManager.append(appid, APPID_ID);
@@ -176,6 +179,7 @@ public void registerEventsRegister(Class<? extends Events.EventRegister> cla) {
176179

177180
@Data
178181
public static class Config {
182+
public boolean sandbox = false;
179183
private String appid;
180184
private String token;
181185
/**
@@ -190,6 +194,13 @@ public static class Config {
190194
private Set<ListenerHost> listenerHosts = new HashSet<>();
191195
private ImageUploadInterceptor interceptor0;
192196
private WebSocketListener webSocketListener;
197+
198+
/**
199+
* 在沙箱环境与正式环境 之前切换 默认正式环境
200+
*/
201+
public void sandbox() {
202+
sandbox = !sandbox;
203+
}
193204
}
194205

195206
public Bot getBot() {

src/main/java/io/github/kloping/qqbot/http/BotBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @author github.kloping
1111
*/
12-
@HttpClient(Starter.NET_MAIN)
12+
@HttpClient(Starter.NET_POINT)
1313
@Headers("io.github.kloping.qqbot.Start0.getHeaders")
1414
public interface BotBase {
1515
/**

src/main/java/io/github/kloping/qqbot/http/ChannelBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* @author github.kloping
1212
*/
13-
@HttpClient(Starter.NET_MAIN)
13+
@HttpClient(Starter.NET_POINT)
1414
@Headers("io.github.kloping.qqbot.Start0.getHeaders")
1515
public interface ChannelBase {
1616
/**

src/main/java/io/github/kloping/qqbot/http/DmsBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* @author github.kloping
1717
*/
18-
@HttpClient(Starter.NET_MAIN)
18+
@HttpClient(Starter.NET_POINT)
1919
@Headers("io.github.kloping.qqbot.Start0.getHeaders")
2020
public interface DmsBase {
2121
/**

src/main/java/io/github/kloping/qqbot/http/GroupBaseV2.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @author github.kloping
1515
*/
16-
@HttpClient(Starter.NET_MAIN)
16+
@HttpClient(Starter.NET_POINT)
1717
@Headers("io.github.kloping.qqbot.Start0.getV2Headers")
1818
public interface GroupBaseV2 extends BaseV2{
1919
/**

src/main/java/io/github/kloping/qqbot/http/GuildBase.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
import io.github.kloping.qqbot.entities.qqpd.Guild;
88
import io.github.kloping.qqbot.entities.qqpd.Member;
99
import io.github.kloping.qqbot.entities.qqpd.Roles;
10-
import org.jsoup.Connection;
1110

1211
import java.util.Map;
1312

1413
/**
1514
* @author github.kloping
1615
*/
17-
@HttpClient(Starter.NET_MAIN)
16+
@HttpClient(Starter.NET_POINT)
1817
@Headers("io.github.kloping.qqbot.Start0.getHeaders")
1918
public interface GuildBase {
2019
/**

src/main/java/io/github/kloping/qqbot/http/InterActionBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* @author github.kloping
99
*/
10-
@HttpClient(Starter.NET_MAIN)
10+
@HttpClient(Starter.NET_POINT)
1111
@Headers("io.github.kloping.qqbot.Start0.getV2Headers")
1212
public interface InterActionBase {
1313
/**

src/main/java/io/github/kloping/qqbot/http/MemberBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* @author github.kloping
1010
*/
11-
@HttpClient(Starter.NET_MAIN)
11+
@HttpClient(Starter.NET_POINT)
1212
@Headers("io.github.kloping.qqbot.Start0.getHeaders")
1313
public interface MemberBase {
1414

src/main/java/io/github/kloping/qqbot/http/MessageBase.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.github.kloping.spt.annotations.http.*;
44
import io.github.kloping.spt.entity.KeyVals;
55
import io.github.kloping.qqbot.Starter;
6-
import io.github.kloping.qqbot.entities.qqpd.message.RawPreMessage;
76
import io.github.kloping.qqbot.http.data.ActionResult;
87

98
import java.util.Map;
@@ -15,7 +14,7 @@
1514
*
1615
* @author github.kloping
1716
*/
18-
@HttpClient(Starter.NET_MAIN)
17+
@HttpClient(Starter.NET_POINT)
1918
@Headers("io.github.kloping.qqbot.Start0.getHeaders")
2019
public interface MessageBase {
2120
/**

src/main/java/io/github/kloping/qqbot/http/UserBase.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
import io.github.kloping.spt.annotations.http.HttpClient;
66
import io.github.kloping.qqbot.entities.qqpd.User;
77

8-
import static io.github.kloping.qqbot.Starter.NET_MAIN;
8+
import static io.github.kloping.qqbot.Starter.NET_POINT;
99

1010
/**
1111
* @author github.kloping
1212
*/
13-
@HttpClient(NET_MAIN)
13+
@HttpClient(NET_POINT)
1414
@Headers("io.github.kloping.qqbot.Start0.getHeaders")
1515
public interface UserBase {
1616
/**
1717
* bot info
1818
*
19-
* @param headers
2019
* @return
2120
*/
2221
@GetPath("/users/@me")

src/main/java/io/github/kloping/qqbot/http/UserBaseV2.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @author github.kloping
1515
*/
16-
@HttpClient(Starter.NET_MAIN)
16+
@HttpClient(Starter.NET_POINT)
1717
@Headers("io.github.kloping.qqbot.Start0.getV2Headers")
1818
public interface UserBaseV2 extends BaseV2 {
1919
/**

src/main/java/io/github/kloping/qqbot/impl/BaseConnectedEvent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public String getClassName() {
4141

4242
@Override
4343
public String toString() {
44-
return String.format("Bot(%s) Connected! By author kloping of bot-qqpd-java for version 1.5.1-R1", bot.getConfig().getAppid());
44+
return String.format("Bot(%s) Connected! By author kloping of bot-qqpd-java for version 1.5.1-R2", bot.getConfig().getAppid());
4545
}
4646
}

0 commit comments

Comments
 (0)