Skip to content

Commit

Permalink
api: 发送Markdown消息
Browse files Browse the repository at this point in the history
  • Loading branch information
RealHeart committed May 11, 2022
1 parent 614e4a2 commit d682287
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
24 changes: 18 additions & 6 deletions qqbot-api/src/main/java/me/zhenxin/qqbot/api/impl/MessageApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
package me.zhenxin.qqbot.api.impl;

import me.zhenxin.qqbot.api.BaseApi;
import me.zhenxin.qqbot.entity.AccessInfo;
import me.zhenxin.qqbot.entity.Message;
import me.zhenxin.qqbot.entity.MessageEmbed;
import me.zhenxin.qqbot.entity.MessageSetting;
import me.zhenxin.qqbot.entity.*;
import me.zhenxin.qqbot.entity.ark.MessageArk;
import me.zhenxin.qqbot.exception.ApiException;

Expand Down Expand Up @@ -93,7 +90,7 @@ public Message sendMessage(String channelId, String content, URL image, String m
* 发送模板(Ark)消息
*
* @param channelId 子频道ID
* @param ark MessageArk对象
* @param ark {@link MessageArk} 对象
* @param messageId 消息ID
* @return {@link Message} 对象
*/
Expand All @@ -108,7 +105,7 @@ public Message sendMessage(String channelId, MessageArk ark, String messageId) t
* 发送 Embed 消息
*
* @param channelId 子频道ID
* @param embed Embed 消息
* @param embed {@link MessageEmbed} 对象
* @param messageId 消息ID
* @return {@link Message} 对象
*/
Expand All @@ -119,6 +116,21 @@ public Message sendMessage(String channelId, MessageEmbed embed, String messageI
return sendMessage(channelId, data);
}

/**
* 发送Markdown消息
*
* @param channelId 子频道ID
* @param markdown {@link MessageMarkdown} 对象
* @param messageId 消息ID
* @return {@link Message} 对象
*/
public Message sendMessage(String channelId, MessageMarkdown markdown, String messageId) throws ApiException {
Map<String, Object> data = new HashMap<>();
data.put("markdown", markdown);
data.put("msg_id", messageId);
return sendMessage(channelId, data);
}

/**
* 撤回消息
*
Expand Down
2 changes: 1 addition & 1 deletion qqbot-sdk/src/test/java/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void main(String[] args) throws InterruptedException {
val handler = new IEventHandler(api);
bot.setEventHandler(handler);
log.info("正在启动中...");
bot.start(0, 2);
bot.start();
// Thread.sleep(2000);
// bot.start(1, 2);
}
Expand Down
6 changes: 6 additions & 0 deletions qqbot-sdk/src/test/java/IEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.zhenxin.qqbot.api.ApiManager;
import me.zhenxin.qqbot.entity.DirectMessageSession;
import me.zhenxin.qqbot.entity.Message;
import me.zhenxin.qqbot.entity.MessageMarkdown;
import me.zhenxin.qqbot.entity.api.ApiPermission;
import me.zhenxin.qqbot.entity.api.ApiPermissionDemand;
import me.zhenxin.qqbot.entity.api.ApiPermissionDemandIdentify;
Expand Down Expand Up @@ -62,6 +63,11 @@ private void message(Message message) {
val args = content.split(" ");
val command = args[0];
switch (command) {
case "md":
MessageMarkdown md = new MessageMarkdown();
md.setContent("测试");
api.getMessageApi().sendMessage(channelId, md, messageId);
break;
case "error":
api.getMessageApi().sendMessage(
channelId,
Expand Down

0 comments on commit d682287

Please sign in to comment.