mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 13:05:09 +00:00
chore: reformat code style
This commit is contained in:
@@ -22,6 +22,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export class FetchEmojiLike extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.FetchEmojiLike;
|
||||
payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
||||
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||
|
||||
@@ -16,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export class GetCollectionList extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.GetCollectionList;
|
||||
payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const NTQQCollectionApi = this.core.apis.CollectionApi;
|
||||
return await NTQQCollectionApi.getAllCollection(parseInt(payload.category.toString()), +(payload.count ?? 1));
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ActionName } from '../types';
|
||||
|
||||
export class GetFriendWithCategory extends BaseAction<void, any> {
|
||||
actionName = ActionName.GetFriendsWithCategory;
|
||||
|
||||
async _handle(payload: void) {
|
||||
return (await this.core.apis.FriendApi.getBuddyV2ExWithCate(true)).map(category => ({
|
||||
...category,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { checkFileReceived, uri2local } from '@/common/utils/file';
|
||||
import fs from 'fs';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -19,7 +20,7 @@ export class OCRImage extends BaseAction<Payload, any> {
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const NTQQSystemApi = this.core.apis.SystemApi;
|
||||
const { path, isLocal, errMsg, success } = (await uri2local(this.core.NapCatTempPath, payload.image));
|
||||
const { path, isLocal, success } = (await uri2local(this.core.NapCatTempPath, payload.image));
|
||||
if (!success) {
|
||||
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ const SchemaData = {
|
||||
properties: {
|
||||
eventType: { type: 'string' },
|
||||
group_id: { type: 'string' },
|
||||
user_id: { type: 'string' }
|
||||
user_id: { type: 'string' },
|
||||
},
|
||||
required: ['eventType'],
|
||||
} as const satisfies JSONSchema;
|
||||
@@ -25,20 +25,19 @@ export class SetInputStatus extends BaseAction<Payload, any> {
|
||||
if (payload.group_id) {
|
||||
peer = {
|
||||
chatType: ChatType.KCHATTYPEGROUP,
|
||||
peerUid: payload.group_id
|
||||
peerUid: payload.group_id,
|
||||
};
|
||||
} else if (payload.user_id) {
|
||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id);
|
||||
if (!uid) throw new Error('uid is empty');
|
||||
peer = {
|
||||
chatType: ChatType.KCHATTYPEC2C,
|
||||
peerUid: uid
|
||||
peerUid: uid,
|
||||
};
|
||||
} else {
|
||||
throw new Error('请指定 group_id 或 user_id');
|
||||
}
|
||||
|
||||
const ret = await NTQQMsgApi.sendShowInputStatusReq(peer, parseInt(payload.eventType));
|
||||
return ret;
|
||||
return await NTQQMsgApi.sendShowInputStatusReq(peer, parseInt(payload.eventType));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export class SetOnlineStatus extends BaseAction<Payload, null> {
|
||||
const ret = await NTQQUserApi.setSelfOnlineStatus(
|
||||
parseInt(payload.status.toString()),
|
||||
parseInt(payload.extStatus.toString()),
|
||||
parseInt(payload.batteryStatus.toString())
|
||||
parseInt(payload.batteryStatus.toString()),
|
||||
);
|
||||
if (ret.result !== 0) {
|
||||
throw new Error('设置在线状态失败');
|
||||
|
||||
@@ -24,7 +24,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
||||
const extendData = await NTQQUserApi.getUserDetailInfoByUinV2(user_id);
|
||||
const uid = (await NTQQUserApi.getUidByUinV2(user_id))!;
|
||||
if (!uid || uid.indexOf('*') != -1) {
|
||||
const ret = {
|
||||
return {
|
||||
...extendData.detail.simpleInfo.coreInfo,
|
||||
...extendData.detail.commonExt,
|
||||
...extendData.detail.simpleInfo.baseInfo,
|
||||
@@ -36,9 +36,8 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
||||
qid: extendData.detail.simpleInfo.baseInfo.qid,
|
||||
level: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? 0) || 0,
|
||||
login_days: 0,
|
||||
uid: ''
|
||||
uid: '',
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
const data = { ...extendData, ...(await NTQQUserApi.getUserDetailInfo(uid)) };
|
||||
return OB11Entities.stranger(data);
|
||||
|
||||
@@ -22,13 +22,16 @@ export class SetQQProfile extends BaseAction<Payload, any | null> {
|
||||
const NTQQUserApi = this.core.apis.UserApi;
|
||||
const self = this.core.selfInfo;
|
||||
const OldProfile = await NTQQUserApi.getUserDetailInfo(self.uid);
|
||||
const ret = await NTQQUserApi.modifySelfProfile({
|
||||
return await NTQQUserApi.modifySelfProfile({
|
||||
nick: payload.nickname,
|
||||
longNick: (payload?.personal_note ?? OldProfile?.longNick) || '',
|
||||
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.sex!.toString()),
|
||||
birthday: { birthday_year: OldProfile?.birthday_year!.toString(), birthday_month: OldProfile?.birthday_month!.toString(), birthday_day: OldProfile?.birthday_day!.toString() },
|
||||
birthday: {
|
||||
birthday_year: OldProfile?.birthday_year!.toString(),
|
||||
birthday_month: OldProfile?.birthday_month!.toString(),
|
||||
birthday_day: OldProfile?.birthday_day!.toString(),
|
||||
},
|
||||
location: undefined,
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(peerUid);
|
||||
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
|
||||
}
|
||||
throw new Error( '缺少参数 user_id');
|
||||
throw new Error('缺少参数 user_id');
|
||||
}
|
||||
|
||||
async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { WebApiGroupNoticeFeed } from '@/core';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
@@ -10,7 +9,7 @@ const SchemaData = {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
notice_id: { type: 'string' },
|
||||
},
|
||||
required: ['group_id','notice_id'],
|
||||
required: ['group_id', 'notice_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
@@ -26,14 +26,14 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||
const isNocache = typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache;
|
||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
||||
if (!uid) throw new Error (`Uin2Uid Error ${payload.user_id}不存在`);
|
||||
if (!uid) throw new Error(`Uin2Uid Error ${payload.user_id}不存在`);
|
||||
const [member, info] = await Promise.allSettled([
|
||||
NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache),
|
||||
NTQQUserApi.getUserDetailInfo(uid),
|
||||
]);
|
||||
if (member.status !== 'fulfilled') throw new Error (`群(${payload.group_id})成员${payload.user_id}不存在 ${member.reason}`);
|
||||
if (member.status !== 'fulfilled') throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在 ${member.reason}`);
|
||||
if (info.status === 'fulfilled') {
|
||||
this.core.context.logger.logDebug("群成员详细信息结果", info.value);
|
||||
this.core.context.logger.logDebug('群成员详细信息结果', info.value);
|
||||
Object.assign(member, info.value);
|
||||
} else {
|
||||
this.core.context.logger.logDebug(`获取群成员详细信息失败, 只能返回基础信息 ${info.reason}`);
|
||||
|
||||
@@ -63,7 +63,7 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_groupMembers = Array.from(MemberMap.values());
|
||||
return _groupMembers;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
||||
'NodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
1,
|
||||
5000,
|
||||
(msgs) => !!msgs.find(m => m.msgId === msg.MsgId && m.recallTime !== '0')
|
||||
(msgs) => !!msgs.find(m => m.msgId === msg.MsgId && m.recallTime !== '0'),
|
||||
).catch(() => new Promise<undefined>((resolve) => {
|
||||
resolve(undefined);
|
||||
}));
|
||||
|
||||
@@ -26,7 +26,7 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
||||
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
|
||||
}
|
||||
if (!payload.group_id) {
|
||||
throw new Error( '缺少参数 group_id 或 user_id');
|
||||
throw new Error('缺少参数 group_id 或 user_id');
|
||||
}
|
||||
return { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
|
||||
const messages = normalize(
|
||||
payload.message,
|
||||
typeof payload.auto_escape === 'string' ? payload.auto_escape === 'true' : !!payload.auto_escape
|
||||
typeof payload.auto_escape === 'string' ? payload.auto_escape === 'true' : !!payload.auto_escape,
|
||||
);
|
||||
|
||||
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import CanSendRecord from './CanSendRecord';
|
||||
interface ReturnType {
|
||||
yes: boolean;
|
||||
}
|
||||
|
||||
export default class CanSendImage extends CanSendRecord {
|
||||
actionName = ActionName.CanSendImage;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export class GetCSRF extends BaseAction<any, any> {
|
||||
|
||||
async _handle(payload: any) {
|
||||
return {
|
||||
token: "",
|
||||
token: '',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ export enum ActionName {
|
||||
GOCQHTTP_UploadPrivateFile = 'upload_private_file',
|
||||
TestApi01 = 'test_api_01',
|
||||
FetchEmojiLike = 'fetch_emoji_like',
|
||||
GetGuildProfile = "get_guild_service_profile",
|
||||
SetModelShow = "_set_model_show",
|
||||
SetInputStatus = "set_input_status",
|
||||
GetCSRF = "get_csrf_token",
|
||||
DelGroupNotice = "_del_group_notice",
|
||||
GetGuildProfile = 'get_guild_service_profile',
|
||||
SetModelShow = '_set_model_show',
|
||||
SetInputStatus = 'set_input_status',
|
||||
GetCSRF = 'get_csrf_token',
|
||||
DelGroupNotice = '_del_group_notice',
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ export class OneBotFriendApi {
|
||||
this.obContext = obContext;
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
//使用前预先判断 busiId 1061
|
||||
async parsePrivatePokeEvent(grayTipElement: GrayTipElement) {
|
||||
const NTQQUserApi = this.core.apis.UserApi;
|
||||
@@ -24,7 +25,7 @@ export class OneBotFriendApi {
|
||||
this.core,
|
||||
parseInt((await NTQQUserApi.getUinByUidV2(pokedetail[0].uid))!),
|
||||
parseInt((await NTQQUserApi.getUinByUidV2(pokedetail[1].uid))!),
|
||||
pokedetail
|
||||
pokedetail,
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
|
||||
@@ -15,6 +15,7 @@ export class OneBotGroupApi {
|
||||
this.obContext = obContext;
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
async parseGroupBanEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
||||
const groupElement = grayTipElement?.groupElement;
|
||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||
@@ -40,11 +41,12 @@ export class OneBotGroupApi {
|
||||
parseInt(memberUin),
|
||||
parseInt(adminUin),
|
||||
duration,
|
||||
subType
|
||||
subType,
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async parseGroupIncreaseEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
||||
this.core.context.logger.logDebug('收到新人被邀请进群消息', grayTipElement);
|
||||
const xmlElement = grayTipElement.xmlElement;
|
||||
@@ -65,12 +67,13 @@ export class OneBotGroupApi {
|
||||
parseInt(GroupCode),
|
||||
parseInt(invitee),
|
||||
parseInt(inviter),
|
||||
'invite'
|
||||
'invite',
|
||||
);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async parseGroupMemberIncreaseEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||
const groupElement = grayTipElement?.groupElement;
|
||||
@@ -84,11 +87,12 @@ export class OneBotGroupApi {
|
||||
this.core,
|
||||
parseInt(GroupCode),
|
||||
parseInt(memberUin),
|
||||
parseInt(operatorUin)
|
||||
parseInt(operatorUin),
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||
const NTQQUserApi = this.core.apis.UserApi;
|
||||
@@ -101,11 +105,12 @@ export class OneBotGroupApi {
|
||||
parseInt(GroupCode),
|
||||
parseInt(this.core.selfInfo.uin),
|
||||
parseInt(adminUin),
|
||||
'kick_me'
|
||||
'kick_me',
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async parseGroupEmjioLikeEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
||||
const emojiLikeData = new fastXmlParser.XMLParser({
|
||||
@@ -120,7 +125,7 @@ export class OneBotGroupApi {
|
||||
const peer = {
|
||||
chatType: ChatType.KCHATTYPEGROUP,
|
||||
guildId: '',
|
||||
peerUid: GroupCode
|
||||
peerUid: GroupCode,
|
||||
};
|
||||
const replyMsgList = (await NTQQMsgApi.getMsgExBySeq(peer, msgSeq)).msgList;
|
||||
if (replyMsgList.length < 1) {
|
||||
|
||||
@@ -36,7 +36,7 @@ type RawToOb11Converters = {
|
||||
[Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: (
|
||||
element: Exclude<MessageElement[Key], null | undefined>,
|
||||
msg: RawMessage,
|
||||
elementWrapper: MessageElement
|
||||
elementWrapper: MessageElement,
|
||||
) => PromiseLike<OB11MessageData | null>
|
||||
}
|
||||
|
||||
@@ -73,12 +73,12 @@ export class OneBotMsgApi {
|
||||
}
|
||||
return {
|
||||
type: OB11MessageDataType.text,
|
||||
data: { text }
|
||||
data: { text },
|
||||
};
|
||||
} else {
|
||||
let qq: string = 'all';
|
||||
if (element.atType !== AtType.atAll) {
|
||||
const { atNtUid, /* content */ } = element;
|
||||
const { atNtUid /* content */ } = element;
|
||||
let atQQ = element.atUid;
|
||||
if (!atQQ || atQQ === '0') {
|
||||
atQQ = await this.core.apis.UserApi.getUinByUidV2(atNtUid);
|
||||
@@ -138,7 +138,7 @@ export class OneBotMsgApi {
|
||||
url: element.filePath,
|
||||
file_id: UUIDConverter.encode(msg.peerUin, msg.msgId),
|
||||
file_size: element.fileSize,
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -149,21 +149,21 @@ export class OneBotMsgApi {
|
||||
type: OB11MessageDataType.dice,
|
||||
data: {
|
||||
result: element.resultId!,
|
||||
}
|
||||
},
|
||||
};
|
||||
} else if (faceIndex === FaceIndex.RPS) {
|
||||
return {
|
||||
type: OB11MessageDataType.RPS,
|
||||
data: {
|
||||
result: element.resultId!,
|
||||
}
|
||||
},
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type: OB11MessageDataType.face,
|
||||
data: {
|
||||
id: element.faceIndex.toString()
|
||||
}
|
||||
id: element.faceIndex.toString(),
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
@@ -190,7 +190,7 @@ export class OneBotMsgApi {
|
||||
file_id: UUIDConverter.encode(msg.peerUin, msg.msgId),
|
||||
path: elementWrapper.elementId,
|
||||
url: elementWrapper.elementId,
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -239,8 +239,8 @@ export class OneBotMsgApi {
|
||||
peerUid: msg.peerUid,
|
||||
guildId: '',
|
||||
chatType: msg.chatType,
|
||||
}, replyMsg.msgId).toString()
|
||||
}
|
||||
}, replyMsg.msgId).toString(),
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -303,7 +303,7 @@ export class OneBotMsgApi {
|
||||
url: videoDownUrl,
|
||||
file_id: UUIDConverter.encode(msg.peerUin, msg.msgId),
|
||||
file_size: element.fileSize,
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -329,7 +329,7 @@ export class OneBotMsgApi {
|
||||
path: element.filePath,
|
||||
file_id: UUIDConverter.encode(msg.peerUin, msg.msgId),
|
||||
file_size: element.fileSize,
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -366,9 +366,9 @@ export class OneBotMsgApi {
|
||||
multiMsgItem.parentMsgIdList = msg.parentMsgIdList;
|
||||
multiMsgItem.id = MessageUnique.createMsg(parentMsgPeer, multiMsgItem.msgId); //该ID仅用查看 无法调用
|
||||
return await this.parseMessage(multiMsgItem);
|
||||
}
|
||||
},
|
||||
))).filter(item => item !== undefined),
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -376,8 +376,8 @@ export class OneBotMsgApi {
|
||||
return {
|
||||
type: OB11MessageDataType.json,
|
||||
data: {
|
||||
data: element.bytesData
|
||||
}
|
||||
data: element.bytesData,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -385,10 +385,10 @@ export class OneBotMsgApi {
|
||||
return {
|
||||
type: OB11MessageDataType.markdown,
|
||||
data: {
|
||||
content: element.content
|
||||
}
|
||||
content: element.content,
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
ob11ToRawConverters: Ob11ToRawConverters = {
|
||||
@@ -716,11 +716,11 @@ export class OneBotMsgApi {
|
||||
// @ts-ignore
|
||||
element[key],
|
||||
msg,
|
||||
element
|
||||
element,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
))).filter(entry => {
|
||||
if (entry.status === 'fulfilled') {
|
||||
return !!entry.value;
|
||||
@@ -822,7 +822,7 @@ export class OneBotMsgApi {
|
||||
this.core.context.logger.logError('文件消息缺少参数', inputdata);
|
||||
throw Error('文件消息缺少参数');
|
||||
}
|
||||
const fileOrUrl = (isBlankUrl ? inputdata.file : inputdata.url) ?? "";
|
||||
const fileOrUrl = (isBlankUrl ? inputdata.file : inputdata.url) ?? '';
|
||||
const {
|
||||
path,
|
||||
isLocal,
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import {
|
||||
NapCatOneBot11Adapter,
|
||||
OB11Message, OB11MessageAt,
|
||||
OB11Message,
|
||||
OB11MessageAt,
|
||||
OB11MessageData,
|
||||
OB11MessageReply,
|
||||
QuickAction,
|
||||
QuickActionEvent, QuickActionFriendRequest, QuickActionGroupMessage, QuickActionGroupRequest,
|
||||
QuickActionEvent,
|
||||
QuickActionFriendRequest,
|
||||
QuickActionGroupMessage,
|
||||
QuickActionGroupRequest,
|
||||
} from '@/onebot';
|
||||
import { ChatType, GroupRequestOperateTypes, NapCatCore, Peer } from '@/core';
|
||||
import { OB11FriendRequestEvent } from '@/onebot/event/request/OB11FriendRequest';
|
||||
@@ -15,8 +19,9 @@ import { isNull } from '@/common/utils/helper';
|
||||
export class OneBotQuickActionApi {
|
||||
constructor(
|
||||
public obContext: NapCatOneBot11Adapter,
|
||||
public core: NapCatCore
|
||||
) {}
|
||||
public core: NapCatCore,
|
||||
) {
|
||||
}
|
||||
|
||||
async handleQuickOperation(eventContext: QuickActionEvent, quickAction: QuickAction) {
|
||||
if (eventContext.post_type === 'message') {
|
||||
@@ -72,7 +77,10 @@ export class OneBotQuickActionApi {
|
||||
}
|
||||
}
|
||||
replyMessage = replyMessage.concat(normalize(reply, quickAction.auto_escape));
|
||||
const { sendElements, deleteAfterSentFiles } = await this.obContext.apis.MsgApi.createSendElements(replyMessage, peer);
|
||||
const {
|
||||
sendElements,
|
||||
deleteAfterSentFiles,
|
||||
} = await this.obContext.apis.MsgApi.createSendElements(replyMessage, peer);
|
||||
this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles, false).then().catch(this.core.context.logger.logError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { NapCatOneBot11Adapter } from "..";
|
||||
import { OB11BaseNoticeEvent } from "../event/notice/OB11BaseNoticeEvent";
|
||||
import { OB11FriendAddNoticeEvent } from "../event/notice/OB11FriendAddNoticeEvent";
|
||||
import { OB11GroupNoticeEvent } from "../event/notice/OB11GroupNoticeEvent";
|
||||
import { OB11GroupCardEvent } from "../event/notice/OB11GroupCardEvent";
|
||||
import { OB11GroupDecreaseEvent } from "../event/notice/OB11GroupDecreaseEvent";
|
||||
import { OB11GroupUploadNoticeEvent } from "../event/notice/OB11GroupUploadNoticeEvent";
|
||||
import { OB11GroupPokeEvent } from "../event/notice/OB11PokeEvent";
|
||||
import { OB11GroupEssenceEvent } from "../event/notice/OB11GroupEssenceEvent";
|
||||
import { MessageUnique } from "@/common/utils/message-unique";
|
||||
import { OB11GroupTitleEvent } from "../event/notice/OB11GroupTitleEvent";
|
||||
import { NapCatOneBot11Adapter } from '..';
|
||||
import { OB11BaseNoticeEvent } from '../event/notice/OB11BaseNoticeEvent';
|
||||
import { OB11FriendAddNoticeEvent } from '../event/notice/OB11FriendAddNoticeEvent';
|
||||
import { OB11GroupNoticeEvent } from '../event/notice/OB11GroupNoticeEvent';
|
||||
import { OB11GroupCardEvent } from '../event/notice/OB11GroupCardEvent';
|
||||
import { OB11GroupDecreaseEvent } from '../event/notice/OB11GroupDecreaseEvent';
|
||||
import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent';
|
||||
import { OB11GroupPokeEvent } from '../event/notice/OB11PokeEvent';
|
||||
import { OB11GroupEssenceEvent } from '../event/notice/OB11GroupEssenceEvent';
|
||||
import { MessageUnique } from '@/common/utils/message-unique';
|
||||
import { OB11GroupTitleEvent } from '../event/notice/OB11GroupTitleEvent';
|
||||
import { NapCatCore, RawMessage, ChatType, NTGrayTipElementSubTypeV2, TipGroupElementType, Peer } from '@/core';
|
||||
|
||||
export async function NT2PrivateEvent(core: NapCatCore, obContext: NapCatOneBot11Adapter, msg: RawMessage): Promise<OB11BaseNoticeEvent | undefined> {
|
||||
@@ -72,7 +72,7 @@ export async function NT2GroupEvent(core: NapCatCore, obContext: NapCatOneBot11A
|
||||
parseInt(msg.peerUid),
|
||||
parseInt(core.selfInfo.uin),
|
||||
0,
|
||||
'leave'
|
||||
'leave',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ export async function NT2GroupEvent(core: NapCatCore, obContext: NapCatOneBot11A
|
||||
name: element.fileElement.fileName,
|
||||
size: parseInt(element.fileElement.fileSize),
|
||||
busid: element.fileElement.fileBizId || 0,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
if (element.grayTipElement) {
|
||||
@@ -113,7 +113,7 @@ export async function NT2GroupEvent(core: NapCatCore, obContext: NapCatOneBot11A
|
||||
parseInt(msg.peerUid),
|
||||
parseInt((await NTQQUserApi.getUinByUidV2(poke_uid[0].uid))!),
|
||||
parseInt((await NTQQUserApi.getUinByUidV2(poke_uid[1].uid))!),
|
||||
pokedetail
|
||||
pokedetail,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ export async function NT2GroupEvent(core: NapCatCore, obContext: NapCatOneBot11A
|
||||
core,
|
||||
parseInt(msg.peerUid),
|
||||
MessageUnique.getShortIdByMsgId(msgData.msgList[0].msgId)!,
|
||||
parseInt(msgData.msgList[0].senderUin)
|
||||
parseInt(msgData.msgList[0].senderUin),
|
||||
);
|
||||
// 获取MsgSeq+Peer可获取具体消息
|
||||
}
|
||||
@@ -145,7 +145,7 @@ export async function NT2GroupEvent(core: NapCatCore, obContext: NapCatOneBot11A
|
||||
core,
|
||||
parseInt(msg.peerUid),
|
||||
parseInt(memberUin),
|
||||
title
|
||||
title,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,13 +94,13 @@ export class NapCatOneBot11Adapter {
|
||||
//创建NetWork服务
|
||||
if (ob11Config.http.enable) {
|
||||
this.networkManager.registerAdapter(new OB11PassiveHttpAdapter(
|
||||
ob11Config.http.port, ob11Config.token, this.core, this.actions
|
||||
ob11Config.http.port, ob11Config.token, this.core, this.actions,
|
||||
));
|
||||
}
|
||||
if (ob11Config.http.enablePost) {
|
||||
ob11Config.http.postUrls.forEach(url => {
|
||||
this.networkManager.registerAdapter(new OB11ActiveHttpAdapter(
|
||||
url, ob11Config.token, this.core, this
|
||||
url, ob11Config.token, this.core, this,
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -113,7 +113,7 @@ export class NapCatOneBot11Adapter {
|
||||
if (ob11Config.reverseWs.enable) {
|
||||
ob11Config.reverseWs.urls.forEach(url => {
|
||||
this.networkManager.registerAdapter(new OB11ActiveWebSocketAdapter(
|
||||
url, 5000, ob11Config.heartInterval, ob11Config.token, this.core, this.actions
|
||||
url, 5000, ob11Config.heartInterval, ob11Config.token, this.core, this.actions,
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -134,9 +134,10 @@ export class NapCatOneBot11Adapter {
|
||||
await this.reloadNetwork(prev, newConfig);
|
||||
});
|
||||
}
|
||||
|
||||
initRecentContactListener() {
|
||||
const recentContactListener = new NodeIKernelRecentContactListener();
|
||||
recentContactListener.onRecentContactNotification = function (msgList: any[], /* arg0: { msgListUnreadCnt: string }, arg1: number */) {
|
||||
recentContactListener.onRecentContactNotification = function(msgList: any[] /* arg0: { msgListUnreadCnt: string }, arg1: number */) {
|
||||
msgList.forEach((msg) => {
|
||||
if (msg.chatType == ChatType.KCHATTYPEGROUP) {
|
||||
// log("recent contact", msgList, arg0, arg1);
|
||||
@@ -157,10 +158,10 @@ export class NapCatOneBot11Adapter {
|
||||
if (prev.http.enable !== now.http.enable) {
|
||||
if (now.http.enable) {
|
||||
await this.networkManager.registerAdapterAndOpen(new OB11PassiveHttpAdapter(
|
||||
now.http.port, now.token, this.core, this.actions
|
||||
now.http.port, now.token, this.core, this.actions,
|
||||
));
|
||||
} else {
|
||||
await this.networkManager.closeAdapterByPredicate(adapter => adapter instanceof OB11PassiveHttpAdapter,);
|
||||
await this.networkManager.closeAdapterByPredicate(adapter => adapter instanceof OB11PassiveHttpAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +170,7 @@ export class NapCatOneBot11Adapter {
|
||||
if (now.http.enablePost) {
|
||||
now.http.postUrls.forEach(url => {
|
||||
this.networkManager.registerAdapterAndOpen(new OB11ActiveHttpAdapter(
|
||||
url, now.token, this.core, this
|
||||
url, now.token, this.core, this,
|
||||
));
|
||||
});
|
||||
} else {
|
||||
@@ -183,7 +184,7 @@ export class NapCatOneBot11Adapter {
|
||||
);
|
||||
for (const url of added) {
|
||||
await this.networkManager.registerAdapterAndOpen(new OB11ActiveHttpAdapter(
|
||||
url, now.token, this.core, this
|
||||
url, now.token, this.core, this,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -197,7 +198,7 @@ export class NapCatOneBot11Adapter {
|
||||
));
|
||||
} else {
|
||||
await this.networkManager.closeAdapterByPredicate(
|
||||
adapter => adapter instanceof OB11PassiveWebSocketAdapter
|
||||
adapter => adapter instanceof OB11PassiveWebSocketAdapter,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -207,12 +208,12 @@ export class NapCatOneBot11Adapter {
|
||||
if (now.reverseWs.enable) {
|
||||
now.reverseWs.urls.forEach(url => {
|
||||
this.networkManager.registerAdapterAndOpen(new OB11ActiveWebSocketAdapter(
|
||||
url, 5000, now.heartInterval, now.token, this.core, this.actions
|
||||
url, 5000, now.heartInterval, now.token, this.core, this.actions,
|
||||
));
|
||||
});
|
||||
} else {
|
||||
await this.networkManager.closeAdapterByPredicate(
|
||||
adapter => adapter instanceof OB11ActiveWebSocketAdapter
|
||||
adapter => adapter instanceof OB11ActiveWebSocketAdapter,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -223,7 +224,7 @@ export class NapCatOneBot11Adapter {
|
||||
);
|
||||
for (const url of added) {
|
||||
await this.networkManager.registerAdapterAndOpen(new OB11ActiveWebSocketAdapter(
|
||||
url, 5000, now.heartInterval, now.token, this.core, this.actions
|
||||
url, 5000, now.heartInterval, now.token, this.core, this.actions,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -300,7 +301,7 @@ export class NapCatOneBot11Adapter {
|
||||
};
|
||||
|
||||
this.context.session.getMsgService().addKernelMsgListener(
|
||||
proxiedListenerOf(msgListener, this.context.logger) as any
|
||||
proxiedListenerOf(msgListener, this.context.logger) as any,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -335,7 +336,7 @@ export class NapCatOneBot11Adapter {
|
||||
};
|
||||
|
||||
this.context.session.getBuddyService().addKernelBuddyListener(
|
||||
proxiedListenerOf(buddyListener, this.context.logger) as any
|
||||
proxiedListenerOf(buddyListener, this.context.logger) as any,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -377,7 +378,7 @@ export class NapCatOneBot11Adapter {
|
||||
parseInt(member1.uin),
|
||||
[
|
||||
GroupNotifyMsgType.CANCEL_ADMIN_NOTIFY_CANCELED,
|
||||
GroupNotifyMsgType.CANCEL_ADMIN_NOTIFY_ADMIN
|
||||
GroupNotifyMsgType.CANCEL_ADMIN_NOTIFY_ADMIN,
|
||||
].includes(notify.type) ? 'unset' : 'set',
|
||||
);
|
||||
this.networkManager.emitEvent(groupAdminNoticeEvent)
|
||||
@@ -471,7 +472,7 @@ export class NapCatOneBot11Adapter {
|
||||
};
|
||||
|
||||
this.context.session.getGroupService().addKernelGroupListener(
|
||||
proxiedListenerOf(groupListener, this.context.logger)
|
||||
proxiedListenerOf(groupListener, this.context.logger),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
public url: string,
|
||||
public secret: string | undefined,
|
||||
public core: NapCatCore,
|
||||
public obContext: NapCatOneBot11Adapter
|
||||
public obContext: NapCatOneBot11Adapter,
|
||||
) {
|
||||
this.logger = core.context.logger;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
connectEvent(core: NapCatCore) {
|
||||
try {
|
||||
this.checkStateAndReply<any>(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT));
|
||||
@@ -126,6 +127,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
this.logger.logError('[OneBot] [WebSocket Client] 发送生命周期失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
private async handleMessage(message: any) {
|
||||
let receiveData: { action: ActionName, params?: any, echo?: any } = { action: ActionName.Unknown, params: {} };
|
||||
let echo = undefined;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IOB11NetworkAdapter, OB11EmitEventContent } from './index';
|
||||
import { IOB11NetworkAdapter } from './index';
|
||||
import express, { Express, Request, Response } from 'express';
|
||||
import http from 'http';
|
||||
import { NapCatCore } from '@/core';
|
||||
@@ -44,6 +44,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
this.server?.close();
|
||||
this.app = undefined;
|
||||
}
|
||||
|
||||
private initializeServer() {
|
||||
this.app = express();
|
||||
this.server = http.createServer(this.app);
|
||||
|
||||
@@ -28,7 +28,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
heartbeatInterval: number,
|
||||
token: string,
|
||||
core: NapCatCore,
|
||||
public actions: ActionMap
|
||||
public actions: ActionMap,
|
||||
) {
|
||||
this.core = core;
|
||||
this.logger = core.context.logger;
|
||||
|
||||
Reference in New Issue
Block a user