feat: forward single msg

This commit is contained in:
linyuchen 2024-04-25 23:24:58 +08:00
parent 5562a3251d
commit 3ae2d2a1e6
3 changed files with 109 additions and 52 deletions

View File

@ -14,7 +14,11 @@ import GetVersionInfo from "./system/GetVersionInfo";
import CanSendRecord from "./system/CanSendRecord"; import CanSendRecord from "./system/CanSendRecord";
import CanSendImage from "./system/CanSendImage"; import CanSendImage from "./system/CanSendImage";
import GetStatus from "./system/GetStatus"; import GetStatus from "./system/GetStatus";
import {GoCQHTTPSendForwardMsg, GoCQHTTPSendGroupForwardMsg, GoCQHTTPSendPrivateForwardMsg} from "./go-cqhttp/SendForwardMsg"; import {
GoCQHTTPSendForwardMsg,
GoCQHTTPSendGroupForwardMsg,
GoCQHTTPSendPrivateForwardMsg
} from "./go-cqhttp/SendForwardMsg";
import GoCQHTTPGetStrangerInfo from "./go-cqhttp/GetStrangerInfo"; import GoCQHTTPGetStrangerInfo from "./go-cqhttp/GetStrangerInfo";
import SendLike from "./user/SendLike"; import SendLike from "./user/SendLike";
import SetGroupAddRequest from "./group/SetGroupAddRequest"; import SetGroupAddRequest from "./group/SetGroupAddRequest";
@ -32,7 +36,7 @@ import GetImage from "./file/GetImage";
import GetRecord from "./file/GetRecord"; import GetRecord from "./file/GetRecord";
import GoCQHTTPMarkMsgAsRead from "./msg/MarkMsgAsRead"; import GoCQHTTPMarkMsgAsRead from "./msg/MarkMsgAsRead";
import CleanCache from "./system/CleanCache"; import CleanCache from "./system/CleanCache";
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile"; import {GoCQHTTPUploadGroupFile, GoCQHTTPUploadPrivateFile} from "./go-cqhttp/UploadGroupFile";
import {GetConfigAction, SetConfigAction} from "./llonebot/Config"; import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest"; import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
import SetQQAvatar from './llonebot/SetQQAvatar' import SetQQAvatar from './llonebot/SetQQAvatar'
@ -41,62 +45,67 @@ import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
import GetFile from "./file/GetFile"; import GetFile from "./file/GetFile";
import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg"; import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg";
import {GetCookies} from "./user/GetCookie"; import {GetCookies} from "./user/GetCookie";
import {SetMsgEmojiLike} from "./msg/SetMsgEmojiLike";
import {ForwardFriendSingleMsg, ForwardSingleGroupMsg} from "./msg/ForwardSingleMsg";
export const actionHandlers = [ export const actionHandlers = [
new GetFile(), new GetFile(),
new Debug(), new Debug(),
new GetConfigAction(), new GetConfigAction(),
new SetConfigAction(), new SetConfigAction(),
new GetGroupAddRequest(), new GetGroupAddRequest(),
new SetQQAvatar(), new SetQQAvatar(),
// onebot11 // onebot11
new SendLike(), new SendLike(),
new GetMsg(), new GetMsg(),
new GetLoginInfo(), new GetLoginInfo(),
new GetFriendList(), new GetFriendList(),
new GetGroupList(), new GetGroupInfo(), new GetGroupMemberList(), new GetGroupMemberInfo(), new GetGroupList(), new GetGroupInfo(), new GetGroupMemberList(), new GetGroupMemberInfo(),
new SendGroupMsg(), new SendPrivateMsg(), new SendMsg(), new SendGroupMsg(), new SendPrivateMsg(), new SendMsg(),
new DeleteMsg(), new DeleteMsg(),
new SetGroupAddRequest(), new SetGroupAddRequest(),
new SetFriendAddRequest(), new SetFriendAddRequest(),
new SetGroupLeave(), new SetGroupLeave(),
new GetVersionInfo(), new GetVersionInfo(),
new CanSendRecord(), new CanSendRecord(),
new CanSendImage(), new CanSendImage(),
new GetStatus(), new GetStatus(),
new SetGroupWholeBan(), new SetGroupWholeBan(),
new SetGroupBan(), new SetGroupBan(),
new SetGroupKick(), new SetGroupKick(),
new SetGroupAdmin(), new SetGroupAdmin(),
new SetGroupName(), new SetGroupName(),
new SetGroupCard(), new SetGroupCard(),
new GetImage(), new GetImage(),
new GetRecord(), new GetRecord(),
new CleanCache(), new CleanCache(),
new GetCookies(), new GetCookies(),
//以下为go-cqhttp api new SetMsgEmojiLike(),
new GoCQHTTPSendForwardMsg(), new ForwardFriendSingleMsg(),
new GoCQHTTPSendGroupForwardMsg(), new ForwardSingleGroupMsg(),
new GoCQHTTPSendPrivateForwardMsg(), //以下为go-cqhttp api
new GoCQHTTPGetStrangerInfo(), new GoCQHTTPSendForwardMsg(),
new GoCQHTTPDownloadFile(), new GoCQHTTPSendGroupForwardMsg(),
new GetGuildList(), new GoCQHTTPSendPrivateForwardMsg(),
new GoCQHTTPMarkMsgAsRead(), new GoCQHTTPGetStrangerInfo(),
new GoCQHTTPUploadGroupFile(), new GoCQHTTPDownloadFile(),
new GoCQHTTPGetGroupMsgHistory(), new GetGuildList(),
new GoCQHTTGetForwardMsgAction(), new GoCQHTTPMarkMsgAsRead(),
new GoCQHTTPUploadGroupFile(),
new GoCQHTTPUploadPrivateFile(),
new GoCQHTTPGetGroupMsgHistory(),
new GoCQHTTGetForwardMsgAction(),
] ]
function initActionMap() { function initActionMap() {
const actionMap = new Map<string, BaseAction<any, any>>(); const actionMap = new Map<string, BaseAction<any, any>>();
for (const action of actionHandlers) { for (const action of actionHandlers) {
actionMap.set(action.actionName, action); actionMap.set(action.actionName, action);
actionMap.set(action.actionName + '_async', action); actionMap.set(action.actionName + '_async', action);
actionMap.set(action.actionName + '_rate_limited', action); actionMap.set(action.actionName + '_rate_limited', action);
} }
return actionMap return actionMap
} }
export const actionMap = initActionMap(); export const actionMap = initActionMap();

