Skip to content

Commit

Permalink
common: 消息相关对象补充
Browse files Browse the repository at this point in the history
api: 消息相关API补充
  • Loading branch information
RealHeart committed May 10, 2022
1 parent 3714fe1 commit 891cf4e
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ public Message sendMessage(String guildId, MessageEmbed embed, String messageId)
return sendMessage(guildId, data);
}

/**
* 撤回消息
*
* @param guildId 频道ID
* @param messageId 消息ID
* @param hidetip 是否隐藏撤回提示
*/
public void deleteMessage(String guildId, String messageId, boolean hidetip) throws ApiException {
Map<String, Object> data = new HashMap<>();
data.put("hidetip", hidetip);
delete("/guilds/" + guildId + "/messages/" + messageId, data);
}

/**
* 发送消息
*
* @param guildId 频道ID
* @param data 消息数据
* @return {@link Message} 对象
*/
private Message sendMessage(String guildId, Map<String, Object> data) {
return post("/dms/" + guildId + "/messages", data, Message.class);
}
Expand Down
83 changes: 18 additions & 65 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 @@ -22,10 +22,10 @@
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.ark.MessageArk;
import me.zhenxin.qqbot.exception.ApiException;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -48,7 +48,7 @@ public MessageApi(AccessInfo accessInfo) {
* @param channelId 子频道ID
* @param content 文本内容
* @param messageId 消息ID
* @return 消息对象
* @return {@link Message} 对象
*/
public Message sendMessage(String channelId, String content, String messageId) throws ApiException {
Map<String, Object> data = new HashMap<>();
Expand All @@ -63,7 +63,7 @@ public Message sendMessage(String channelId, String content, String messageId) t
* @param channelId 子频道ID
* @param image 图片URL
* @param messageId 消息ID
* @return 消息对象
* @return {@link Message} 对象
*/
public Message sendMessage(String channelId, URL image, String messageId) throws ApiException {
Map<String, Object> data = new HashMap<>();
Expand All @@ -79,7 +79,7 @@ public Message sendMessage(String channelId, URL image, String messageId) throws
* @param content 文本内容
* @param image 图片URL
* @param messageId 消息ID
* @return 消息对象
* @return {@link Message} 对象
*/
public Message sendMessage(String channelId, String content, URL image, String messageId) throws ApiException {
Map<String, Object> data = new HashMap<>();
Expand All @@ -95,7 +95,7 @@ public Message sendMessage(String channelId, String content, URL image, String m
* @param channelId 子频道ID
* @param ark MessageArk对象
* @param messageId 消息ID
* @return 消息对象
* @return {@link Message} 对象
*/
public Message sendMessage(String channelId, MessageArk ark, String messageId) throws ApiException {
Map<String, Object> data = new HashMap<>();
Expand All @@ -110,7 +110,7 @@ public Message sendMessage(String channelId, MessageArk ark, String messageId) t
* @param channelId 子频道ID
* @param embed Embed 消息
* @param messageId 消息ID
* @return 消息对象
* @return {@link Message} 对象
*/
public Message sendMessage(String channelId, MessageEmbed embed, String messageId) throws ApiException {
Map<String, Object> data = new HashMap<>();
Expand All @@ -130,81 +130,34 @@ public void deleteMessage(String channelId, String messageId) throws ApiExceptio
}

/**
* 发送文本消息
*
* @param channelId 子频道ID
* @param content 文本内容
* @param messageId 消息ID
* @return 消息对象
* @deprecated 使用 {@link #sendMessage(String, String, String)} 替代
*/
public Message sendTextMessage(String channelId, String content, String messageId) throws ApiException {
return sendMessage(channelId, content, messageId);
}

/**
* 发送模板(Ark)消息
*
* @param channelId 子频道ID
* @param ark MessageArk对象
* @param messageId 消息ID
* @return 消息对象
* @deprecated 使用 {@link #sendMessage(String, MessageArk, String)} 替代
*/
public Message sendTemplateMessage(String channelId, MessageArk ark, String messageId) throws ApiException {
return sendMessage(channelId, ark, messageId);
}

/**
* 发送图片消息
* 获取指定消息
*
* @param channelId 子频道ID
* @param image 图片URL
* @param messageId 消息ID
* @return 消息对象
* @deprecated 使用 {@link #sendMessage(String, URL, String)} 替代
* @return {@link Message} 对象
*/
public Message sendImageMessage(String channelId, String image, String messageId) throws ApiException {
try {
return sendMessage(channelId, new URL(image), messageId);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
public Message getMessageInfo(String channelId, String messageId) {
return get("/channels/" + channelId + "/messages/" + messageId, Message.class);
}

/**
* 发送文本和图片消息
* 获取频道消息频率设置
*
* @param channelId 子频道ID
* @param content 文本内容
* @param image 图片URL
* @param messageId 消息ID
* @return 消息对象
* @deprecated 使用 {@link #sendMessage(String, String, URL, String)} 替代
* @param guildId 频道ID
* @return @{@link MessageSetting} 对象
*/
public Message sendTextAndImageMessage(String channelId, String content, String image, String messageId) throws ApiException {
try {
return sendMessage(channelId, content, new URL(image), messageId);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
public MessageSetting getMessageSetting(String guildId) {
return get("/guilds/" + guildId + "/message/setting", MessageSetting.class);
}


/**
* 获取指定消息
* 发送消息
*
* @param channelId 子频道ID
* @param messageId 消息ID
* @return 消息对象
* @param data 消息数据
* @return {@link Message} 对象
*/
public Message getMessageInfo(String channelId, String messageId) {
return get("/channels/" + channelId + "/messages/" + messageId, Message.class);
}


private Message sendMessage(String channelId, Map<String, Object> data) {
return post("/channels/" + channelId + "/messages", data, Message.class);
}
Expand Down
20 changes: 20 additions & 0 deletions qqbot-common/src/main/java/me/zhenxin/qqbot/entity/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,24 @@ public class Message {
* Ark消息
*/
private MessageArk ark;
/**
* 消息序号
* <p>
* 子频道消息的序号,用于消息间的排序。<br/>
* 在同一子频道中按从先到后的顺序递增。<br/>
* 不同的子频道之间消息无法排序。
* </p>
*/
private String seqInChannel;
/**
* 引用消息
*/
private MessageReference messageReference;
/**
* 来源频道ID
* <p>
* 用于私信场景下识别真实的来源频道。
* </p>
*/
private String srcGuildId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* qq-official-bot-sdk - QQ Official Bot SDK For Java
* Copyright (C) 2021-2022 xiaoye-bot Project Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.zhenxin.qqbot.entity;

import lombok.Data;

/**
* 删除消息对象
*
* @author 真心
* @since 2022/5/11 2:38
*/
@Data
public class MessageDelete {
/**
* 被删除的消息
*/
private Message message;
/**
* 操作用户
*/
private User opUser;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* qq-official-bot-sdk - QQ Official Bot SDK For Java
* Copyright (C) 2021-2022 xiaoye-bot Project Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.zhenxin.qqbot.entity;

import lombok.Data;

/**
* Keyboard消息
*
* @author 真心
* @since 2022/5/11 2:40
*/
@Data
public class MessageKeyboard {
/**
* 模板ID
*/
private String id;
/**
* Keyboard内容
*/
private String content; // 官方文档中没有该字段类型(InlineKeyboard) 待确认
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* qq-official-bot-sdk - QQ Official Bot SDK For Java
* Copyright (C) 2021-2022 xiaoye-bot Project Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.zhenxin.qqbot.entity;

import lombok.Data;

/**
* Markdown消息对象
*
* @author 真心
* @since 2022/5/11 2:35
*/
@Data
public class MessageMarkdown {
/**
* 模板ID
*/
private String templateId;
/**
* 模板参数
*/
private MessageMarkdownParams params;
/**
* 消息内容
*/
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* qq-official-bot-sdk - QQ Official Bot SDK For Java
* Copyright (C) 2021-2022 xiaoye-bot Project Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.zhenxin.qqbot.entity;

import lombok.Data;

/**
* Markdown消息参数
*
* @author 真心
* @since 2022/5/11 2:36
*/
@Data
public class MessageMarkdownParams {
/**
* Markdown模版的Key值
*/
private String key;
/**
* Markdown模版的参数
*/
private String[] values;
}
Loading

0 comments on commit 891cf4e

Please sign in to comment.