mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8b9c7b0c27 | ||
![]() |
1005619bf3 | ||
![]() |
3e09cff9cb | ||
![]() |
c24384e454 | ||
![]() |
f87a543406 | ||
![]() |
f752136283 | ||
![]() |
7e71622a44 | ||
![]() |
da92afb379 | ||
![]() |
d3062de5f9 | ||
![]() |
f1440b03a8 | ||
![]() |
9a8b266cef | ||
![]() |
2a9bc57120 | ||
![]() |
2ed83a0e30 | ||
![]() |
116e8fd30a | ||
![]() |
891f11173b | ||
![]() |
dfc7996c17 | ||
![]() |
dc0561d34f | ||
![]() |
4fb0845d79 | ||
![]() |
0e0d4837b8 | ||
![]() |
a6adde7966 | ||
![]() |
7b693132f9 | ||
![]() |
3c3114b6ab | ||
![]() |
5cdbf58f59 |
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "4.2.30",
|
"version": "4.2.33",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -89,7 +89,11 @@
|
|||||||
<t-tag class="tag-item pgk-color"> WebUi: {{ pkg.version }} </t-tag>
|
<t-tag class="tag-item pgk-color"> WebUi: {{ pkg.version }} </t-tag>
|
||||||
<t-tag class="tag-item nc-color">
|
<t-tag class="tag-item nc-color">
|
||||||
NapCat:
|
NapCat:
|
||||||
{{ githubReleasesData&&githubReleasesData[0] ?.tag_name ? githubReleasesData[0].tag_name : napCatVersion }}
|
{{ napCatVersion }}
|
||||||
|
</t-tag>
|
||||||
|
<t-tag v-if="githubReleasesData&&githubReleasesData[0] ?.tag_name" class="tag-item nc-color">
|
||||||
|
New NapCat:
|
||||||
|
{{ githubReleasesData[0].tag_name }}
|
||||||
</t-tag>
|
</t-tag>
|
||||||
<t-tag class="tag-item td-color"> TDesign: {{ pkg.dependencies['tdesign-vue-next'] }} </t-tag>
|
<t-tag class="tag-item td-color"> TDesign: {{ pkg.dependencies['tdesign-vue-next'] }} </t-tag>
|
||||||
</span>
|
</span>
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "4.2.30",
|
"version": "4.2.33",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
||||||
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
||||||
@@ -23,8 +23,8 @@
|
|||||||
"@eslint/js": "^9.14.0",
|
"@eslint/js": "^9.14.0",
|
||||||
"@log4js-node/log4js-api": "^1.0.2",
|
"@log4js-node/log4js-api": "^1.0.2",
|
||||||
"@napneko/nap-proto-core": "^0.0.4",
|
"@napneko/nap-proto-core": "^0.0.4",
|
||||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
"@rollup/plugin-typescript": "^12.1.2",
|
||||||
"@rollup/plugin-typescript": "^11.1.6",
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
||||||
"@types/cors": "^2.8.17",
|
"@types/cors": "^2.8.17",
|
||||||
"@sinclair/typebox": "^0.34.9",
|
"@sinclair/typebox": "^0.34.9",
|
||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const napCatVersion = '4.2.30';
|
export const napCatVersion = '4.2.33';
|
||||||
|
@@ -3,6 +3,7 @@ export interface MiniAppReqCustomParams {
|
|||||||
desc: string;
|
desc: string;
|
||||||
picUrl: string;
|
picUrl: string;
|
||||||
jumpUrl: string;
|
jumpUrl: string;
|
||||||
|
webUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MiniAppReqTemplateParams {
|
export interface MiniAppReqTemplateParams {
|
||||||
|
@@ -30,7 +30,7 @@ class GetMiniAppAdaptShareInfo extends PacketTransformer<typeof proto.MiniAppAda
|
|||||||
shareType: req.shareType,
|
shareType: req.shareType,
|
||||||
versionId: req.versionId,
|
versionId: req.versionId,
|
||||||
withShareTicket: req.withShareTicket,
|
withShareTicket: req.withShareTicket,
|
||||||
webURL: "",
|
webURL: req.webUrl ?? "",
|
||||||
appidRich: Buffer.alloc(0),
|
appidRich: Buffer.alloc(0),
|
||||||
template: {
|
template: {
|
||||||
templateId: "",
|
templateId: "",
|
||||||
|
@@ -29,7 +29,7 @@ export class OB11Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
||||||
actionName: ActionName = ActionName.Unknown;
|
actionName: typeof ActionName[keyof typeof ActionName] = ActionName.Unknown;
|
||||||
core: NapCatCore;
|
core: NapCatCore;
|
||||||
private validate: ValidateFunction<any> | undefined = undefined;
|
private validate: ValidateFunction<any> | undefined = undefined;
|
||||||
payloadSchema: any = undefined;
|
payloadSchema: any = undefined;
|
||||||
@@ -84,4 +84,4 @@ export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract _handle(payload: PayloadType, adaptername: string): PromiseLike<ReturnDataType>;
|
abstract _handle(payload: PayloadType, adaptername: string): PromiseLike<ReturnDataType>;
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,8 @@ const SchemaData = Type.Union([
|
|||||||
desc: Type.String(),
|
desc: Type.String(),
|
||||||
picUrl: Type.String(),
|
picUrl: Type.String(),
|
||||||
jumpUrl: Type.String(),
|
jumpUrl: Type.String(),
|
||||||
rawArkData: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
webUrl: Type.Optional(Type.String()),
|
||||||
|
rawArkData: Type.Optional(Type.Union([Type.String()]))
|
||||||
}),
|
}),
|
||||||
Type.Object({
|
Type.Object({
|
||||||
title: Type.String(),
|
title: Type.String(),
|
||||||
@@ -19,6 +20,7 @@ const SchemaData = Type.Union([
|
|||||||
picUrl: Type.String(),
|
picUrl: Type.String(),
|
||||||
jumpUrl: Type.String(),
|
jumpUrl: Type.String(),
|
||||||
iconUrl: Type.String(),
|
iconUrl: Type.String(),
|
||||||
|
webUrl: Type.Optional(Type.String()),
|
||||||
appId: Type.String(),
|
appId: Type.String(),
|
||||||
scene: Type.Union([Type.Number(), Type.String()]),
|
scene: Type.Union([Type.Number(), Type.String()]),
|
||||||
templateType: Type.Union([Type.Number(), Type.String()]),
|
templateType: Type.Union([Type.Number(), Type.String()]),
|
||||||
@@ -28,7 +30,7 @@ const SchemaData = Type.Union([
|
|||||||
versionId: Type.String(),
|
versionId: Type.String(),
|
||||||
sdkId: Type.String(),
|
sdkId: Type.String(),
|
||||||
withShareTicket: Type.Union([Type.Number(), Type.String()]),
|
withShareTicket: Type.Union([Type.Number(), Type.String()]),
|
||||||
rawArkData: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
rawArkData: Type.Optional(Type.Union([Type.String()]))
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
type Payload = Static<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
@@ -45,7 +47,8 @@ export class GetMiniAppArk extends GetPacketStatusDepends<Payload, {
|
|||||||
title: payload.title,
|
title: payload.title,
|
||||||
desc: payload.desc,
|
desc: payload.desc,
|
||||||
picUrl: payload.picUrl,
|
picUrl: payload.picUrl,
|
||||||
jumpUrl: payload.jumpUrl
|
jumpUrl: payload.jumpUrl,
|
||||||
|
webUrl: payload.webUrl,
|
||||||
} as MiniAppReqCustomParams;
|
} as MiniAppReqCustomParams;
|
||||||
if ('type' in payload) {
|
if ('type' in payload) {
|
||||||
reqParam = MiniAppInfoHelper.generateReq(customParams, MiniAppInfo.get(payload.type)!.template);
|
reqParam = MiniAppInfoHelper.generateReq(customParams, MiniAppInfo.get(payload.type)!.template);
|
||||||
@@ -63,13 +66,13 @@ export class GetMiniAppArk extends GetPacketStatusDepends<Payload, {
|
|||||||
verType: +verType,
|
verType: +verType,
|
||||||
shareType: +shareType,
|
shareType: +shareType,
|
||||||
versionId: versionId,
|
versionId: versionId,
|
||||||
withShareTicket: +withShareTicket
|
withShareTicket: +withShareTicket,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const arkData = await this.core.apis.PacketApi.pkt.operation.GetMiniAppAdaptShareInfo(reqParam);
|
const arkData = await this.core.apis.PacketApi.pkt.operation.GetMiniAppAdaptShareInfo(reqParam);
|
||||||
return {
|
return {
|
||||||
data: payload.rawArkData ? arkData : MiniAppInfoHelper.RawToSend(arkData)
|
data: payload.rawArkData === 'true' ? arkData : MiniAppInfoHelper.RawToSend(arkData)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,8 +10,7 @@ const SchemaData = Type.Object({
|
|||||||
|
|
||||||
type Payload = Static<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class OCRImage extends OneBotAction<Payload, any> {
|
class OCRImageBase extends OneBotAction<Payload, any> {
|
||||||
actionName = ActionName.OCRImage;
|
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
@@ -34,6 +33,10 @@ export class OCRImage extends OneBotAction<Payload, any> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class IOCRImage extends OCRImage {
|
export class OCRImage extends OCRImageBase {
|
||||||
|
actionName = ActionName.OCRImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IOCRImage extends OCRImageBase {
|
||||||
actionName = ActionName.IOCRImage;
|
actionName = ActionName.IOCRImage;
|
||||||
}
|
}
|
||||||
|
@@ -8,14 +8,18 @@ const SchemaData = Type.Object({
|
|||||||
|
|
||||||
type Payload = Static<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetGroupSign extends GetPacketStatusDepends<Payload, any> {
|
class SetGroupSignBase extends GetPacketStatusDepends<Payload, any> {
|
||||||
actionName = ActionName.SetGroupSign;
|
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
return await this.core.apis.PacketApi.pkt.operation.GroupSign(+payload.group_id);
|
return await this.core.apis.PacketApi.pkt.operation.GroupSign(+payload.group_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class SendGroupSign extends SetGroupSign {
|
|
||||||
|
export class SetGroupSign extends SetGroupSignBase {
|
||||||
|
actionName = ActionName.SendGroupSign;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SendGroupSign extends SetGroupSignBase {
|
||||||
actionName = ActionName.SendGroupSign;
|
actionName = ActionName.SendGroupSign;
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import SendMsg, { ContextMode } from '@/onebot/action/msg/SendMsg';
|
import {ContextMode, SendMsgBase} from '@/onebot/action/msg/SendMsg';
|
||||||
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
||||||
import { OB11PostSendMsg } from '@/onebot/types';
|
import { OB11PostSendMsg } from '@/onebot/types';
|
||||||
|
|
||||||
// 未检测参数
|
// 未检测参数
|
||||||
class SendGroupMsg extends SendMsg {
|
class SendGroupMsg extends SendMsgBase {
|
||||||
actionName = ActionName.SendGroupMsg;
|
actionName = ActionName.SendGroupMsg;
|
||||||
contextMode: ContextMode = ContextMode.Group;
|
contextMode: ContextMode = ContextMode.Group;
|
||||||
|
|
||||||
|
@@ -103,10 +103,7 @@ import { GetAiCharacters } from "@/onebot/action/extends/GetAiCharacters";
|
|||||||
import { GetGuildList } from './guild/GetGuildList';
|
import { GetGuildList } from './guild/GetGuildList';
|
||||||
import { GetGuildProfile } from './guild/GetGuildProfile';
|
import { GetGuildProfile } from './guild/GetGuildProfile';
|
||||||
|
|
||||||
|
export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
||||||
export type ActionMap = Map<string, OneBotAction<any, any>>;
|
|
||||||
|
|
||||||
export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore): ActionMap {
|
|
||||||
|
|
||||||
const actionHandlers = [
|
const actionHandlers = [
|
||||||
new GetGroupInfoEx(obContext, core),
|
new GetGroupInfoEx(obContext, core),
|
||||||
@@ -220,12 +217,30 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
|
|||||||
new SendGroupAiRecord(obContext, core),
|
new SendGroupAiRecord(obContext, core),
|
||||||
new GetAiCharacters(obContext, core),
|
new GetAiCharacters(obContext, core),
|
||||||
];
|
];
|
||||||
const actionMap = new Map();
|
|
||||||
for (const action of actionHandlers) {
|
type HandlerUnion = typeof actionHandlers[number];
|
||||||
actionMap.set(action.actionName, action);
|
type MapType = {
|
||||||
actionMap.set(action.actionName + '_async', action);
|
[H in HandlerUnion as H['actionName']]: H;
|
||||||
actionMap.set(action.actionName + '_rate_limited', action);
|
} & {
|
||||||
|
[H in HandlerUnion as `${H['actionName']}_async`]: H;
|
||||||
|
} & {
|
||||||
|
[H in HandlerUnion as `${H['actionName']}_rate_limited`]: H;
|
||||||
|
};
|
||||||
|
|
||||||
|
const _map = new Map<keyof MapType, HandlerUnion>();
|
||||||
|
|
||||||
|
actionHandlers.forEach(h => {
|
||||||
|
_map.set(h.actionName as keyof MapType, h);
|
||||||
|
_map.set(`${h.actionName}_async` as keyof MapType, h);
|
||||||
|
_map.set(`${h.actionName}_rate_limited` as keyof MapType, h);
|
||||||
|
});
|
||||||
|
|
||||||
|
function get<K extends keyof MapType>(key: K): MapType[K];
|
||||||
|
function get<K extends keyof MapType>(key: K): null;
|
||||||
|
function get<K extends keyof MapType>(key: K): HandlerUnion | null | MapType[K] {
|
||||||
|
return _map.get(key as keyof MapType) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return actionMap;
|
return { get };
|
||||||
}
|
}
|
||||||
|
export type ActionMap = ReturnType<typeof createActionMap>
|
||||||
|
@@ -88,8 +88,7 @@ function getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SendMsg extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
|
export class SendMsgBase extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
|
||||||
actionName = ActionName.SendMsg;
|
|
||||||
contextMode = ContextMode.Normal;
|
contextMode = ContextMode.Normal;
|
||||||
|
|
||||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||||
@@ -379,4 +378,6 @@ export class SendMsg extends OneBotAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SendMsg;
|
export default class SendMsg extends SendMsgBase {
|
||||||
|
actionName = ActionName.SendMsg;
|
||||||
|
}
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import SendMsg, { ContextMode } from './SendMsg';
|
import {ContextMode, SendMsgBase} from './SendMsg';
|
||||||
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
||||||
import { OB11PostSendMsg } from '@/onebot/types';
|
import { OB11PostSendMsg } from '@/onebot/types';
|
||||||
|
|
||||||
// 未检测参数
|
// 未检测参数
|
||||||
class SendPrivateMsg extends SendMsg {
|
class SendPrivateMsg extends SendMsgBase {
|
||||||
actionName = ActionName.SendPrivateMsg;
|
actionName = ActionName.SendPrivateMsg;
|
||||||
contextMode: ContextMode = ContextMode.Private;
|
contextMode: ContextMode = ContextMode.Private;
|
||||||
|
|
||||||
|
@@ -3,8 +3,6 @@ import { ActionName, BaseCheckResult } from '@/onebot/action/router';
|
|||||||
|
|
||||||
|
|
||||||
export abstract class GetPacketStatusDepends<PT, RT> extends OneBotAction<PT, RT> {
|
export abstract class GetPacketStatusDepends<PT, RT> extends OneBotAction<PT, RT> {
|
||||||
actionName = ActionName.GetPacketStatus;
|
|
||||||
|
|
||||||
protected async check(payload: PT): Promise<BaseCheckResult>{
|
protected async check(payload: PT): Promise<BaseCheckResult>{
|
||||||
if (!this.core.apis.PacketApi.available) {
|
if (!this.core.apis.PacketApi.available) {
|
||||||
return {
|
return {
|
||||||
@@ -18,6 +16,8 @@ export abstract class GetPacketStatusDepends<PT, RT> extends OneBotAction<PT, RT
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class GetPacketStatus extends GetPacketStatusDepends<any, null> {
|
export class GetPacketStatus extends GetPacketStatusDepends<any, null> {
|
||||||
|
actionName = ActionName.GetPacketStatus;
|
||||||
|
|
||||||
async _handle(payload: any) {
|
async _handle(payload: any) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -13,134 +13,134 @@ export interface InvalidCheckResult {
|
|||||||
[k: string | number]: any;
|
[k: string | number]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ActionName {
|
export const ActionName = {
|
||||||
// onebot 11
|
// onebot 11
|
||||||
SendPrivateMsg = 'send_private_msg',
|
SendPrivateMsg : 'send_private_msg',
|
||||||
SendGroupMsg = 'send_group_msg',
|
SendGroupMsg : 'send_group_msg',
|
||||||
SendMsg = 'send_msg',
|
SendMsg : 'send_msg',
|
||||||
DeleteMsg = 'delete_msg',
|
DeleteMsg : 'delete_msg',
|
||||||
GetMsg = 'get_msg',
|
GetMsg : 'get_msg',
|
||||||
GoCQHTTP_GetForwardMsg = 'get_forward_msg',
|
GoCQHTTP_GetForwardMsg : 'get_forward_msg',
|
||||||
SendLike = 'send_like',
|
SendLike : 'send_like',
|
||||||
SetGroupKick = 'set_group_kick',
|
SetGroupKick : 'set_group_kick',
|
||||||
SetGroupBan = 'set_group_ban',
|
SetGroupBan : 'set_group_ban',
|
||||||
// SetGroupAnoymousBan = 'set_group_anonymous_ban',
|
// SetGroupAnoymousBan : 'set_group_anonymous_ban',
|
||||||
SetGroupWholeBan = 'set_group_whole_ban',
|
SetGroupWholeBan : 'set_group_whole_ban',
|
||||||
SetGroupAdmin = 'set_group_admin',
|
SetGroupAdmin : 'set_group_admin',
|
||||||
// SetGroupAnoymous = 'set_group_anonymous',
|
// SetGroupAnoymous : 'set_group_anonymous',
|
||||||
SetGroupCard = 'set_group_card',
|
SetGroupCard : 'set_group_card',
|
||||||
SetGroupName = 'set_group_name',
|
SetGroupName : 'set_group_name',
|
||||||
SetGroupLeave = 'set_group_leave',
|
SetGroupLeave : 'set_group_leave',
|
||||||
SetSpecialTittle = 'set_group_special_title',
|
SetSpecialTittle : 'set_group_special_title',
|
||||||
SetFriendAddRequest = 'set_friend_add_request',
|
SetFriendAddRequest : 'set_friend_add_request',
|
||||||
SetGroupAddRequest = 'set_group_add_request',
|
SetGroupAddRequest : 'set_group_add_request',
|
||||||
GetLoginInfo = 'get_login_info',
|
GetLoginInfo : 'get_login_info',
|
||||||
GoCQHTTP_GetStrangerInfo = 'get_stranger_info',
|
GoCQHTTP_GetStrangerInfo : 'get_stranger_info',
|
||||||
GetFriendList = 'get_friend_list',
|
GetFriendList : 'get_friend_list',
|
||||||
GetGroupInfo = 'get_group_info',
|
GetGroupInfo : 'get_group_info',
|
||||||
GetGroupList = 'get_group_list',
|
GetGroupList : 'get_group_list',
|
||||||
GetGroupMemberInfo = 'get_group_member_info',
|
GetGroupMemberInfo : 'get_group_member_info',
|
||||||
GetGroupMemberList = 'get_group_member_list',
|
GetGroupMemberList : 'get_group_member_list',
|
||||||
GetGroupHonorInfo = 'get_group_honor_info',
|
GetGroupHonorInfo : 'get_group_honor_info',
|
||||||
GetCookies = 'get_cookies',
|
GetCookies : 'get_cookies',
|
||||||
GetCSRF = 'get_csrf_token',
|
GetCSRF : 'get_csrf_token',
|
||||||
GetCredentials = 'get_credentials',
|
GetCredentials : 'get_credentials',
|
||||||
GetRecord = 'get_record',
|
GetRecord : 'get_record',
|
||||||
GetImage = 'get_image',
|
GetImage : 'get_image',
|
||||||
CanSendImage = 'can_send_image',
|
CanSendImage : 'can_send_image',
|
||||||
CanSendRecord = 'can_send_record',
|
CanSendRecord : 'can_send_record',
|
||||||
GetStatus = 'get_status',
|
GetStatus : 'get_status',
|
||||||
GetVersionInfo = 'get_version_info',
|
GetVersionInfo : 'get_version_info',
|
||||||
// Reboot = 'set_restart',
|
// Reboot : 'set_restart',
|
||||||
// CleanCache = 'clean_cache',
|
// CleanCache : 'clean_cache',
|
||||||
|
|
||||||
// go-cqhttp
|
// go-cqhttp
|
||||||
SetQQProfile = 'set_qq_profile',
|
SetQQProfile : 'set_qq_profile',
|
||||||
// QidianGetAccountInfo = 'qidian_get_account_info',
|
// QidianGetAccountInfo : 'qidian_get_account_info',
|
||||||
GoCQHTTP_GetModelShow = '_get_model_show',
|
GoCQHTTP_GetModelShow : '_get_model_show',
|
||||||
GoCQHTTP_SetModelShow = '_set_model_show',
|
GoCQHTTP_SetModelShow : '_set_model_show',
|
||||||
GetOnlineClient = 'get_online_clients',
|
GetOnlineClient : 'get_online_clients',
|
||||||
// GetUnidirectionalFriendList = 'get_unidirectional_friend_list',
|
// GetUnidirectionalFriendList : 'get_unidirectional_friend_list',
|
||||||
GoCQHTTP_DeleteFriend = 'delete_friend',
|
GoCQHTTP_DeleteFriend : 'delete_friend',
|
||||||
// DeleteUnidirectionalFriendList = 'delete_unidirectional_friend',
|
// DeleteUnidirectionalFriendList : 'delete_unidirectional_friend',
|
||||||
GoCQHTTP_MarkMsgAsRead = 'mark_msg_as_read',
|
GoCQHTTP_MarkMsgAsRead : 'mark_msg_as_read',
|
||||||
GoCQHTTP_SendGroupForwardMsg = 'send_group_forward_msg',
|
GoCQHTTP_SendGroupForwardMsg : 'send_group_forward_msg',
|
||||||
GoCQHTTP_SendPrivateForwardMsg = 'send_private_forward_msg',
|
GoCQHTTP_SendPrivateForwardMsg : 'send_private_forward_msg',
|
||||||
GoCQHTTP_GetGroupMsgHistory = 'get_group_msg_history',
|
GoCQHTTP_GetGroupMsgHistory : 'get_group_msg_history',
|
||||||
OCRImage = 'ocr_image',
|
OCRImage : 'ocr_image',
|
||||||
IOCRImage = '.ocr_image',
|
IOCRImage : '.ocr_image',
|
||||||
GetGroupSystemMsg = 'get_group_system_msg',
|
GetGroupSystemMsg : 'get_group_system_msg',
|
||||||
GoCQHTTP_GetEssenceMsg = 'get_essence_msg_list',
|
GoCQHTTP_GetEssenceMsg : 'get_essence_msg_list',
|
||||||
GoCQHTTP_GetGroupAtAllRemain = 'get_group_at_all_remain',
|
GoCQHTTP_GetGroupAtAllRemain : 'get_group_at_all_remain',
|
||||||
SetGroupPortrait = 'set_group_portrait',
|
SetGroupPortrait : 'set_group_portrait',
|
||||||
SetEssenceMsg = 'set_essence_msg',
|
SetEssenceMsg : 'set_essence_msg',
|
||||||
DelEssenceMsg = 'delete_essence_msg',
|
DelEssenceMsg : 'delete_essence_msg',
|
||||||
GoCQHTTP_SendGroupNotice = '_send_group_notice',
|
GoCQHTTP_SendGroupNotice : '_send_group_notice',
|
||||||
GoCQHTTP_GetGroupNotice = '_get_group_notice',
|
GoCQHTTP_GetGroupNotice : '_get_group_notice',
|
||||||
GoCQHTTP_UploadGroupFile = 'upload_group_file',
|
GoCQHTTP_UploadGroupFile : 'upload_group_file',
|
||||||
GOCQHTTP_DeleteGroupFile = 'delete_group_file',
|
GOCQHTTP_DeleteGroupFile : 'delete_group_file',
|
||||||
GoCQHTTP_CreateGroupFileFolder = 'create_group_file_folder',
|
GoCQHTTP_CreateGroupFileFolder : 'create_group_file_folder',
|
||||||
GoCQHTTP_DeleteGroupFileFolder = 'delete_group_folder',
|
GoCQHTTP_DeleteGroupFileFolder : 'delete_group_folder',
|
||||||
GoCQHTTP_GetGroupFileSystemInfo = 'get_group_file_system_info',
|
GoCQHTTP_GetGroupFileSystemInfo : 'get_group_file_system_info',
|
||||||
GoCQHTTP_GetGroupRootFiles = 'get_group_root_files',
|
GoCQHTTP_GetGroupRootFiles : 'get_group_root_files',
|
||||||
GoCQHTTP_GetGroupFilesByFolder = 'get_group_files_by_folder',
|
GoCQHTTP_GetGroupFilesByFolder : 'get_group_files_by_folder',
|
||||||
GOCQHTTP_GetGroupFileUrl = 'get_group_file_url',
|
GOCQHTTP_GetGroupFileUrl : 'get_group_file_url',
|
||||||
GOCQHTTP_UploadPrivateFile = 'upload_private_file',
|
GOCQHTTP_UploadPrivateFile : 'upload_private_file',
|
||||||
// GOCQHTTP_ReloadEventFilter = 'reload_event_filter',
|
// GOCQHTTP_ReloadEventFilter : 'reload_event_filter',
|
||||||
GoCQHTTP_DownloadFile = 'download_file',
|
GoCQHTTP_DownloadFile : 'download_file',
|
||||||
GoCQHTTP_CheckUrlSafely = 'check_url_safely',
|
GoCQHTTP_CheckUrlSafely : 'check_url_safely',
|
||||||
GoCQHTTP_GetWordSlices = '.get_word_slices',
|
GoCQHTTP_GetWordSlices : '.get_word_slices',
|
||||||
GoCQHTTP_HandleQuickAction = '.handle_quick_operation',
|
GoCQHTTP_HandleQuickAction : '.handle_quick_operation',
|
||||||
|
|
||||||
// 以下为扩展napcat扩展
|
// 以下为扩展napcat扩展
|
||||||
Unknown = 'unknown',
|
Unknown : 'unknown',
|
||||||
SharePeer = 'ArkSharePeer',
|
SharePeer : 'ArkSharePeer',
|
||||||
ShareGroupEx = 'ArkShareGroup',
|
ShareGroupEx : 'ArkShareGroup',
|
||||||
// RebootNormal = 'reboot_normal', //无快速登录重新启动
|
// RebootNormal : 'reboot_normal', //无快速登录重新启动
|
||||||
GetRobotUinRange = 'get_robot_uin_range',
|
GetRobotUinRange : 'get_robot_uin_range',
|
||||||
SetOnlineStatus = 'set_online_status',
|
SetOnlineStatus : 'set_online_status',
|
||||||
GetFriendsWithCategory = 'get_friends_with_category',
|
GetFriendsWithCategory : 'get_friends_with_category',
|
||||||
SetQQAvatar = 'set_qq_avatar',
|
SetQQAvatar : 'set_qq_avatar',
|
||||||
GetFile = 'get_file',
|
GetFile : 'get_file',
|
||||||
ForwardFriendSingleMsg = 'forward_friend_single_msg',
|
ForwardFriendSingleMsg : 'forward_friend_single_msg',
|
||||||
ForwardGroupSingleMsg = 'forward_group_single_msg',
|
ForwardGroupSingleMsg : 'forward_group_single_msg',
|
||||||
TranslateEnWordToZn = 'translate_en2zh',
|
TranslateEnWordToZn : 'translate_en2zh',
|
||||||
SetMsgEmojiLike = 'set_msg_emoji_like',
|
SetMsgEmojiLike : 'set_msg_emoji_like',
|
||||||
GoCQHTTP_SendForwardMsg = 'send_forward_msg',
|
GoCQHTTP_SendForwardMsg : 'send_forward_msg',
|
||||||
MarkPrivateMsgAsRead = 'mark_private_msg_as_read',
|
MarkPrivateMsgAsRead : 'mark_private_msg_as_read',
|
||||||
MarkGroupMsgAsRead = 'mark_group_msg_as_read',
|
MarkGroupMsgAsRead : 'mark_group_msg_as_read',
|
||||||
GetFriendMsgHistory = 'get_friend_msg_history',
|
GetFriendMsgHistory : 'get_friend_msg_history',
|
||||||
CreateCollection = 'create_collection',
|
CreateCollection : 'create_collection',
|
||||||
GetCollectionList = 'get_collection_list',
|
GetCollectionList : 'get_collection_list',
|
||||||
SetLongNick = 'set_self_longnick',
|
SetLongNick : 'set_self_longnick',
|
||||||
GetRecentContact = 'get_recent_contact',
|
GetRecentContact : 'get_recent_contact',
|
||||||
_MarkAllMsgAsRead = '_mark_all_as_read',
|
_MarkAllMsgAsRead : '_mark_all_as_read',
|
||||||
GetProfileLike = 'get_profile_like',
|
GetProfileLike : 'get_profile_like',
|
||||||
FetchCustomFace = 'fetch_custom_face',
|
FetchCustomFace : 'fetch_custom_face',
|
||||||
FetchEmojiLike = 'fetch_emoji_like',
|
FetchEmojiLike : 'fetch_emoji_like',
|
||||||
SetInputStatus = 'set_input_status',
|
SetInputStatus : 'set_input_status',
|
||||||
GetGroupInfoEx = 'get_group_info_ex',
|
GetGroupInfoEx : 'get_group_info_ex',
|
||||||
GetGroupIgnoreAddRequest = 'get_group_ignore_add_request',
|
GetGroupIgnoreAddRequest : 'get_group_ignore_add_request',
|
||||||
DelGroupNotice = '_del_group_notice',
|
DelGroupNotice : '_del_group_notice',
|
||||||
FetchUserProfileLike = 'fetch_user_profile_like',
|
FetchUserProfileLike : 'fetch_user_profile_like',
|
||||||
FriendPoke = 'friend_poke',
|
FriendPoke : 'friend_poke',
|
||||||
GroupPoke = 'group_poke',
|
GroupPoke : 'group_poke',
|
||||||
GetPacketStatus = 'nc_get_packet_status',
|
GetPacketStatus : 'nc_get_packet_status',
|
||||||
GetUserStatus = 'nc_get_user_status',
|
GetUserStatus : 'nc_get_user_status',
|
||||||
GetRkey = 'nc_get_rkey',
|
GetRkey : 'nc_get_rkey',
|
||||||
GetGroupShutList = 'get_group_shut_list',
|
GetGroupShutList : 'get_group_shut_list',
|
||||||
|
|
||||||
GetGuildList = 'get_guild_list',
|
GetGuildList : 'get_guild_list',
|
||||||
GetGuildProfile = 'get_guild_service_profile',
|
GetGuildProfile : 'get_guild_service_profile',
|
||||||
|
|
||||||
GetGroupIgnoredNotifies = 'get_group_ignored_notifies',
|
GetGroupIgnoredNotifies : 'get_group_ignored_notifies',
|
||||||
|
|
||||||
SetGroupSign = "set_group_sign",
|
SetGroupSign : "set_group_sign",
|
||||||
SendGroupSign = "send_group_sign",
|
SendGroupSign : "send_group_sign",
|
||||||
|
|
||||||
GetMiniAppArk = "get_mini_app_ark",
|
GetMiniAppArk : "get_mini_app_ark",
|
||||||
// UploadForwardMsg = "upload_forward_msg",
|
// UploadForwardMsg : "upload_forward_msg",
|
||||||
GetAiRecord = "get_ai_record",
|
GetAiRecord : "get_ai_record",
|
||||||
GetAiCharacters = "get_ai_characters",
|
GetAiCharacters : "get_ai_characters",
|
||||||
SendGroupAiRecord = "send_group_ai_record",
|
SendGroupAiRecord : "send_group_ai_record",
|
||||||
}
|
} as const;
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import CanSendRecord from './CanSendRecord';
|
import CanSendRecord, {CanSend} from './CanSendRecord';
|
||||||
|
|
||||||
interface ReturnType {
|
interface ReturnType {
|
||||||
yes: boolean;
|
yes: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CanSendImage extends CanSendRecord {
|
export default class CanSendImage extends CanSend {
|
||||||
actionName = ActionName.CanSendImage;
|
actionName = ActionName.CanSendImage;
|
||||||
}
|
}
|
||||||
|
@@ -5,12 +5,15 @@ interface ReturnType {
|
|||||||
yes: boolean;
|
yes: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CanSendRecord extends OneBotAction<any, ReturnType> {
|
export class CanSend extends OneBotAction<any, ReturnType> {
|
||||||
actionName = ActionName.CanSendRecord;
|
|
||||||
|
|
||||||
async _handle(_payload: void): Promise<ReturnType> {
|
async _handle(_payload: void): Promise<ReturnType> {
|
||||||
return {
|
return {
|
||||||
yes: true,
|
yes: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default class CanSendRecord extends CanSend{
|
||||||
|
actionName = ActionName.CanSendRecord;
|
||||||
|
}
|
||||||
|
@@ -18,8 +18,8 @@ import { ContextMode, createContext, normalize } from '@/onebot/action/msg/SendM
|
|||||||
import { isNull } from '@/common/helper';
|
import { isNull } from '@/common/helper';
|
||||||
|
|
||||||
export class OneBotQuickActionApi {
|
export class OneBotQuickActionApi {
|
||||||
private obContext: NapCatOneBot11Adapter;
|
obContext: NapCatOneBot11Adapter;
|
||||||
private core: NapCatCore;
|
core: NapCatCore;
|
||||||
constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
||||||
this.obContext = obContext;
|
this.obContext = obContext;
|
||||||
this.core = core;
|
this.core = core;
|
||||||
@@ -82,11 +82,20 @@ export class OneBotQuickActionApi {
|
|||||||
this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles, false).then().catch(e => this.core.context.logger.logError(e));
|
this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles, false).then().catch(e => this.core.context.logger.logError(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async findNotify(flag: string) {
|
||||||
|
let notify = (await this.core.apis.GroupApi.getSingleScreenNotifies(false, 100)).find(e => e.seq == flag);
|
||||||
|
if (!notify) {
|
||||||
|
notify = (await this.core.apis.GroupApi.getSingleScreenNotifies(true, 100)).find(e => e.seq == flag);
|
||||||
|
}
|
||||||
|
return notify;
|
||||||
|
}
|
||||||
|
|
||||||
async handleGroupRequest(request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) {
|
async handleGroupRequest(request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) {
|
||||||
if (!isNull(quickAction.approve)) {
|
let noify = await this.findNotify(request.flag);
|
||||||
|
|
||||||
|
if (!isNull(quickAction.approve) && noify) {
|
||||||
this.core.apis.GroupApi.handleGroupRequest(
|
this.core.apis.GroupApi.handleGroupRequest(
|
||||||
request.flag,
|
noify,
|
||||||
quickAction.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
quickAction.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
||||||
quickAction.reason,
|
quickAction.reason,
|
||||||
).catch(e => this.core.context.logger.logError(e));
|
).catch(e => this.core.context.logger.logError(e));
|
||||||
@@ -94,8 +103,9 @@ export class OneBotQuickActionApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleFriendRequest(request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) {
|
async handleFriendRequest(request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) {
|
||||||
if (!isNull(quickAction.approve)) {
|
const notify = (await this.core.apis.FriendApi.getBuddyReq()).buddyReqs.find(e => e.reqTime == request.flag.toString());
|
||||||
this.core.apis.FriendApi.handleFriendRequest(request.flag, !!quickAction.approve).then().catch(e => this.core.context.logger.logError(e));
|
if (!isNull(quickAction.approve) && notify) {
|
||||||
|
this.core.apis.FriendApi.handleFriendRequest(notify, !!quickAction.approve).then().catch(e => this.core.context.logger.logError(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -157,9 +157,9 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.initBuddyListener();
|
this.initBuddyListener();
|
||||||
this.initGroupListener();
|
this.initGroupListener();
|
||||||
|
|
||||||
await WebUiDataRuntime.setQQLoginUin(selfInfo.uin.toString());
|
WebUiDataRuntime.setQQLoginInfo(selfInfo);
|
||||||
await WebUiDataRuntime.setQQLoginStatus(true);
|
WebUiDataRuntime.setQQLoginStatus(true);
|
||||||
await WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
|
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
|
||||||
const prev = this.configLoader.configData;
|
const prev = this.configLoader.configData;
|
||||||
this.configLoader.save(newConfig);
|
this.configLoader.save(newConfig);
|
||||||
this.context.logger.log(`OneBot11 配置更改:${JSON.stringify(prev)} -> ${JSON.stringify(newConfig)}`);
|
this.context.logger.log(`OneBot11 配置更改:${JSON.stringify(prev)} -> ${JSON.stringify(newConfig)}`);
|
||||||
@@ -207,7 +207,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 通知新配置重载 删除关闭的 加入新开的
|
// 通知新配置重载 删除关闭的 加入新开的
|
||||||
for (const adapterConfig of nowConfig) {
|
for (const adapterConfig of nowConfig) {
|
||||||
const existingAdapter = this.networkManager.findSomeAdapter(adapterConfig.name);
|
const existingAdapter = this.networkManager.findSomeAdapter(adapterConfig.name);
|
||||||
if (existingAdapter) {
|
if (existingAdapter) {
|
||||||
|
@@ -11,7 +11,8 @@ import { ActionMap } from '@/onebot/action';
|
|||||||
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||||
logger: LogWrapper;
|
logger: LogWrapper;
|
||||||
isEnable: boolean = false;
|
isEnable: boolean = false;
|
||||||
public config: HttpClientConfig;
|
config: HttpClientConfig;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public name: string,
|
public name: string,
|
||||||
config: HttpClientConfig,
|
config: HttpClientConfig,
|
||||||
@@ -24,39 +25,32 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||||
if (!this.isEnable) {
|
this.emitEventAsync(event).catch(e => this.logger.logError('[OneBot] [Http Client] 新消息事件HTTP上报返回快速操作失败', e));
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
async emitEventAsync<T extends OB11EmitEventContent>(event: T) {
|
||||||
|
if (!this.isEnable) return;
|
||||||
|
|
||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'x-self-id': this.core.selfInfo.uin,
|
'x-self-id': this.core.selfInfo.uin,
|
||||||
};
|
};
|
||||||
|
|
||||||
const msgStr = JSON.stringify(event);
|
const msgStr = JSON.stringify(event);
|
||||||
if (this.config.token && this.config.token.length > 0) {
|
if (this.config.token) {
|
||||||
const hmac = createHmac('sha1', this.config.token);
|
const hmac = createHmac('sha1', this.config.token);
|
||||||
hmac.update(msgStr);
|
hmac.update(msgStr);
|
||||||
const sig = hmac.digest('hex');
|
headers['x-signature'] = 'sha1=' + hmac.digest('hex');
|
||||||
headers['x-signature'] = 'sha1=' + sig;
|
|
||||||
}
|
}
|
||||||
RequestUtil.HttpGetText(this.config.url, 'POST', msgStr, headers).then(async (res) => {
|
|
||||||
let resJson: QuickAction;
|
const data = await RequestUtil.HttpGetText(this.config.url, 'POST', msgStr, headers);
|
||||||
try {
|
const resJson: QuickAction = data ? JSON.parse(data) : {};
|
||||||
resJson = JSON.parse(res);
|
|
||||||
//logDebug('新消息事件HTTP上报返回快速操作: ', JSON.stringify(resJson));
|
if (!this.obContext.apis.QuickActionApi.handleQuickOperation) {
|
||||||
} catch (e) {
|
throw new Error('apis.QuickActionApi.handleQuickOperation 异常');
|
||||||
this.logger.logDebug('[OneBot] [Http Client] 新消息事件HTTP上报没有返回快速操作,不需要处理');
|
}
|
||||||
return;
|
|
||||||
}
|
await this.obContext.apis.QuickActionApi.handleQuickOperation(event as QuickActionEvent, resJson);
|
||||||
try {
|
|
||||||
this.obContext.apis.QuickActionApi
|
|
||||||
.handleQuickOperation(event as QuickActionEvent, resJson)
|
|
||||||
.catch(e => this.logger.logError(e));
|
|
||||||
} catch (e: any) {
|
|
||||||
this.logger.logError('[OneBot] [Http Client] 新消息事件HTTP上报返回快速操作失败', e);
|
|
||||||
}
|
|
||||||
}).catch((e) => {
|
|
||||||
this.logger.logError('[OneBot] [Http Client] 新消息事件HTTP上报失败', e);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
@@ -66,20 +60,24 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
close() {
|
close() {
|
||||||
this.isEnable = false;
|
this.isEnable = false;
|
||||||
}
|
}
|
||||||
async reload(newconfig: HttpClientConfig) {
|
|
||||||
|
async reload(newConfig: HttpClientConfig) {
|
||||||
const wasEnabled = this.isEnable;
|
const wasEnabled = this.isEnable;
|
||||||
const oldUrl = this.config.url;
|
const oldUrl = this.config.url;
|
||||||
this.config = newconfig;
|
this.config = newConfig;
|
||||||
if (newconfig.enable && !wasEnabled) {
|
|
||||||
|
if (newConfig.enable && !wasEnabled) {
|
||||||
this.open();
|
this.open();
|
||||||
return OB11NetworkReloadType.NetWorkOpen;
|
return OB11NetworkReloadType.NetWorkOpen;
|
||||||
} else if (!newconfig.enable && wasEnabled) {
|
} else if (!newConfig.enable && wasEnabled) {
|
||||||
this.close();
|
this.close();
|
||||||
return OB11NetworkReloadType.NetWorkClose;
|
return OB11NetworkReloadType.NetWorkClose;
|
||||||
}
|
}
|
||||||
if (oldUrl !== newconfig.url) {
|
|
||||||
|
if (oldUrl !== newConfig.url) {
|
||||||
return OB11NetworkReloadType.NetWorkReload;
|
return OB11NetworkReloadType.NetWorkReload;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OB11NetworkReloadType.Normal;
|
return OB11NetworkReloadType.Normal;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -2,7 +2,7 @@ import { IOB11NetworkAdapter, OB11EmitEventContent, OB11NetworkReloadType } from
|
|||||||
import { WebSocket } from 'ws';
|
import { WebSocket } from 'ws';
|
||||||
import { OB11HeartbeatEvent } from '@/onebot/event/meta/OB11HeartbeatEvent';
|
import { OB11HeartbeatEvent } from '@/onebot/event/meta/OB11HeartbeatEvent';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { OB11Response } from '@/onebot/action/OneBotAction';
|
import { OB11Response } from '@/onebot/action/OneBotAction';
|
||||||
import { LogWrapper } from '@/common/log';
|
import { LogWrapper } from '@/common/log';
|
||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
@@ -133,7 +133,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleMessage(message: any) {
|
private async handleMessage(message: any) {
|
||||||
let receiveData: { action: ActionName, params?: any, echo?: any } = { action: ActionName.Unknown, params: {} };
|
let receiveData: { action: typeof ActionName[keyof typeof ActionName], params?: any, echo?: any } = { action: ActionName.Unknown, params: {} };
|
||||||
let echo = undefined;
|
let echo = undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -145,7 +145,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
receiveData.params = (receiveData?.params) ? receiveData.params : {};// 兼容类型验证
|
receiveData.params = (receiveData?.params) ? receiveData.params : {};// 兼容类型验证
|
||||||
const action = this.actions.get(receiveData.action);
|
const action = this.actions.get(receiveData.action as any);
|
||||||
if (!action) {
|
if (!action) {
|
||||||
this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的Api ' + receiveData.action);
|
this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的Api ' + receiveData.action);
|
||||||
this.checkStateAndReply<any>(OB11Response.error('不支持的Api ' + receiveData.action, 1404, echo));
|
this.checkStateAndReply<any>(OB11Response.error('不支持的Api ' + receiveData.action, 1404, echo));
|
||||||
|
@@ -105,7 +105,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
return res.json(hello);
|
return res.json(hello);
|
||||||
}
|
}
|
||||||
const actionName = req.path.split('/')[1];
|
const actionName = req.path.split('/')[1];
|
||||||
const action = this.actions.get(actionName);
|
const action = this.actions.get(actionName as any);
|
||||||
if (action) {
|
if (action) {
|
||||||
try {
|
try {
|
||||||
const result = await action.handle(payload, this.name);
|
const result = await action.handle(payload, this.name);
|
||||||
|
@@ -166,7 +166,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleMessage(wsClient: WebSocket, message: any) {
|
private async handleMessage(wsClient: WebSocket, message: any) {
|
||||||
let receiveData: { action: ActionName, params?: any, echo?: any } = { action: ActionName.Unknown, params: {} };
|
let receiveData: { action: typeof ActionName[keyof typeof ActionName], params?: any, echo?: any } = { action: ActionName.Unknown, params: {} };
|
||||||
let echo = undefined;
|
let echo = undefined;
|
||||||
try {
|
try {
|
||||||
receiveData = JSON.parse(message.toString());
|
receiveData = JSON.parse(message.toString());
|
||||||
@@ -177,7 +177,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
receiveData.params = (receiveData?.params) ? receiveData.params : {};//兼容类型验证 不然类型校验爆炸
|
receiveData.params = (receiveData?.params) ? receiveData.params : {};//兼容类型验证 不然类型校验爆炸
|
||||||
const action = this.actions.get(receiveData.action);
|
const action = this.actions.get(receiveData.action as any);
|
||||||
if (!action) {
|
if (!action) {
|
||||||
this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的API ' + receiveData.action);
|
this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的API ' + receiveData.action);
|
||||||
this.checkStateAndReply<any>(OB11Response.error('不支持的API ' + receiveData.action, 1404, echo), wsClient);
|
this.checkStateAndReply<any>(OB11Response.error('不支持的API ' + receiveData.action, 1404, echo), wsClient);
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import { IOB11NetworkAdapter, OB11EmitEventContent, OB11NetworkReloadType } from './index';
|
import { IOB11NetworkAdapter, OB11EmitEventContent, OB11NetworkReloadType } from './index';
|
||||||
import { NapCatOneBot11Adapter, OB11Message } from '@/onebot';
|
import { NapCatOneBot11Adapter, OB11Message } from '@/onebot';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { ActionMap } from '../action';
|
|
||||||
import { AdapterConfig } from '../config/config';
|
import { AdapterConfig } from '../config/config';
|
||||||
import { plugin_onmessage } from '@/plugin';
|
import { plugin_onmessage } from '@/plugin';
|
||||||
|
import { ActionMap } from '../action';
|
||||||
|
|
||||||
export class OB11PluginAdapter implements IOB11NetworkAdapter {
|
export class OB11PluginAdapter implements IOB11NetworkAdapter {
|
||||||
isEnable: boolean = true;
|
isEnable: boolean = true;
|
||||||
@@ -27,7 +27,7 @@ export class OB11PluginAdapter implements IOB11NetworkAdapter {
|
|||||||
|
|
||||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||||
if (event.post_type === 'message') {
|
if (event.post_type === 'message') {
|
||||||
plugin_onmessage(this.config.name, this.core, this.obCore, event as OB11Message).then().catch();
|
plugin_onmessage(this.config.name, this.core, this.obCore, event as OB11Message,this.actions).then().catch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
import { NapCatOneBot11Adapter, OB11Message } from "@/onebot";
|
import { NapCatOneBot11Adapter, OB11Message } from "@/onebot";
|
||||||
import { NapCatCore } from "../core";
|
import { NapCatCore } from "../core";
|
||||||
import { SetSpecialTittle } from "@/onebot/action/extends/SetSpecialTittle";
|
import { ActionMap } from "@/onebot/action";
|
||||||
|
|
||||||
export const plugin_onmessage = async (adapter: string, core: NapCatCore, obCore: NapCatOneBot11Adapter, message: OB11Message) => {
|
export const plugin_onmessage = async (adapter: string, core: NapCatCore, obCore: NapCatOneBot11Adapter, message: OB11Message, action: ActionMap) => {
|
||||||
if (message.raw_message.startsWith('设置头衔') && message.group_id) {
|
if (message.raw_message === 'ping') {
|
||||||
const ret = await new SetSpecialTittle(obCore, core)
|
const ret = await action.get('send_group_msg')?.handle({ group_id: String(message.group_id), message: 'pong' }, adapter);
|
||||||
.handle({ group_id: message.group_id, user_id: message.user_id, special_title: message.raw_message.replace('设置头衔', '') }, adapter);
|
console.log(ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -175,7 +175,9 @@ async function handleLogin(
|
|||||||
|
|
||||||
loginService.getLoginList().then((res) => {
|
loginService.getLoginList().then((res) => {
|
||||||
// 遍历 res.LocalLoginInfoList[x].isQuickLogin是否可以 res.LocalLoginInfoList[x].uin 转为string 加入string[] 最后遍历完成调用WebUiDataRuntime.setQQQuickLoginList
|
// 遍历 res.LocalLoginInfoList[x].isQuickLogin是否可以 res.LocalLoginInfoList[x].uin 转为string 加入string[] 最后遍历完成调用WebUiDataRuntime.setQQQuickLoginList
|
||||||
WebUiDataRuntime.setQQQuickLoginList(res.LocalLoginInfoList.filter((item) => item.isQuickLogin).map((item) => item.uin.toString()));
|
const list = res.LocalLoginInfoList.filter((item) => item.isQuickLogin);
|
||||||
|
WebUiDataRuntime.setQQQuickLoginList(list.map((item) => item.uin.toString()));
|
||||||
|
WebUiDataRuntime.setQQNewLoginList(list);
|
||||||
});
|
});
|
||||||
|
|
||||||
WebUiDataRuntime.setQuickLoginCall(async (uin: string) => {
|
WebUiDataRuntime.setQuickLoginCall(async (uin: string) => {
|
||||||
@@ -285,7 +287,7 @@ export async function NCoreInitShell() {
|
|||||||
|
|
||||||
await initializeEngine(engine, basicInfoWrapper, dataPathGlobal, systemPlatform, systemVersion);
|
await initializeEngine(engine, basicInfoWrapper, dataPathGlobal, systemPlatform, systemVersion);
|
||||||
await initializeLoginService(loginService, basicInfoWrapper, dataPathGlobal, systemVersion, hostname);
|
await initializeLoginService(loginService, basicInfoWrapper, dataPathGlobal, systemVersion, hostname);
|
||||||
|
|
||||||
program.option('-q, --qq [number]', 'QQ号').parse(process.argv);
|
program.option('-q, --qq [number]', 'QQ号').parse(process.argv);
|
||||||
const cmdOptions = program.opts();
|
const cmdOptions = program.opts();
|
||||||
const quickLoginUin = cmdOptions.qq;
|
const quickLoginUin = cmdOptions.qq;
|
||||||
@@ -354,8 +356,6 @@ export class NapCatShell {
|
|||||||
};
|
};
|
||||||
this.core = new NapCatCore(this.context, selfInfo);
|
this.core = new NapCatCore(this.context, selfInfo);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
async InitNapCat() {
|
async InitNapCat() {
|
||||||
await this.core.initCore();
|
await this.core.initCore();
|
||||||
|
@@ -18,7 +18,7 @@ export const LoginHandler: RequestHandler = async (req, res) => {
|
|||||||
return sendError(res, 'token is empty');
|
return sendError(res, 'token is empty');
|
||||||
}
|
}
|
||||||
// 检查登录频率
|
// 检查登录频率
|
||||||
if (!(await WebUiDataRuntime.checkLoginRate(WebUiConfigData.loginRate))) {
|
if (!WebUiDataRuntime.checkLoginRate(WebUiConfigData.loginRate)) {
|
||||||
return sendError(res, 'login rate limit');
|
return sendError(res, 'login rate limit');
|
||||||
}
|
}
|
||||||
//验证config.token是否等于token
|
//验证config.token是否等于token
|
||||||
|
@@ -1,15 +1,9 @@
|
|||||||
import { RequestHandler } from 'express';
|
import { RequestHandler } from 'express';
|
||||||
|
import { WebUiDataRuntime } from '@webapi/helper/Data';
|
||||||
|
|
||||||
import { sendSuccess } from '@webapi/utils/response';
|
import { sendSuccess } from '@webapi/utils/response';
|
||||||
|
|
||||||
// TODO: Implement LogFileListHandler
|
export const PackageInfoHandler: RequestHandler = (_, res) => {
|
||||||
export const LogFileListHandler: RequestHandler = async (_, res) => {
|
const data = WebUiDataRuntime.getPackageJson();
|
||||||
const fakeData = {
|
sendSuccess(res, data);
|
||||||
uin: 0,
|
|
||||||
nick: 'NapCat',
|
|
||||||
avatar: 'https://q1.qlogo.cn/g?b=qq&nk=0&s=640',
|
|
||||||
status: 'online',
|
|
||||||
boottime: Date.now(),
|
|
||||||
};
|
|
||||||
sendSuccess(res, fakeData);
|
|
||||||
};
|
};
|
||||||
|
@@ -10,15 +10,15 @@ import { sendError, sendSuccess } from '@webapi/utils/response';
|
|||||||
import { isEmpty } from '@webapi/utils/check';
|
import { isEmpty } from '@webapi/utils/check';
|
||||||
|
|
||||||
// 获取OneBot11配置
|
// 获取OneBot11配置
|
||||||
export const OB11GetConfigHandler: RequestHandler = async (_, res) => {
|
export const OB11GetConfigHandler: RequestHandler = (_, res) => {
|
||||||
// 获取QQ登录状态
|
// 获取QQ登录状态
|
||||||
const isLogin = await WebUiDataRuntime.getQQLoginStatus();
|
const isLogin = WebUiDataRuntime.getQQLoginStatus();
|
||||||
// 如果未登录,返回错误
|
// 如果未登录,返回错误
|
||||||
if (!isLogin) {
|
if (!isLogin) {
|
||||||
return sendError(res, 'Not Login');
|
return sendError(res, 'Not Login');
|
||||||
}
|
}
|
||||||
// 获取登录的QQ号
|
// 获取登录的QQ号
|
||||||
const uin = await WebUiDataRuntime.getQQLoginUin();
|
const uin = WebUiDataRuntime.getQQLoginUin();
|
||||||
// 读取配置文件
|
// 读取配置文件
|
||||||
const configFilePath = resolve(webUiPathWrapper.configPath, `./onebot11_${uin}.json`);
|
const configFilePath = resolve(webUiPathWrapper.configPath, `./onebot11_${uin}.json`);
|
||||||
// 尝试解析配置文件
|
// 尝试解析配置文件
|
||||||
@@ -39,7 +39,7 @@ export const OB11GetConfigHandler: RequestHandler = async (_, res) => {
|
|||||||
// 写入OneBot11配置
|
// 写入OneBot11配置
|
||||||
export const OB11SetConfigHandler: RequestHandler = async (req, res) => {
|
export const OB11SetConfigHandler: RequestHandler = async (req, res) => {
|
||||||
// 获取QQ登录状态
|
// 获取QQ登录状态
|
||||||
const isLogin = await WebUiDataRuntime.getQQLoginStatus();
|
const isLogin = WebUiDataRuntime.getQQLoginStatus();
|
||||||
// 如果未登录,返回错误
|
// 如果未登录,返回错误
|
||||||
if (!isLogin) {
|
if (!isLogin) {
|
||||||
return sendError(res, 'Not Login');
|
return sendError(res, 'Not Login');
|
||||||
|
@@ -7,12 +7,12 @@ import { sendError, sendSuccess } from '@webapi/utils/response';
|
|||||||
// 获取QQ登录二维码
|
// 获取QQ登录二维码
|
||||||
export const QQGetQRcodeHandler: RequestHandler = async (req, res) => {
|
export const QQGetQRcodeHandler: RequestHandler = async (req, res) => {
|
||||||
// 判断是否已经登录
|
// 判断是否已经登录
|
||||||
if (await WebUiDataRuntime.getQQLoginStatus()) {
|
if (WebUiDataRuntime.getQQLoginStatus()) {
|
||||||
// 已经登录
|
// 已经登录
|
||||||
return sendError(res, 'QQ Is Logined');
|
return sendError(res, 'QQ Is Logined');
|
||||||
}
|
}
|
||||||
// 获取二维码
|
// 获取二维码
|
||||||
const qrcodeUrl = await WebUiDataRuntime.getQQLoginQrcodeURL();
|
const qrcodeUrl = WebUiDataRuntime.getQQLoginQrcodeURL();
|
||||||
// 判断二维码是否为空
|
// 判断二维码是否为空
|
||||||
if (isEmpty(qrcodeUrl)) {
|
if (isEmpty(qrcodeUrl)) {
|
||||||
return sendError(res, 'QRCode Get Error');
|
return sendError(res, 'QRCode Get Error');
|
||||||
@@ -27,8 +27,8 @@ export const QQGetQRcodeHandler: RequestHandler = async (req, res) => {
|
|||||||
// 获取QQ登录状态
|
// 获取QQ登录状态
|
||||||
export const QQCheckLoginStatusHandler: RequestHandler = async (req, res) => {
|
export const QQCheckLoginStatusHandler: RequestHandler = async (req, res) => {
|
||||||
const data = {
|
const data = {
|
||||||
isLogin: await WebUiDataRuntime.getQQLoginStatus(),
|
isLogin: WebUiDataRuntime.getQQLoginStatus(),
|
||||||
qrcodeurl: await WebUiDataRuntime.getQQLoginQrcodeURL(),
|
qrcodeurl: WebUiDataRuntime.getQQLoginQrcodeURL(),
|
||||||
};
|
};
|
||||||
return sendSuccess(res, data);
|
return sendSuccess(res, data);
|
||||||
};
|
};
|
||||||
@@ -38,7 +38,7 @@ export const QQSetQuickLoginHandler: RequestHandler = async (req, res) => {
|
|||||||
// 获取QQ号
|
// 获取QQ号
|
||||||
const { uin } = req.body;
|
const { uin } = req.body;
|
||||||
// 判断是否已经登录
|
// 判断是否已经登录
|
||||||
const isLogin = await WebUiDataRuntime.getQQLoginStatus();
|
const isLogin = WebUiDataRuntime.getQQLoginStatus();
|
||||||
if (isLogin) {
|
if (isLogin) {
|
||||||
return sendError(res, 'QQ Is Logined');
|
return sendError(res, 'QQ Is Logined');
|
||||||
}
|
}
|
||||||
@@ -53,12 +53,24 @@ export const QQSetQuickLoginHandler: RequestHandler = async (req, res) => {
|
|||||||
return sendError(res, message);
|
return sendError(res, message);
|
||||||
}
|
}
|
||||||
//本来应该验证 但是http不宜这么搞 建议前端验证
|
//本来应该验证 但是http不宜这么搞 建议前端验证
|
||||||
//isLogin = await WebUiDataRuntime.getQQLoginStatus();
|
//isLogin = WebUiDataRuntime.getQQLoginStatus();
|
||||||
return sendSuccess(res, null);
|
return sendSuccess(res, null);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取快速登录列表
|
// 获取快速登录列表
|
||||||
export const QQGetQuickLoginListHandler: RequestHandler = async (_, res) => {
|
export const QQGetQuickLoginListHandler: RequestHandler = async (_, res) => {
|
||||||
const quickLoginList = await WebUiDataRuntime.getQQQuickLoginList();
|
const quickLoginList = WebUiDataRuntime.getQQQuickLoginList();
|
||||||
return sendSuccess(res, quickLoginList);
|
return sendSuccess(res, quickLoginList);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 获取快速登录列表(新)
|
||||||
|
export const QQGetLoginListNewHandler: RequestHandler = async (_, res) => {
|
||||||
|
const newLoginList = WebUiDataRuntime.getQQNewLoginList();
|
||||||
|
return sendSuccess(res, newLoginList);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取登录的QQ的信息
|
||||||
|
export const getQQLoginInfoHandler: RequestHandler = async (_, res) => {
|
||||||
|
const data = WebUiDataRuntime.getQQLoginInfo();
|
||||||
|
return sendSuccess(res, data);
|
||||||
|
};
|
||||||
|
@@ -1,11 +1,16 @@
|
|||||||
import { OneBotConfig } from '@/onebot/config/config';
|
import type { LoginRuntimeType } from '../types/data';
|
||||||
|
import packageJson from '../../../../package.json';
|
||||||
const LoginRuntime: LoginRuntimeType = {
|
const LoginRuntime: LoginRuntimeType = {
|
||||||
LoginCurrentTime: Date.now(),
|
LoginCurrentTime: Date.now(),
|
||||||
LoginCurrentRate: 0,
|
LoginCurrentRate: 0,
|
||||||
QQLoginStatus: false, //已实现 但太傻了 得去那边注册个回调刷新
|
QQLoginStatus: false, //已实现 但太傻了 得去那边注册个回调刷新
|
||||||
QQQRCodeURL: '',
|
QQQRCodeURL: '',
|
||||||
QQLoginUin: '',
|
QQLoginUin: '',
|
||||||
|
QQLoginInfo: {
|
||||||
|
uid: '',
|
||||||
|
uin: '',
|
||||||
|
nick: '',
|
||||||
|
},
|
||||||
NapCatHelper: {
|
NapCatHelper: {
|
||||||
onOB11ConfigChanged: async () => {
|
onOB11ConfigChanged: async () => {
|
||||||
return;
|
return;
|
||||||
@@ -14,11 +19,13 @@ const LoginRuntime: LoginRuntimeType = {
|
|||||||
return { result: false, message: '' };
|
return { result: false, message: '' };
|
||||||
},
|
},
|
||||||
QQLoginList: [],
|
QQLoginList: [],
|
||||||
|
NewQQLoginList: [],
|
||||||
},
|
},
|
||||||
|
packageJson: packageJson,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WebUiDataRuntime = {
|
export const WebUiDataRuntime = {
|
||||||
checkLoginRate: async function (RateLimit: number): Promise<boolean> {
|
checkLoginRate(RateLimit: number): boolean {
|
||||||
LoginRuntime.LoginCurrentRate++;
|
LoginRuntime.LoginCurrentRate++;
|
||||||
//console.log(RateLimit, LoginRuntime.LoginCurrentRate, Date.now() - LoginRuntime.LoginCurrentTime);
|
//console.log(RateLimit, LoginRuntime.LoginCurrentRate, Date.now() - LoginRuntime.LoginCurrentTime);
|
||||||
if (Date.now() - LoginRuntime.LoginCurrentTime > 1000 * 60) {
|
if (Date.now() - LoginRuntime.LoginCurrentTime > 1000 * 60) {
|
||||||
@@ -29,51 +36,68 @@ export const WebUiDataRuntime = {
|
|||||||
return LoginRuntime.LoginCurrentRate <= RateLimit;
|
return LoginRuntime.LoginCurrentRate <= RateLimit;
|
||||||
},
|
},
|
||||||
|
|
||||||
getQQLoginStatus: async function (): Promise<boolean> {
|
getQQLoginStatus(): LoginRuntimeType['QQLoginStatus'] {
|
||||||
return LoginRuntime.QQLoginStatus;
|
return LoginRuntime.QQLoginStatus;
|
||||||
},
|
},
|
||||||
|
|
||||||
setQQLoginStatus: async function (status: boolean): Promise<void> {
|
setQQLoginStatus(status: LoginRuntimeType['QQLoginStatus']): void {
|
||||||
LoginRuntime.QQLoginStatus = status;
|
LoginRuntime.QQLoginStatus = status;
|
||||||
},
|
},
|
||||||
|
|
||||||
setQQLoginQrcodeURL: async function (url: string): Promise<void> {
|
setQQLoginQrcodeURL(url: LoginRuntimeType['QQQRCodeURL']): void {
|
||||||
LoginRuntime.QQQRCodeURL = url;
|
LoginRuntime.QQQRCodeURL = url;
|
||||||
},
|
},
|
||||||
|
|
||||||
getQQLoginQrcodeURL: async function (): Promise<string> {
|
getQQLoginQrcodeURL(): LoginRuntimeType['QQQRCodeURL'] {
|
||||||
return LoginRuntime.QQQRCodeURL;
|
return LoginRuntime.QQQRCodeURL;
|
||||||
},
|
},
|
||||||
|
|
||||||
setQQLoginUin: async function (uin: string): Promise<void> {
|
setQQLoginInfo(info: LoginRuntimeType['QQLoginInfo']): void {
|
||||||
LoginRuntime.QQLoginUin = uin;
|
LoginRuntime.QQLoginInfo = info;
|
||||||
|
LoginRuntime.QQLoginUin = info.uin.toString();
|
||||||
},
|
},
|
||||||
|
|
||||||
getQQLoginUin: async function (): Promise<string> {
|
getQQLoginInfo(): LoginRuntimeType['QQLoginInfo'] {
|
||||||
|
return LoginRuntime.QQLoginInfo;
|
||||||
|
},
|
||||||
|
|
||||||
|
getQQLoginUin(): LoginRuntimeType['QQLoginUin'] {
|
||||||
return LoginRuntime.QQLoginUin;
|
return LoginRuntime.QQLoginUin;
|
||||||
},
|
},
|
||||||
|
|
||||||
getQQQuickLoginList: async function (): Promise<any[]> {
|
getQQQuickLoginList(): LoginRuntimeType['NapCatHelper']['QQLoginList'] {
|
||||||
return LoginRuntime.NapCatHelper.QQLoginList;
|
return LoginRuntime.NapCatHelper.QQLoginList;
|
||||||
},
|
},
|
||||||
|
|
||||||
setQQQuickLoginList: async function (list: string[]): Promise<void> {
|
setQQQuickLoginList(list: LoginRuntimeType['NapCatHelper']['QQLoginList']): void {
|
||||||
LoginRuntime.NapCatHelper.QQLoginList = list;
|
LoginRuntime.NapCatHelper.QQLoginList = list;
|
||||||
},
|
},
|
||||||
|
|
||||||
setQuickLoginCall(func: (uin: string) => Promise<{ result: boolean; message: string }>): void {
|
getQQNewLoginList(): LoginRuntimeType['NapCatHelper']['NewQQLoginList'] {
|
||||||
|
return LoginRuntime.NapCatHelper.NewQQLoginList;
|
||||||
|
},
|
||||||
|
|
||||||
|
setQQNewLoginList(list: LoginRuntimeType['NapCatHelper']['NewQQLoginList']): void {
|
||||||
|
LoginRuntime.NapCatHelper.NewQQLoginList = list;
|
||||||
|
},
|
||||||
|
|
||||||
|
setQuickLoginCall(func: LoginRuntimeType['NapCatHelper']['onQuickLoginRequested']): void {
|
||||||
LoginRuntime.NapCatHelper.onQuickLoginRequested = func;
|
LoginRuntime.NapCatHelper.onQuickLoginRequested = func;
|
||||||
},
|
},
|
||||||
|
|
||||||
requestQuickLogin: async function (uin: string): Promise<{ result: boolean; message: string }> {
|
requestQuickLogin: function (uin) {
|
||||||
return await LoginRuntime.NapCatHelper.onQuickLoginRequested(uin);
|
return LoginRuntime.NapCatHelper.onQuickLoginRequested(uin);
|
||||||
},
|
} as LoginRuntimeType['NapCatHelper']['onQuickLoginRequested'],
|
||||||
|
|
||||||
setOnOB11ConfigChanged: async function (func: (ob11: OneBotConfig) => Promise<void>): Promise<void> {
|
setOnOB11ConfigChanged(func: LoginRuntimeType['NapCatHelper']['onOB11ConfigChanged']): void {
|
||||||
LoginRuntime.NapCatHelper.onOB11ConfigChanged = func;
|
LoginRuntime.NapCatHelper.onOB11ConfigChanged = func;
|
||||||
},
|
},
|
||||||
|
|
||||||
setOB11Config: async function (ob11: OneBotConfig): Promise<void> {
|
setOB11Config: function (ob11) {
|
||||||
await LoginRuntime.NapCatHelper.onOB11ConfigChanged(ob11);
|
return LoginRuntime.NapCatHelper.onOB11ConfigChanged(ob11);
|
||||||
|
} as LoginRuntimeType['NapCatHelper']['onOB11ConfigChanged'],
|
||||||
|
|
||||||
|
getPackageJson() {
|
||||||
|
return LoginRuntime.packageJson;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
8
src/webui/src/router/Base.ts
Normal file
8
src/webui/src/router/Base.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import { PackageInfoHandler } from '../api/BaseInfo';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
// router: 获取nc的package.json信息
|
||||||
|
router.get('/PackageInfo', PackageInfoHandler);
|
||||||
|
|
||||||
|
export { router as BaseRouter };
|
@@ -5,16 +5,22 @@ import {
|
|||||||
QQGetQRcodeHandler,
|
QQGetQRcodeHandler,
|
||||||
QQGetQuickLoginListHandler,
|
QQGetQuickLoginListHandler,
|
||||||
QQSetQuickLoginHandler,
|
QQSetQuickLoginHandler,
|
||||||
|
QQGetLoginListNewHandler,
|
||||||
|
getQQLoginInfoHandler,
|
||||||
} from '@webapi/api/QQLogin';
|
} from '@webapi/api/QQLogin';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
// router:获取快速登录列表
|
// router:获取快速登录列表
|
||||||
router.all('/GetQuickLoginList', QQGetQuickLoginListHandler);
|
router.all('/GetQuickLoginList', QQGetQuickLoginListHandler);
|
||||||
|
// router:获取快速登录列表(新)
|
||||||
|
router.all('/GetQuickLoginListNew', QQGetLoginListNewHandler);
|
||||||
// router:检查QQ登录状态
|
// router:检查QQ登录状态
|
||||||
router.post('/CheckLoginStatus', QQCheckLoginStatusHandler);
|
router.post('/CheckLoginStatus', QQCheckLoginStatusHandler);
|
||||||
// router:获取QQ登录二维码
|
// router:获取QQ登录二维码
|
||||||
router.post('/GetQQLoginQrcode', QQGetQRcodeHandler);
|
router.post('/GetQQLoginQrcode', QQGetQRcodeHandler);
|
||||||
// router:设置QQ快速登录
|
// router:设置QQ快速登录
|
||||||
router.post('/SetQuickLogin', QQSetQuickLoginHandler);
|
router.post('/SetQuickLogin', QQSetQuickLoginHandler);
|
||||||
|
// router:获取QQ登录信息
|
||||||
|
router.post('/GetQQLoginInfo', getQQLoginInfoHandler);
|
||||||
|
|
||||||
export { router as QQLoginRouter };
|
export { router as QQLoginRouter };
|
||||||
|
@@ -11,6 +11,7 @@ import { sendSuccess } from '@webapi/utils/response';
|
|||||||
import { QQLoginRouter } from '@webapi/router/QQLogin';
|
import { QQLoginRouter } from '@webapi/router/QQLogin';
|
||||||
import { AuthRouter } from '@webapi/router/auth';
|
import { AuthRouter } from '@webapi/router/auth';
|
||||||
import { LogRouter } from '@webapi/router/Log';
|
import { LogRouter } from '@webapi/router/Log';
|
||||||
|
import { BaseRouter } from '@webapi/router/Base';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -21,6 +22,8 @@ router.use(auth);
|
|||||||
router.all('/test', (_, res) => {
|
router.all('/test', (_, res) => {
|
||||||
return sendSuccess(res);
|
return sendSuccess(res);
|
||||||
});
|
});
|
||||||
|
// router:基础信息相关路由
|
||||||
|
router.use('/base', BaseRouter);
|
||||||
// router:WebUI登录相关路由
|
// router:WebUI登录相关路由
|
||||||
router.use('/auth', AuthRouter);
|
router.use('/auth', AuthRouter);
|
||||||
// router:QQ登录相关路由
|
// router:QQ登录相关路由
|
||||||
|
5
src/webui/src/types/data.d.ts
vendored
5
src/webui/src/types/data.d.ts
vendored
@@ -1,12 +1,17 @@
|
|||||||
|
import type { LoginListItem, SelfInfo } from '@/core';
|
||||||
|
|
||||||
interface LoginRuntimeType {
|
interface LoginRuntimeType {
|
||||||
LoginCurrentTime: number;
|
LoginCurrentTime: number;
|
||||||
LoginCurrentRate: number;
|
LoginCurrentRate: number;
|
||||||
QQLoginStatus: boolean;
|
QQLoginStatus: boolean;
|
||||||
QQQRCodeURL: string;
|
QQQRCodeURL: string;
|
||||||
QQLoginUin: string;
|
QQLoginUin: string;
|
||||||
|
QQLoginInfo: SelfInfo;
|
||||||
NapCatHelper: {
|
NapCatHelper: {
|
||||||
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
|
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
|
||||||
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
||||||
QQLoginList: string[];
|
QQLoginList: string[];
|
||||||
|
NewQQLoginList: LoginListItem[];
|
||||||
};
|
};
|
||||||
|
packageJson: object;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user