View File

@ -0,0 +1,44 @@
import BaseAction from "../BaseAction";
import {NTQQMsgApi, Peer} from "../../../ntqqapi/api";
import {ChatType, RawMessage} from "../../../ntqqapi/types";
import {dbUtil} from "../../../common/db";
import {getUidByUin} from "../../../common/data";
import {ActionName} from "../types";
interface Payload {
message_id: number
group_id: number
user_id?: number
}
class ForwardSingleMsg extends BaseAction<Payload, null> {
protected async getTargetPeer(payload: Payload): Promise<Peer> {
if (payload.user_id){
return {chatType: ChatType.friend, peerUid: getUidByUin(payload.user_id.toString())}
}
return {chatType: ChatType.group, peerUid: payload.group_id.toString()}
}
protected async _handle(payload: Payload): Promise<null> {
const msg = await dbUtil.getMsgByShortId(payload.message_id)
const peer = await this.getTargetPeer(payload);
await NTQQMsgApi.forwardMsg({
chatType: msg.chatType,
peerUid: msg.peerUid
},
peer,
[msg.msgId]
)
return null;
}
}
export class ForwardFriendSingleMsg extends ForwardSingleMsg {
actionName = ActionName.ForwardFriendSingleMsg
}
export class ForwardSingleGroupMsg extends ForwardSingleMsg {
actionName = ActionName.ForwardGroupSingleMsg
}

View File

@ -34,6 +34,7 @@ export enum ActionName {
SendGroupMsg = "send_group_msg", SendGroupMsg = "send_group_msg",
SendPrivateMsg = "send_private_msg", SendPrivateMsg = "send_private_msg",
DeleteMsg = "delete_msg", DeleteMsg = "delete_msg",
SetMsgEmojiLike = "set_msg_emoji_like",
SetGroupAddRequest = "set_group_add_request", SetGroupAddRequest = "set_group_add_request",
SetFriendAddRequest = "set_friend_add_request", SetFriendAddRequest = "set_friend_add_request",
SetGroupLeave = "set_group_leave", SetGroupLeave = "set_group_leave",
@ -51,6 +52,8 @@ export enum ActionName {
GetRecord = "get_record", GetRecord = "get_record",
CleanCache = "clean_cache", CleanCache = "clean_cache",
GetCookies = "get_cookies", GetCookies = "get_cookies",
ForwardFriendSingleMsg = "forward_friend_single_msg",
ForwardGroupSingleMsg = "forward_group_single_msg",
// 以下为go-cqhttp api // 以下为go-cqhttp api
GoCQHTTP_SendForwardMsg = "send_forward_msg", GoCQHTTP_SendForwardMsg = "send_forward_msg",
GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg", GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg",
@ -59,6 +62,7 @@ export enum ActionName {
GetGuildList = "get_guild_list", GetGuildList = "get_guild_list",
GoCQHTTP_MarkMsgAsRead = "mark_msg_as_read", GoCQHTTP_MarkMsgAsRead = "mark_msg_as_read",
GoCQHTTP_UploadGroupFile = "upload_group_file", GoCQHTTP_UploadGroupFile = "upload_group_file",
GoCQHTTP_UploadPrivateFile = "upload_private_file",
GoCQHTTP_DownloadFile = "download_file", GoCQHTTP_DownloadFile = "download_file",
GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history", GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history",
GoCQHTTP_GetForwardMsg = "get_forward_msg", GoCQHTTP_GetForwardMsg = "get_forward_msg",