Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Commit e2b98ca

Browse files
committed
更新
1 parent 6c95c0f commit e2b98ca

File tree

18 files changed

+514
-242
lines changed

18 files changed

+514
-242
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ replay_pid*
2828
.idea/
2929
*.iml
3030
target/
31-
test/
31+
src/test/

README.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,47 @@ JavaDoc:https://qscraft.top/javadoc
77
Dodo开放平台:https://open.imdodo.com/
88

99
### 代码范例
10+
1011
```java
1112
package io.github.minecraftchampions.dodoopenjava.test;
1213

1314
import io.github.minecraftchampions.dodoopenjava.Bot;
1415
import io.github.minecraftchampions.dodoopenjava.DodoOpenJava;
1516
import io.github.minecraftchampions.dodoopenjava.command.CommandExecutor;
16-
import io.github.minecraftchampions.dodoopenjava.command.CommandSender;
17+
import io.github.minecraftchampions.dodoopenjava.api.CommandSender;
1718
import io.github.minecraftchampions.dodoopenjava.event.EventHandler;
1819
import io.github.minecraftchampions.dodoopenjava.event.Listener;
1920
import io.github.minecraftchampions.dodoopenjava.event.events.v2.channelmessage.MessageEvent;
2021

2122
import java.io.IOException;
2223

23-
public class Main implements CommandExecutor,Listener{
24+
public class Main implements CommandExecutor, Listener {
2425
public static Bot bot;
26+
2527
public static void main(String... args) {
2628
//创建机器人实例
27-
bot = DodoOpenJava.createBot("111111","token");
29+
bot = DodoOpenJava.createBot("111111", "token");
2830
//启用日志记录功能
2931
bot.enableApiResultsLogger();
3032
//注册事件监听器
3133
bot.registerListener(new Main());
3234
//注册命令处理器
3335
bot.registerCommand(new Main());
34-
System.out.println(bot.getApi().V2.eventApi.getWebSocketConnection().getJSONObjectData().getString("endpoint"));
36+
// bot.getCommandManager().getCommandTrigger().setCommandHeader("/");;
37+
System.out.println(bot.getApi().V2.eventApi.getWebSocketConnection().getJSONObjectData().getJSONObject("data").getString("endpoint"));
3538
bot.getApi().V2.botApi.getBotInfo().ifSuccess(result -> {
3639
System.out.println("成功");
37-
System.out.println(result.getJSONObjectData());
3840
});
3941

40-
bot.getApi().V2.channelMessageApi.sendTextMessage("1252355","测试");
42+
bot.getApi().V2.channelMessageApi.sendTextMessage("1252355", "测试");
4143
System.out.println(bot.getApiResultsLogger());
4244
}
4345

4446
@EventHandler
4547
public void onEvent(MessageEvent e) {
4648
System.out.println(e.getEventName());
4749
System.out.println(e.getMessageId());
48-
bot.getApi().V2.channelMessageApi.sendTextMessage(e.getChannelId(),"你发送了" + e.getMessageBody());
50+
bot.getApi().V2.channelMessageApi.sendTextMessage(e.getChannelId(), "你发送了" + e.getMessageBody());
4951
}
5052

5153
@Override
@@ -60,14 +62,9 @@ public class Main implements CommandExecutor,Listener{
6062

6163
@Override
6264
public void onCommand(CommandSender commandSender, String[] strings) {
63-
System.out.println(commandSender.getSenderName());
64-
try {
65-
commandSender.editSenderNickName("测试名字");
66-
} catch (IOException e) {
67-
throw new RuntimeException(e);
68-
}
69-
bot.getApi().V2.channelMessageApi.sendTextMessage(commandSender.getChannelId(),"测试成功");
70-
65+
System.out.println(commandSender.getName());
66+
commandSender.editNickName("测试名字");
67+
bot.getApi().V2.channelMessageApi.sendTextMessage(commandSender.getChannelId(), "测试成功");
7168
}
7269
}
7370

@@ -96,7 +93,7 @@ public class Main implements CommandExecutor,Listener{
9693
<dependency>
9794
<groupId>top.qscraft</groupId>
9895
<artifactId>dodoopenjava</artifactId>
99-
<version>3.2.5-SNAPSHOT</version>
96+
<version>3.2.5</version>
10097
</dependency>
10198
</dependencies>
10299
```
@@ -109,7 +106,7 @@ public class Main implements CommandExecutor,Listener{
109106
}
110107
111108
dependencies {
112-
implementation 'top.qscraft:dodoopenjava:3.2.5-SNAPSHOT'
109+
implementation 'top.qscraft:dodoopenjava:3.2.5'
113110
}
114111
```
115112
### 教程(过于古老,无参考价值,改日重写)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<groupId>io.github.minecraftchampions.dodoopenjava</groupId>
1515
<artifactId>DodoOpenJava</artifactId>
16-
<version>3.2.5-SNAPSHOT</version>
16+
<version>3.2.5</version>
1717
<packaging>jar</packaging>
1818
<name>DodoOpenJava</name>
1919

src/main/java/io/github/minecraftchampions/dodoopenjava/Bot.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package io.github.minecraftchampions.dodoopenjava;
22

3+
import io.github.minecraftchampions.dodoopenjava.api.User;
34
import io.github.minecraftchampions.dodoopenjava.command.CommandExecutor;
45
import io.github.minecraftchampions.dodoopenjava.command.CommandManager;
5-
import io.github.minecraftchampions.dodoopenjava.event.EventManager;
66
import io.github.minecraftchampions.dodoopenjava.event.AbstractEventTrigger;
7+
import io.github.minecraftchampions.dodoopenjava.event.EventManager;
78
import io.github.minecraftchampions.dodoopenjava.event.Listener;
89
import io.github.minecraftchampions.dodoopenjava.event.WebSocketEventTrigger;
10+
import io.github.minecraftchampions.dodoopenjava.impl.DodoUserImpl;
911
import io.github.minecraftchampions.dodoopenjava.message.Message;
1012
import io.github.minecraftchampions.dodoopenjava.message.card.CardMessage;
1113
import io.github.minecraftchampions.dodoopenjava.message.text.TextMessage;
@@ -539,6 +541,11 @@ public Result getMemberInfo(String islandSourceId, String dodoSourceId) {
539541
return io.github.minecraftchampions.dodoopenjava.api.v2.MemberApi.getMemberInfo(bot.getAuthorization(), islandSourceId, dodoSourceId);
540542
}
541543

544+
@SneakyThrows
545+
public User getUser(String islandSourceId, String dodoSourceId) {
546+
return new DodoUserImpl(dodoSourceId, islandSourceId, bot);
547+
}
548+
542549
@SneakyThrows
543550
public Result editMemberNickName(String islandSourceId, String dodoSourceId, String nickName) {
544551
return io.github.minecraftchampions.dodoopenjava.api.v2.MemberApi.editMemberNickName(bot.getAuthorization(), islandSourceId, dodoSourceId, nickName);
@@ -569,6 +576,12 @@ public Result addMemberReasonBan(String islandSourceId, String dodoSourceId, Str
569576
return io.github.minecraftchampions.dodoopenjava.api.v2.MemberApi.addMemberReasonBan(bot.getAuthorization(), islandSourceId, dodoSourceId, reason);
570577
}
571578

579+
@SneakyThrows
580+
public Result addMemberReasonChannelBan(String islandSourceId, String dodoSourceId, String reason, String noticeChannelId) {
581+
return io.github.minecraftchampions.dodoopenjava.api.v2.MemberApi.addMemberReasonChannelBan(bot.getAuthorization(), islandSourceId, dodoSourceId, reason, noticeChannelId);
582+
}
583+
584+
572585
@SneakyThrows
573586
public Result getMemberDodoIdMapList(List<String> strList) {
574587
return io.github.minecraftchampions.dodoopenjava.api.v2.MemberApi.getMemberDodoIdMapList(bot.getAuthorization(), strList);
@@ -623,6 +636,10 @@ public Result sendDodoVideoMessage(String islandSourceId, String dodoSourceId, S
623636
return io.github.minecraftchampions.dodoopenjava.api.v2.PersonalApi.sendDodoVideoMessage(bot.getAuthorization(), islandSourceId, dodoSourceId, u);
624637
}
625638

639+
@SneakyThrows
640+
public Result sendMessage(String islandSourceId, String dodoSourceId, Message message) {
641+
return io.github.minecraftchampions.dodoopenjava.api.v2.PersonalApi.sendMessage(bot.getAuthorization(), islandSourceId, dodoSourceId, message);
642+
}
626643
}
627644

628645
public class RoleApi {

src/main/java/io/github/minecraftchampions/dodoopenjava/Result.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import lombok.Getter;
44
import lombok.NonNull;
5-
import org.json.JSONArray;
65
import org.json.JSONObject;
76

87
import java.util.function.Consumer;
8+
import java.util.function.Function;
99

1010
/**
1111
* api结果
@@ -91,18 +91,13 @@ public class Result {
9191

9292
private final long timestamp;
9393

94-
private final JSONObject jsonObjectData;
95-
96-
private Object data;
94+
private final JSONObject JSONObjectData;
9795

9896
private Result(@NonNull JSONObject jsonObject) {
99-
this.jsonObjectData = jsonObject;
97+
this.JSONObjectData = jsonObject;
10098
this.statusCode = jsonObject.getInt("status");
10199
this.message = jsonObject.getString("message");
102100
this.timestamp = System.currentTimeMillis();
103-
if (statusCode == 0) {
104-
this.data = jsonObject.get("data");
105-
}
106101
}
107102

108103
/**
@@ -142,33 +137,36 @@ public Result ifFailure(@NonNull Consumer<Result> consumer) {
142137
}
143138

144139
/**
145-
* 获取
140+
* 如果成功
146141
*
147-
* @return jsonObject
142+
* @param function function
143+
* @return this
148144
*/
149-
public JSONObject getJSONObjectData() {
150-
if (data instanceof JSONObject jsonObject) {
151-
return jsonObject;
145+
public <T> T ifSuccess(@NonNull Function<Result, T> function) {
146+
if (statusCode == 0) {
147+
return function.apply(this);
152148
} else {
153-
return new JSONObject();
149+
return null;
154150
}
155151
}
156152

157153
/**
158-
* 获取
154+
* 如果失败
159155
*
160-
* @return jsonArray
156+
* @param function function
157+
* @return this
161158
*/
162-
public JSONArray getJSONArrayData() {
163-
if (data instanceof JSONArray jsonArray) {
164-
return jsonArray;
159+
public <T> T ifFailure(@NonNull Function<Result, T> function) {
160+
if (statusCode != 0) {
161+
return function.apply(this);
165162
} else {
166-
return new JSONArray();
163+
return null;
167164
}
168165
}
169166

167+
170168
@Override
171169
public String toString() {
172-
return jsonObjectData.toString();
170+
return getJSONObjectData().toString();
173171
}
174172
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.minecraftchampions.dodoopenjava.api;
2+
3+
import io.github.minecraftchampions.dodoopenjava.message.text.TextMessage;
4+
5+
/**
6+
* 命令发送者接口
7+
*/
8+
public interface CommandSender extends User {
9+
void editMessage(TextMessage message);
10+
11+
String getChannelId();
12+
13+
String getMessageId();
14+
15+
boolean isPersonalChat();
16+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package io.github.minecraftchampions.dodoopenjava.api;
2+
3+
import io.github.minecraftchampions.dodoopenjava.message.Message;
4+
import lombok.NonNull;
5+
6+
/**
7+
* 用户接口
8+
*/
9+
public interface User {
10+
String getIslandSourceId();
11+
12+
String getDodoSourceId();
13+
14+
String getNickName();
15+
16+
String getName();
17+
18+
String getAvatarUrl();
19+
20+
String getJoinTime();
21+
22+
int getSex();
23+
24+
int getLevel();
25+
26+
int getIsBot();
27+
28+
int getOnlineDevice();
29+
30+
int getOnlineStatus();
31+
32+
String getInviterDodoSourceId();
33+
34+
void editNickName(@NonNull String nickName);
35+
36+
void mute(int mills);
37+
38+
void mute(int mills, @NonNull String reason);
39+
40+
int getInvitationCount();
41+
42+
/**
43+
* 封禁成员,传null视作不传参
44+
*/
45+
void ban(String reason, String noticeChannelId);
46+
47+
void unmute();
48+
49+
void unban();
50+
51+
void addRole(@NonNull String roleId);
52+
53+
void removeRole(@NonNull String roleId);
54+
55+
long getIntegralBalance();
56+
57+
void editIntegral(int type, long integral);
58+
59+
void addIntegral(long integral);
60+
61+
void removeIntegral(long integral);
62+
63+
String sendPersonalMessage(@NonNull Message message);
64+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
2-
* Dodo开放平台各个版本的接口
2+
* API
33
*/
44
package io.github.minecraftchampions.dodoopenjava.api;

src/main/java/io/github/minecraftchampions/dodoopenjava/api/v2/MemberApi.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,44 @@ public static Result addMemberReasonBan(String authorization, String islandSourc
342342

343343
}
344344

345+
/**
346+
* 永久封禁成员
347+
*
348+
* @param clientId 机器人唯一标识
349+
* @param token 机器人鉴权Token
350+
* @param islandSourceId 群号
351+
* @param noticeChannelId 提醒频道ID
352+
* @param dodoSourceId Dodo号
353+
* @param reason 封禁理由
354+
* @return JSON对象
355+
* @throws IOException 失败后抛出
356+
*/
357+
public static Result addMemberReasonChannelBan(String clientId, String token, String islandSourceId, String dodoSourceId, String reason, String noticeChannelId) throws IOException {
358+
return addMemberReasonChannelBan(BaseUtil.Authorization(clientId, token), islandSourceId, dodoSourceId, reason, noticeChannelId);
359+
}
360+
361+
/**
362+
* 永久封禁成员
363+
*
364+
* @param authorization authorization
365+
* @param islandSourceId 群号
366+
* @param dodoSourceId Dodo号
367+
* @param reason 封禁理由
368+
* @param noticeChannelId 提醒频道ID
369+
* @return JSON对象
370+
* @throws IOException 失败后抛出
371+
*/
372+
public static Result addMemberReasonChannelBan(String authorization, String islandSourceId, String dodoSourceId, String reason, String noticeChannelId) throws IOException {
373+
String url = DodoOpenJava.BASEURL + "member/ban/add";
374+
JSONObject jsonObject = new JSONObject();
375+
jsonObject.put("islandSourceId", islandSourceId)
376+
.put("dodoSourceId", dodoSourceId)
377+
.put("reason", reason)
378+
.put("noticeChannelId", noticeChannelId);
379+
return NetUtil.sendRequest(jsonObject.toString(), url, authorization);
380+
381+
}
382+
345383
/**
346384
* 永久封禁成员
347385
*
@@ -447,10 +485,9 @@ public static Result removeMemberBan(String authorization, String islandSourceId
447485
/**
448486
* 获取成员DoDo号映射列表
449487
*
450-
* @param clientId 机器人唯一标识
451-
* @param token 机器人鉴权Token
452-
453-
* @param dodoIdList dodoId
488+
* @param clientId 机器人唯一标识
489+
* @param token 机器人鉴权Token
490+
* @param dodoIdList dodoId
454491
* @return JSON对象
455492
* @throws IOException 失败后抛出
456493
*/
@@ -461,8 +498,8 @@ public static Result getMemberDodoIdMapList(String clientId, String token, List<
461498
/**
462499
* 获取成员DoDo号映射列表
463500
*
464-
* @param authorization authorization
465-
* @param dodoIdList dodoId
501+
* @param authorization authorization
502+
* @param dodoIdList dodoId
466503
* @return JSON对象
467504
* @throws IOException 失败后抛出
468505
*/

0 commit comments

Comments
 (0)