mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: forward single msg
This commit is contained in:
parent
5562a3251d
commit
3ae2d2a1e6
@ -14,7 +14,11 @@ import GetVersionInfo from "./system/GetVersionInfo";
|
||||
import CanSendRecord from "./system/CanSendRecord";
|
||||
import CanSendImage from "./system/CanSendImage";
|
||||
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 SendLike from "./user/SendLike";
|
||||
import SetGroupAddRequest from "./group/SetGroupAddRequest";
|
||||
@ -32,7 +36,7 @@ import GetImage from "./file/GetImage";
|
||||
import GetRecord from "./file/GetRecord";
|
||||
import GoCQHTTPMarkMsgAsRead from "./msg/MarkMsgAsRead";
|
||||
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 GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
||||
import SetQQAvatar from './llonebot/SetQQAvatar'
|
||||
@ -41,62 +45,67 @@ import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
||||
import GetFile from "./file/GetFile";
|
||||
import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg";
|
||||
import {GetCookies} from "./user/GetCookie";
|
||||
import {SetMsgEmojiLike} from "./msg/SetMsgEmojiLike";
|
||||
import {ForwardFriendSingleMsg, ForwardSingleGroupMsg} from "./msg/ForwardSingleMsg";
|
||||
|
||||
export const actionHandlers = [
|
||||
new GetFile(),
|
||||
new Debug(),
|
||||
new GetConfigAction(),
|
||||
new SetConfigAction(),
|
||||
new GetGroupAddRequest(),
|
||||
new SetQQAvatar(),
|
||||
// onebot11
|
||||
new SendLike(),
|
||||
new GetMsg(),
|
||||
new GetLoginInfo(),
|
||||
new GetFriendList(),
|
||||
new GetGroupList(), new GetGroupInfo(), new GetGroupMemberList(), new GetGroupMemberInfo(),
|
||||
new SendGroupMsg(), new SendPrivateMsg(), new SendMsg(),
|
||||
new DeleteMsg(),
|
||||
new SetGroupAddRequest(),
|
||||
new SetFriendAddRequest(),
|
||||
new SetGroupLeave(),
|
||||
new GetVersionInfo(),
|
||||
new CanSendRecord(),
|
||||
new CanSendImage(),
|
||||
new GetStatus(),
|
||||
new SetGroupWholeBan(),
|
||||
new SetGroupBan(),
|
||||
new SetGroupKick(),
|
||||
new SetGroupAdmin(),
|
||||
new SetGroupName(),
|
||||
new SetGroupCard(),
|
||||
new GetImage(),
|
||||
new GetRecord(),
|
||||
new CleanCache(),
|
||||
new GetCookies(),
|
||||
//以下为go-cqhttp api
|
||||
new GoCQHTTPSendForwardMsg(),
|
||||
new GoCQHTTPSendGroupForwardMsg(),
|
||||
new GoCQHTTPSendPrivateForwardMsg(),
|
||||
new GoCQHTTPGetStrangerInfo(),
|
||||
new GoCQHTTPDownloadFile(),
|
||||
new GetGuildList(),
|
||||
new GoCQHTTPMarkMsgAsRead(),
|
||||
new GoCQHTTPUploadGroupFile(),
|
||||
new GoCQHTTPGetGroupMsgHistory(),
|
||||
new GoCQHTTGetForwardMsgAction(),
|
||||
|
||||
new GetFile(),
|
||||
new Debug(),
|
||||
new GetConfigAction(),
|
||||
new SetConfigAction(),
|
||||
new GetGroupAddRequest(),
|
||||
new SetQQAvatar(),
|
||||
// onebot11
|
||||
new SendLike(),
|
||||
new GetMsg(),
|
||||
new GetLoginInfo(),
|
||||
new GetFriendList(),
|
||||
new GetGroupList(), new GetGroupInfo(), new GetGroupMemberList(), new GetGroupMemberInfo(),
|
||||
new SendGroupMsg(), new SendPrivateMsg(), new SendMsg(),
|
||||
new DeleteMsg(),
|
||||
new SetGroupAddRequest(),
|
||||
new SetFriendAddRequest(),
|
||||
new SetGroupLeave(),
|
||||
new GetVersionInfo(),
|
||||
new CanSendRecord(),
|
||||
new CanSendImage(),
|
||||
new GetStatus(),
|
||||
new SetGroupWholeBan(),
|
||||
new SetGroupBan(),
|
||||
new SetGroupKick(),
|
||||
new SetGroupAdmin(),
|
||||
new SetGroupName(),
|
||||
new SetGroupCard(),
|
||||
new GetImage(),
|
||||
new GetRecord(),
|
||||
new CleanCache(),
|
||||
new GetCookies(),
|
||||
new SetMsgEmojiLike(),
|
||||
new ForwardFriendSingleMsg(),
|
||||
new ForwardSingleGroupMsg(),
|
||||
//以下为go-cqhttp api
|
||||
new GoCQHTTPSendForwardMsg(),
|
||||
new GoCQHTTPSendGroupForwardMsg(),
|
||||
new GoCQHTTPSendPrivateForwardMsg(),
|
||||
new GoCQHTTPGetStrangerInfo(),
|
||||
new GoCQHTTPDownloadFile(),
|
||||
new GetGuildList(),
|
||||
new GoCQHTTPMarkMsgAsRead(),
|
||||
new GoCQHTTPUploadGroupFile(),
|
||||
new GoCQHTTPUploadPrivateFile(),
|
||||
new GoCQHTTPGetGroupMsgHistory(),
|
||||
new GoCQHTTGetForwardMsgAction(),
|
||||
]
|
||||
|
||||
function initActionMap() {
|
||||
const actionMap = new Map<string, BaseAction<any, any>>();
|
||||
for (const action of actionHandlers) {
|
||||
actionMap.set(action.actionName, action);
|
||||
actionMap.set(action.actionName + '_async', action);
|
||||
actionMap.set(action.actionName + '_rate_limited', action);
|
||||
}
|
||||
const actionMap = new Map<string, BaseAction<any, any>>();
|
||||
for (const action of actionHandlers) {
|
||||
actionMap.set(action.actionName, action);
|
||||
actionMap.set(action.actionName + '_async', action);
|
||||
actionMap.set(action.actionName + '_rate_limited', action);
|
||||
}
|
||||
|
||||
return actionMap
|
||||
return actionMap
|
||||
}
|
||||
|
||||
export const actionMap = initActionMap();
|
||||
|
44
src/onebot11/action/msg/ForwardSingleMsg.ts
Normal file
44
src/onebot11/action/msg/ForwardSingleMsg.ts
Normal 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
|
||||
}
|
@ -34,6 +34,7 @@ export enum ActionName {
|
||||
SendGroupMsg = "send_group_msg",
|
||||
SendPrivateMsg = "send_private_msg",
|
||||
DeleteMsg = "delete_msg",
|
||||
SetMsgEmojiLike = "set_msg_emoji_like",
|
||||
SetGroupAddRequest = "set_group_add_request",
|
||||
SetFriendAddRequest = "set_friend_add_request",
|
||||
SetGroupLeave = "set_group_leave",
|
||||
@ -51,6 +52,8 @@ export enum ActionName {
|
||||
GetRecord = "get_record",
|
||||
CleanCache = "clean_cache",
|
||||
GetCookies = "get_cookies",
|
||||
ForwardFriendSingleMsg = "forward_friend_single_msg",
|
||||
ForwardGroupSingleMsg = "forward_group_single_msg",
|
||||
// 以下为go-cqhttp api
|
||||
GoCQHTTP_SendForwardMsg = "send_forward_msg",
|
||||
GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg",
|
||||
@ -59,6 +62,7 @@ export enum ActionName {
|
||||
GetGuildList = "get_guild_list",
|
||||
GoCQHTTP_MarkMsgAsRead = "mark_msg_as_read",
|
||||
GoCQHTTP_UploadGroupFile = "upload_group_file",
|
||||
GoCQHTTP_UploadPrivateFile = "upload_private_file",
|
||||
GoCQHTTP_DownloadFile = "download_file",
|
||||
GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history",
|
||||
GoCQHTTP_GetForwardMsg = "get_forward_msg",
|
||||
|
Loading…
x
Reference in New Issue
Block a user