|
1 | 1 | # DodoOpenJava <img src="https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=java&logoColor=white" alt="Java"> [](https://jitpack.io/#top.qscraft/dodoopenjava) |
2 | 2 |
|
3 | | -Dodo开放平台的JavaSDK |
4 | | - |
5 | | -JavaDoc:https://qscraft.top/javadoc |
6 | | - |
7 | | -Dodo开放平台:https://open.imdodo.com/ |
8 | | - |
9 | | -### 代码范例 |
10 | | - |
11 | | -```java |
12 | | -import io.github.minecraftchampions.dodoopenjava.DodoOpenJava; |
13 | | -import io.github.minecraftchampions.dodoopenjava.command.CommandExecutor; |
14 | | -import io.github.minecraftchampions.dodoopenjava.api.CommandSender; |
15 | | -import io.github.minecraftchampions.dodoopenjava.event.EventHandler; |
16 | | -import io.github.minecraftchampions.dodoopenjava.event.Listener; |
17 | | -import io.github.minecraftchampions.dodoopenjava.event.events.v2.channelmessage.MessageEvent; |
18 | | -import io.github.minecraftchampions.dodoopenjava.api.Bot; |
19 | | - |
20 | | -public class Main implements CommandExecutor, Listener { |
21 | | - public static Bot bot; |
22 | | - |
23 | | - public static void main(String... args) { |
24 | | - // 创建机器人实例 |
25 | | - bot = DodoOpenJava.createBot("111111", "token"); |
26 | | - // 采用WebHook监听事件 |
27 | | - // WebHookEventTrigger webHookEventTrigger = new WebHookEventTrigger(bot,"密钥","ssl证书密码",new File("C:\\abc.com.jks")); |
28 | | - // bot.initEventListenSystem(webHookEventTrigger); |
29 | | - //启用日志记录功能 |
30 | | - bot.enableDebugMode(); |
31 | | - // 注册事件监听器 |
32 | | - bot.registerListener(new Main()); |
33 | | - // 注册命令处理器 |
34 | | - bot.registerCommand(new Main()); |
35 | | - // bot.getCommandManager().getCommandTrigger().setCommandHeader("/");; |
36 | | - System.out.println(bot.getApi().getEventApi().getWebSocketConnection().getData().getJSONObject("data").getString("endpoint")); |
37 | | - bot.getApi().getBotApi().getBotInfo().ifSuccess(result -> { |
38 | | - System.out.println("成功"); |
39 | | - }); |
40 | | - |
41 | | - bot.getApi().getChannelMessageApi().sendTextMessage("1252355", "测试"); |
42 | | - testCard(); |
43 | | - } |
44 | | - |
45 | | - static void testCard() { |
46 | | - SectionComponent normalSection = SectionComponent.of("卡片消息文本测试1"); |
47 | | - SectionComponent paragraphText = SectionComponent.of("卡片消息多栏文本测试1", |
48 | | - "卡片消息多栏文本测试2"); |
49 | | - ImageElement imageElement1 = ImageElement.of("https://img.imdodo.com/upload/cdn/09151DF5C726C6E2F5915E5B117EF98E_1660189645615.png"); |
50 | | - ImageComponent imageComponent1 = ImageComponent.of(imageElement1); |
51 | | - ImageElement imageElement2 = ImageElement.of("https://img.imdodo.com/upload/cdn/09151DF5C726C6E2F5915E5B117EF98E_1660189645615.png"); |
52 | | - ImageGroupComponent imageGroupComponent = ImageGroupComponent.of(imageElement1, imageElement2); |
53 | | - SectionWithModuleComponent moduleComponent1 = SectionWithModuleComponent.of("文字+模块测试1", imageElement1); |
54 | | - HeaderComponent headerComponent = HeaderComponent.of("***标题测试***", TextType.Markdown); |
55 | | - RemarkComponent remarkComponent = RemarkComponent.of(imageElement1, imageElement2, TextElement.newNormalText("备注文本测试")); |
56 | | - VideoComponent videoComponent = VideoComponent.of("屏幕内覆盖视频地址", "https://img.imdodo.com/dodo/2493bf9b000b8dc18e77d079ac517bb9.png", "https://video.imdodo.com/dodo/7f0a1979c818fa05cf7bdeae20aad24b.mp4"); |
57 | | - CountdownComponent countdownComponent = CountdownComponent.of(CountdownStyle.Day, 1760644927968L); |
58 | | - OptionElement optionElement1 = OptionElement.of("选项1", "一个选项"); |
59 | | - OptionElement optionElement2 = OptionElement.of("选项2"); |
60 | | - ListSelectorComponent listSelectorComponent = ListSelectorComponent.of(1, 2, "id", "请选择", optionElement1, optionElement2); |
61 | | - InputElement inputElement1 = InputElement.of("title1", "input1", 2, 1, 2500, "请输入"); |
62 | | - InputElement inputElement2 = InputElement.of("title2", "input2", 2, 1, 2500); |
63 | | - Form form = Form.of("title"); |
64 | | - form.append(inputElement1).append(inputElement2); |
65 | | - ButtonElement.Action action1 = ButtonElement.Action.form(form); |
66 | | - ButtonElement.Action action2 = ButtonElement.Action.of(ActionType.link_url); |
67 | | - action2.setValue("https://github.com"); |
68 | | - ButtonElement.Action action3 = ButtonElement.Action.of(ActionType.copy_content); |
69 | | - action3.setValue("复制"); |
70 | | - ButtonElement.Action action4 = ButtonElement.Action.of(ActionType.call_back); |
71 | | - action4.setValue("message"); |
72 | | - ButtonElement buttonElement1 = ButtonElement.of(ButtonColor.Blue, "跳转", action2); |
73 | | - ButtonElement buttonElement2 = ButtonElement.of(ButtonColor.Grey, "表单", action1); |
74 | | - ButtonElement buttonElement3 = ButtonElement.of(ButtonColor.Green, "复制", action3); |
75 | | - ButtonElement buttonElement4 = ButtonElement.of(ButtonColor.Orange, "回传", action4); |
76 | | - SectionWithModuleComponent moduleComponent2 = SectionWithModuleComponent.of("文字+模块测试2", buttonElement3); |
77 | | - ButtonGroupComponent buttonGroupComponent = ButtonGroupComponent.of(buttonElement1, buttonElement2, buttonElement3, buttonElement4); |
78 | | - CardMessage.Builder builder = CardMessage.builder(); |
79 | | - CardMessage m = builder.content("Dodo卡片消息附加文本测试").title("Dodo卡片消息标题测试").theme(Theme.Black) |
80 | | - .button(buttonGroupComponent).header(headerComponent).section(normalSection) |
81 | | - .section(paragraphText).image(imageComponent1).images(imageGroupComponent).divider() |
82 | | - .remark(remarkComponent).countdown(countdownComponent).video(videoComponent) |
83 | | - .button(buttonGroupComponent).section(moduleComponent1).listSelector(listSelectorComponent) |
84 | | - .section(moduleComponent2).build(); |
85 | | - bot.getApi().getChannelMessageApi().sendMessage("1252355", m); |
86 | | - } |
87 | | - |
88 | | - @EventHandler |
89 | | - public void onEvent(MessageEvent e) { |
90 | | - System.out.println(e.getEventName()); |
91 | | - System.out.println(e.getMessageId()); |
92 | | - bot.getApi().getChannelMessageApi().sendTextMessage(e.getChannelId(), "你发送了" + e.getMessageBody()); |
93 | | - } |
94 | | - |
95 | | - @Override |
96 | | - public String getMainCommand() { |
97 | | - return "test"; |
98 | | - } |
99 | | - |
100 | | - @Override |
101 | | - public String getPermission() { |
102 | | - return null; |
103 | | - } |
104 | | - |
105 | | - @Override |
106 | | - public void onCommand(CommandSender commandSender, String[] strings) { |
107 | | - System.out.println(commandSender.getName()); |
108 | | - commandSender.editNickName("测试名字"); |
109 | | - bot.getApi().getChannelMessageApi().sendTextMessage(commandSender.getChannelId(), "测试成功"); |
110 | | - } |
111 | | -} |
112 | | - |
113 | | -``` |
114 | | -### 计划 |
115 | | -- [X] 减小大小 |
116 | | -- [X] 重构卡片消息 |
117 | | -- [ ] 将卡片回传参数处理包含在卡片消息部分 |
118 | | - |
119 | | -### 添加依赖 |
120 | | -#### Maven: |
121 | | -```xml |
122 | | -<repositories> |
123 | | - <repository> |
124 | | - <id>jitpack.io</id> |
125 | | - <url>https://jitpack.io</url> |
126 | | - </repository> |
127 | | -</repositories> |
128 | | -``` |
129 | | -```xml |
130 | | -<dependencies> |
131 | | - <dependency> |
132 | | - <groupId>icu.qscraft</groupId> |
133 | | - <artifactId>dodoopenjava</artifactId> |
134 | | - <version>3.3.2</version> |
135 | | - </dependency> |
136 | | -</dependencies> |
137 | | -``` |
138 | | -#### Gradle |
139 | | -```groovy |
140 | | -allprojects { |
141 | | - repositories { |
142 | | - maven { url 'https://jitpack.io' } |
143 | | - } |
144 | | -} |
145 | | -
|
146 | | -dependencies { |
147 | | - implementation 'icu.qscraft:dodoopenjava:3.3.2' |
148 | | -} |
149 | | -``` |
150 | | -### 教程(过于古老,无参考价值,改日重写) |
151 | | -[直达链接](https://www.showdoc.com.cn/DodoOpenJava/) |
152 | | - |
| 3 | +随着Dodo的停止运营(~~跑路~~) |
| 4 | +本项目也跑路了哈哈 |
0 commit comments