mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: handleQuickOperation
This commit is contained in:
parent
be39fc3a21
commit
f691320453
@ -13,7 +13,7 @@ export class GoCQHTTPHandleQuickAction extends BaseAction<Payload, null> {
|
|||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
this.obContext.apis.QuickActionApi
|
this.obContext.apis.QuickActionApi
|
||||||
.handleQuickOperation(payload.context, payload.operation)
|
.handleQuickOperation(payload.context, payload.operation)
|
||||||
.catch(this.core.context.logger.logError);
|
.catch(this.core.context.logger.logError.bind(this.core.context.logger));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ export function normalize(message: OB11MessageMixType, autoEscape = false): OB11
|
|||||||
) : Array.isArray(message) ? message : [message];
|
) : Array.isArray(message) ? message : [message];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createContext(core: NapCatCore, payload: OB11PostSendMsg, contextMode: ContextMode): Promise<Peer> {
|
export async function createContext(core: NapCatCore, payload: OB11PostSendMsg, contextMode: ContextMode): Promise<Peer> {
|
||||||
// This function determines the type of message by the existence of user_id / group_id,
|
// This function determines the type of message by the existence of user_id / group_id,
|
||||||
// not message_type.
|
// not message_type.
|
||||||
// This redundant design of Ob11 here should be blamed.
|
// This redundant design of Ob11 here should be blamed.
|
||||||
|
@ -13,9 +13,9 @@ import {
|
|||||||
import { ChatType, GroupRequestOperateTypes, NapCatCore, Peer } from '@/core';
|
import { ChatType, GroupRequestOperateTypes, NapCatCore, Peer } from '@/core';
|
||||||
import { OB11FriendRequestEvent } from '@/onebot/event/request/OB11FriendRequest';
|
import { OB11FriendRequestEvent } from '@/onebot/event/request/OB11FriendRequest';
|
||||||
import { OB11GroupRequestEvent } from '@/onebot/event/request/OB11GroupRequest';
|
import { OB11GroupRequestEvent } from '@/onebot/event/request/OB11GroupRequest';
|
||||||
import { normalize } from '@/onebot/action/msg/SendMsg';
|
import { ContextMode, normalize } from '@/onebot/action/msg/SendMsg';
|
||||||
import { isNull } from '@/common/helper';
|
import { isNull } from '@/common/helper';
|
||||||
|
import { createContext } from '@/onebot/action/msg/SendMsg';
|
||||||
export class OneBotQuickActionApi {
|
export class OneBotQuickActionApi {
|
||||||
constructor(
|
constructor(
|
||||||
public obContext: NapCatOneBot11Adapter,
|
public obContext: NapCatOneBot11Adapter,
|
||||||
@ -24,37 +24,34 @@ export class OneBotQuickActionApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleQuickOperation(eventContext: QuickActionEvent, quickAction: QuickAction) {
|
async handleQuickOperation(eventContext: QuickActionEvent, quickAction: QuickAction) {
|
||||||
|
const logger = this.core.context.logger;
|
||||||
if (eventContext.post_type === 'message') {
|
if (eventContext.post_type === 'message') {
|
||||||
await this.handleMsg(eventContext as OB11Message, quickAction)
|
await this.handleMsg(eventContext as OB11Message, quickAction)
|
||||||
.catch(this.core.context.logger.logError);
|
.catch(logger.logError.bind(logger));
|
||||||
}
|
}
|
||||||
if (eventContext.post_type === 'request') {
|
if (eventContext.post_type === 'request') {
|
||||||
const friendRequest = eventContext as OB11FriendRequestEvent;
|
const friendRequest = eventContext as OB11FriendRequestEvent;
|
||||||
const groupRequest = eventContext as OB11GroupRequestEvent;
|
const groupRequest = eventContext as OB11GroupRequestEvent;
|
||||||
if ((friendRequest).request_type === 'friend') {
|
if ((friendRequest).request_type === 'friend') {
|
||||||
await this.handleFriendRequest(friendRequest, quickAction)
|
await this.handleFriendRequest(friendRequest, quickAction)
|
||||||
.catch(this.core.context.logger.logError);
|
.catch(logger.logError.bind(logger));
|
||||||
} else if (groupRequest.request_type === 'group') {
|
} else if (groupRequest.request_type === 'group') {
|
||||||
await this.handleGroupRequest(groupRequest, quickAction)
|
await this.handleGroupRequest(groupRequest, quickAction)
|
||||||
.catch(this.core.context.logger.logError);
|
.catch(logger.logError.bind(logger));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleMsg(msg: OB11Message, quickAction: QuickAction) {
|
async handleMsg(msg: OB11Message, quickAction: QuickAction) {
|
||||||
const reply = quickAction.reply;
|
const reply = quickAction.reply;
|
||||||
const peer: Peer = {
|
const peerContextMode = msg.message_type == 'private' ? ContextMode.Private : ContextMode.Group;
|
||||||
chatType: ChatType.KCHATTYPEC2C,
|
|
||||||
peerUid: await this.core.apis.UserApi.getUidByUinV2(msg.user_id.toString()) as string,
|
const peer: Peer = await createContext(this.core, {
|
||||||
};
|
message: "",
|
||||||
if (msg.message_type == 'private') {
|
group_id: msg.group_id?.toString(),
|
||||||
if (msg.sub_type === 'group') {
|
user_id: msg.user_id?.toString(),
|
||||||
peer.chatType = ChatType.KCHATTYPETEMPC2CFROMGROUP;
|
}, peerContextMode);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
peer.chatType = ChatType.KCHATTYPETEMPC2CFROMGROUP;
|
|
||||||
peer.peerUid = msg.group_id!.toString();
|
|
||||||
}
|
|
||||||
if (reply) {
|
if (reply) {
|
||||||
// let group: Group | undefined;
|
// let group: Group | undefined;
|
||||||
let replyMessage: OB11MessageData[] = [];
|
let replyMessage: OB11MessageData[] = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user