mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
Merge branch 'main' into upmain
This commit is contained in:
commit
a72c96f56d
17
README.md
17
README.md
@ -3,36 +3,33 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
---
|
---
|
||||||
## To Be Continued
|
## 欢迎回来
|
||||||
当前版本 (v2.1.x) 请使用内核构建版本(版本号最后的五位数)为 27187 以上的 PC NTQQ 运行。
|
NapCatQQ (aka 猫猫框架) 是现代化的基于 NTQQ 的 Bot 协议端实现。
|
||||||
|
|
||||||
## 项目介绍
|
## 猫猫技能
|
||||||
NapCatQQ 是现代化的基于 NTQQ 的 Bot 协议端实现。
|
|
||||||
|
|
||||||
## 项目优势
|
|
||||||
- [x] **多种启动方式**:支持以无头、LiteLoader 插件、仅 QQ GUI 三种方式启动
|
- [x] **多种启动方式**:支持以无头、LiteLoader 插件、仅 QQ GUI 三种方式启动
|
||||||
- [x] **低占用**:无头模式占用资源极低,适合在服务器上运行
|
- [x] **低占用**:无头模式占用资源极低,适合在服务器上运行
|
||||||
- [x] **超多接口**:在实现大部分Onebot接口上扩展了一套私有API
|
- [x] **超多接口**:在实现大部分Onebot接口上扩展了一套私有API
|
||||||
- [x] **WebUI**:自带 WebUI 支持,远程管理更加便捷
|
- [x] **WebUI**:自带 WebUI 支持,远程管理更加便捷
|
||||||
|
|
||||||
## 如何使用
|
## 使用猫猫
|
||||||
|
|
||||||
可前往 [Release](https://github.com/NapNeko/NapCatQQ/releases/) 页面下载最新版本
|
可前往 [Release](https://github.com/NapNeko/NapCatQQ/releases/) 页面下载最新版本
|
||||||
|
|
||||||
**首次使用**请务必前往[官方文档](https://napneko.github.io/)查看使用教程。
|
**首次使用**请务必前往[官方文档](https://napneko.github.io/)查看使用教程。
|
||||||
|
|
||||||
## 相关链接
|
## 回家旅途
|
||||||
[QQ Group](https://qm.qq.com/q/VfjAq5HIMS)
|
[QQ Group](https://qm.qq.com/q/VfjAq5HIMS)
|
||||||
|
|
||||||
[Telegram Link](https://t.me/+nLZEnpne-pQ1OWFl)
|
[Telegram Link](https://t.me/+nLZEnpne-pQ1OWFl)
|
||||||
|
|
||||||
## 鸣谢名单
|
## 猫猫朋友
|
||||||
感谢 [LLOneBot](https://github.com/LLOneBot/LLOneBot) 提供初始版本基础
|
感谢 [LLOneBot](https://github.com/LLOneBot/LLOneBot) 提供初始版本基础
|
||||||
|
|
||||||
感谢 [Lagrange](https://github.com/LagrangeDev/Lagrange.Core) 对本项目的大力支持
|
感谢 [Lagrange](https://github.com/LagrangeDev/Lagrange.Core) 对本项目的大力支持
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 使用许可
|
## 约法三章
|
||||||
|
|
||||||
任何使用本仓库代码的地方,都应当严格遵守[本仓库开源许可](./LICENSE)。**此外,禁止任何项目未经授权二次分发或基于 NapCat 代码开发。**
|
任何使用本仓库代码的地方,都应当严格遵守[本仓库开源许可](./LICENSE)。**此外,禁止任何项目未经授权二次分发或基于 NapCat 代码开发。**
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "2.2.2",
|
"version": "2.2.5",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "2.2.2",
|
"version": "2.2.5",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:framework": "vite build --mode framework",
|
"build:framework": "vite build --mode framework",
|
||||||
"build:shell": "vite build --mode shell",
|
"build:shell": "vite build --mode shell",
|
||||||
|
@ -162,7 +162,89 @@ export class LegacyNTEventWrapper {
|
|||||||
this.createListenerFunction(ListenerMainName);
|
this.createListenerFunction(ListenerMainName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
async CallNormalEventV2<
|
||||||
|
EventType extends (...args: any[]) => Promise<any>,
|
||||||
|
ListenerType extends (...args: any[]) => void
|
||||||
|
>(
|
||||||
|
EventName = '',
|
||||||
|
ListenerName = '',
|
||||||
|
waitTimes = 1,
|
||||||
|
timeout: number = 3000,
|
||||||
|
checkerEvent: (ret: Awaited<ReturnType<EventType>>) => boolean = () => true,
|
||||||
|
checkerListener: (...args: Parameters<ListenerType>) => boolean = () => true,
|
||||||
|
...args: Parameters<EventType>
|
||||||
|
) {
|
||||||
|
return new Promise<[EventRet: Awaited<ReturnType<EventType>>, ...Parameters<ListenerType>]>(
|
||||||
|
async (resolve, reject) => {
|
||||||
|
const id = randomUUID();
|
||||||
|
let complete = 0;
|
||||||
|
let retData: Parameters<ListenerType> | undefined = undefined;
|
||||||
|
let retEvent: any = {};
|
||||||
|
const databack = () => {
|
||||||
|
if (complete == 0) {
|
||||||
|
reject(
|
||||||
|
new Error(
|
||||||
|
'Timeout: NTEvent EventName:' +
|
||||||
|
EventName +
|
||||||
|
' ListenerName:' +
|
||||||
|
ListenerName +
|
||||||
|
' EventRet:\n' +
|
||||||
|
JSON.stringify(retEvent, null, 4) +
|
||||||
|
'\n',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
resolve([retEvent as Awaited<ReturnType<EventType>>, ...retData!]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const ListenerNameList = ListenerName.split('/');
|
||||||
|
const ListenerMainName = ListenerNameList[0];
|
||||||
|
const ListenerSubName = ListenerNameList[1];
|
||||||
|
|
||||||
|
const Timeouter = setTimeout(databack, timeout);
|
||||||
|
|
||||||
|
const eventCallbak = {
|
||||||
|
timeout: timeout,
|
||||||
|
createtime: Date.now(),
|
||||||
|
checker: checkerListener,
|
||||||
|
func: (...args: any[]) => {
|
||||||
|
complete++;
|
||||||
|
//console.log('func', ...args);
|
||||||
|
retData = args as Parameters<ListenerType>;
|
||||||
|
if (complete >= waitTimes) {
|
||||||
|
clearTimeout(Timeouter);
|
||||||
|
databack();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (!this.EventTask.get(ListenerMainName)) {
|
||||||
|
this.EventTask.set(ListenerMainName, new Map());
|
||||||
|
}
|
||||||
|
if (!this.EventTask.get(ListenerMainName)?.get(ListenerSubName)) {
|
||||||
|
this.EventTask.get(ListenerMainName)?.set(ListenerSubName, new Map());
|
||||||
|
}
|
||||||
|
this.EventTask.get(ListenerMainName)?.get(ListenerSubName)?.set(id, eventCallbak);
|
||||||
|
this.createListenerFunction(ListenerMainName);
|
||||||
|
const EventFunc = this.createEventFunction<EventType>(EventName);
|
||||||
|
retEvent = await EventFunc!(...(args as any[]));
|
||||||
|
if(!checkerEvent(retEvent)){
|
||||||
|
clearTimeout(Timeouter);
|
||||||
|
reject(
|
||||||
|
new Error(
|
||||||
|
'EventChecker Failed: NTEvent EventName:' +
|
||||||
|
EventName +
|
||||||
|
' ListenerName:' +
|
||||||
|
ListenerName +
|
||||||
|
' EventRet:\n' +
|
||||||
|
JSON.stringify(retEvent, null, 4) +
|
||||||
|
'\n',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
async CallNormalEvent<
|
async CallNormalEvent<
|
||||||
EventType extends (...args: any[]) => Promise<any>,
|
EventType extends (...args: any[]) => Promise<any>,
|
||||||
ListenerType extends (...args: any[]) => void
|
ListenerType extends (...args: any[]) => void
|
||||||
|
@ -2,7 +2,7 @@ import path, { dirname } from 'path';
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
export const napcat_version = '2.2.2';
|
export const napcat_version = '2.2.5';
|
||||||
|
|
||||||
export class NapCatPathWrapper {
|
export class NapCatPathWrapper {
|
||||||
binaryPath: string;
|
binaryPath: string;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Friend, FriendV2, User } from '@/core/entities';
|
import { Friend, FriendV2, User } from '@/core/entities';
|
||||||
import { BuddyListReqType, InstanceContext, NapCatCore, NodeIKernelProfileService, OnBuddyChangeParams } from '@/core';
|
import { BuddyListReqType, InstanceContext, NapCatCore, NodeIKernelBuddyListener, NodeIKernelBuddyService, NodeIKernelProfileService, OnBuddyChangeParams } from '@/core';
|
||||||
import { LimitedHashTable } from '@/common/utils/MessageUnique';
|
import { LimitedHashTable } from '@/common/utils/MessageUnique';
|
||||||
|
|
||||||
export class NTQQFriendApi {
|
export class NTQQFriendApi {
|
||||||
@ -70,29 +70,14 @@ export class NTQQFriendApi {
|
|||||||
async isBuddy(uid: string) {
|
async isBuddy(uid: string) {
|
||||||
return this.context.session.getBuddyService().isBuddy(uid);
|
return this.context.session.getBuddyService().isBuddy(uid);
|
||||||
}
|
}
|
||||||
|
async clearBuddyReqUnreadCnt() {
|
||||||
/**
|
return this.context.session.getBuddyService().clearBuddyReqUnreadCnt();
|
||||||
* @deprecated
|
|
||||||
* @param forced
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
async getFriends(forced = false): Promise<User[]> {
|
|
||||||
const [_retData, _BuddyArg] = await this.core.eventWrapper.CallNormalEvent<(force: boolean) => Promise<any>, (arg: OnBuddyChangeParams) => void>
|
|
||||||
(
|
|
||||||
'NodeIKernelBuddyService/getBuddyList',
|
|
||||||
'NodeIKernelBuddyListener/onBuddyListChange',
|
|
||||||
1,
|
|
||||||
5000,
|
|
||||||
() => true,
|
|
||||||
forced,
|
|
||||||
);
|
|
||||||
const friends: User[] = [];
|
|
||||||
for (const categoryItem of _BuddyArg) {
|
|
||||||
for (const friend of categoryItem.buddyList) {
|
|
||||||
friends.push(friend);
|
|
||||||
}
|
}
|
||||||
}
|
async getBuddyReq() {
|
||||||
return friends;
|
const [, ret] = await this.core.eventWrapper.CallNormalEventV2
|
||||||
|
<NodeIKernelBuddyService['getBuddyReq'], NodeIKernelBuddyListener['onBuddyReqChange']>
|
||||||
|
('NodeIKernelBuddyService/getBuddyReq', 'NodeIKernelBuddyListener/onBuddyReqChange', 1, 5000);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleFriendRequest(flag: string, accept: boolean) {
|
async handleFriendRequest(flag: string, accept: boolean) {
|
||||||
|
@ -1,40 +1,59 @@
|
|||||||
export enum GroupNotifyTypes {
|
export enum GroupNotifyMsgType {
|
||||||
INVITE_ME = 1,
|
UN_SPECIFIED,
|
||||||
INVITED_JOIN = 4, // 有人接受了邀请入群
|
INVITED_BY_MEMBER,
|
||||||
JOIN_REQUEST = 7,
|
REFUSE_INVITED,
|
||||||
ADMIN_SET = 8,
|
REFUSED_BY_ADMINI_STRATOR,
|
||||||
KICK_MEMBER = 9,
|
AGREED_TOJOIN_DIRECT,// 有人接受了邀请入群
|
||||||
MEMBER_EXIT = 11, // 主动退出
|
INVITED_NEED_ADMINI_STRATOR_PASS,
|
||||||
ADMIN_UNSET = 12,
|
AGREED_TO_JOIN_BY_ADMINI_STRATOR,
|
||||||
ADMIN_UNSET_OTHER = 13, // 其他人取消管理员
|
REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS,
|
||||||
|
SET_ADMIN,
|
||||||
|
KICK_MEMBER_NOTIFY_ADMIN,
|
||||||
|
KICK_MEMBER_NOTIFY_KICKED,
|
||||||
|
MEMBER_LEAVE_NOTIFY_ADMIN,// 主动退出
|
||||||
|
CANCEL_ADMIN_NOTIFY_CANCELED,
|
||||||
|
CANCEL_ADMIN_NOTIFY_ADMIN,// 其他人取消管理员
|
||||||
|
TRANSFER_GROUP_NOTIFY_OLDOWNER,
|
||||||
|
TRANSFER_GROUP_NOTIFY_ADMIN
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GroupNotifies {
|
export interface GroupNotifies {
|
||||||
doubt: boolean;
|
doubt: boolean;
|
||||||
nextStartSeq: string;
|
nextStartSeq: string;
|
||||||
notifies: GroupNotify[];
|
notifies: GroupNotify[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum GroupNotifyStatus {
|
export enum GroupNotifyMsgStatus {
|
||||||
IGNORE = 0,
|
KINIT,//初始化
|
||||||
WAIT_HANDLE = 1,
|
KUNHANDLE,//未处理
|
||||||
APPROVE = 2,
|
KAGREED,//同意
|
||||||
REJECT = 3
|
KREFUSED,//拒绝
|
||||||
|
KIGNORED//忽略
|
||||||
|
}
|
||||||
|
export enum GroupInviteStatus {
|
||||||
|
INIT,
|
||||||
|
WAIT_TO_APPROVE,
|
||||||
|
JOINED,
|
||||||
|
REFUSED_BY_ADMINI_STRATOR
|
||||||
|
}
|
||||||
|
export enum GroupInviteType {
|
||||||
|
BYBUDDY,
|
||||||
|
BYGROUPMEMBER,
|
||||||
|
BYDISCUSSMEMBER
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GroupNotify {
|
export interface GroupNotify {
|
||||||
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
||||||
seq: string; // 唯一标识符,转成数字再除以1000应该就是时间戳?
|
seq: string; // 唯一标识符,转成数字再除以1000应该就是时间戳?
|
||||||
type: GroupNotifyTypes;
|
type: GroupNotifyMsgType;
|
||||||
status: GroupNotifyStatus; // 0是已忽略?,1是未处理,2是已同意
|
status: GroupNotifyMsgStatus;
|
||||||
group: { groupCode: string; groupName: string };
|
group: { groupCode: string; groupName: string };
|
||||||
user1: { uid: string; nickName: string }; // 被设置管理员的人
|
user1: { uid: string; nickName: string }; // 被设置管理员的人
|
||||||
user2: { uid: string; nickName: string }; // 操作者
|
user2: { uid: string; nickName: string }; // 操作者
|
||||||
actionUser: { uid: string; nickName: string }; //未知
|
actionUser: { uid: string; nickName: string }; //未知
|
||||||
actionTime: string;
|
actionTime: string;
|
||||||
invitationExt: {
|
invitationExt: {
|
||||||
srcType: number; // 0?未知
|
srcType: GroupInviteType; // 邀请来源
|
||||||
groupCode: string; waitStatus: number
|
groupCode: string;
|
||||||
|
waitStatus: GroupInviteStatus
|
||||||
};
|
};
|
||||||
postscript: string; // 加群用户填写的验证信息
|
postscript: string; // 加群用户填写的验证信息
|
||||||
repeatSeqs: [];
|
repeatSeqs: [];
|
||||||
@ -64,6 +83,7 @@ export enum BuddyReqType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface FriendRequest {
|
export interface FriendRequest {
|
||||||
|
isBuddy?: boolean;
|
||||||
isInitiator?: boolean;
|
isInitiator?: boolean;
|
||||||
isDecide: boolean;
|
isDecide: boolean;
|
||||||
friendUid: string;
|
friendUid: string;
|
||||||
|
@ -61,11 +61,11 @@ export interface NodeIKernelBuddyService {
|
|||||||
|
|
||||||
getBuddyReqUnreadCnt(): number;
|
getBuddyReqUnreadCnt(): number;
|
||||||
|
|
||||||
getBuddyReq(): unknown;
|
getBuddyReq(): Promise<GeneralCallResult>;
|
||||||
|
|
||||||
delBuddyReq(uid: number): void;
|
delBuddyReq(uid: number): void;
|
||||||
|
|
||||||
clearBuddyReqUnreadCnt(): void;
|
clearBuddyReqUnreadCnt(): Promise<GeneralCallResult>;
|
||||||
|
|
||||||
reqToAddFriends(uid: number, msg: string): void;
|
reqToAddFriends(uid: number, msg: string): void;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import {
|
|||||||
GroupExtParam,
|
GroupExtParam,
|
||||||
GroupMember,
|
GroupMember,
|
||||||
GroupMemberRole,
|
GroupMemberRole,
|
||||||
GroupNotifyTypes,
|
GroupNotifyMsgType,
|
||||||
GroupRequestOperateTypes,
|
GroupRequestOperateTypes,
|
||||||
} from '@/core/entities';
|
} from '@/core/entities';
|
||||||
import { GeneralCallResult } from '@/core/services/common';
|
import { GeneralCallResult } from '@/core/services/common';
|
||||||
@ -195,7 +195,7 @@ export interface NodeIKernelGroupService {
|
|||||||
operateType: GroupRequestOperateTypes, // 2 拒绝
|
operateType: GroupRequestOperateTypes, // 2 拒绝
|
||||||
targetMsg: {
|
targetMsg: {
|
||||||
seq: string, // 通知序列号
|
seq: string, // 通知序列号
|
||||||
type: GroupNotifyTypes,
|
type: GroupNotifyMsgType,
|
||||||
groupCode: string,
|
groupCode: string,
|
||||||
postscript: string
|
postscript: string
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,3 +1,4 @@
|
|||||||
|
import { GroupNotifyMsgStatus } from '@/core';
|
||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
@ -28,7 +29,7 @@ export class GetGroupSystemMsg extends BaseAction<void, any> {
|
|||||||
invitor_nick: SSNotify.user1?.nickName,
|
invitor_nick: SSNotify.user1?.nickName,
|
||||||
group_id: SSNotify.group?.groupCode,
|
group_id: SSNotify.group?.groupCode,
|
||||||
group_name: SSNotify.group?.groupName,
|
group_name: SSNotify.group?.groupName,
|
||||||
checked: SSNotify.status === 1 ? false : true,
|
checked: SSNotify.status === GroupNotifyMsgStatus.KUNHANDLE ? false : true,
|
||||||
actor: await NTQQUserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
actor: await NTQQUserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
||||||
});
|
});
|
||||||
} else if (SSNotify.type == 7) {
|
} else if (SSNotify.type == 7) {
|
||||||
@ -38,7 +39,7 @@ export class GetGroupSystemMsg extends BaseAction<void, any> {
|
|||||||
requester_nick: SSNotify.user1?.nickName,
|
requester_nick: SSNotify.user1?.nickName,
|
||||||
group_id: SSNotify.group?.groupCode,
|
group_id: SSNotify.group?.groupCode,
|
||||||
group_name: SSNotify.group?.groupName,
|
group_name: SSNotify.group?.groupName,
|
||||||
checked: SSNotify.status === 1 ? false : true,
|
checked: SSNotify.status === GroupNotifyMsgStatus.KUNHANDLE ? false : true,
|
||||||
actor: await NTQQUserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
actor: await NTQQUserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ const _handlers: {
|
|||||||
} else {
|
} else {
|
||||||
postData = data;
|
postData = data;
|
||||||
}
|
}
|
||||||
// Mlikiowa V2.2.2 Refactor Todo
|
// Mlikiowa V2.2.5 Refactor Todo
|
||||||
const signUrl = obContext.configLoader.configData.musicSignUrl;
|
const signUrl = obContext.configLoader.configData.musicSignUrl;
|
||||||
if (!signUrl) {
|
if (!signUrl) {
|
||||||
if (data.type === 'qq') {
|
if (data.type === 'qq') {
|
||||||
|
@ -90,6 +90,7 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
|
|||||||
// This redundant design of Ob11 here should be blamed.
|
// This redundant design of Ob11 here should be blamed.
|
||||||
const NTQQFriendApi = coreContext.apis.FriendApi;
|
const NTQQFriendApi = coreContext.apis.FriendApi;
|
||||||
const NTQQUserApi = coreContext.apis.UserApi;
|
const NTQQUserApi = coreContext.apis.UserApi;
|
||||||
|
const NTQQMsgApi = coreContext.apis.MsgApi;
|
||||||
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
||||||
return {
|
return {
|
||||||
chatType: ChatType.KCHATTYPEGROUP,
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
@ -98,12 +99,34 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
|
|||||||
}
|
}
|
||||||
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
||||||
const Uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
const Uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
const isBuddy = await NTQQFriendApi.isBuddy(Uid!);
|
if (!Uid) throw '无法获取用户信息';
|
||||||
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
|
const isBuddy = await NTQQFriendApi.isBuddy(Uid);
|
||||||
|
if (!isBuddy) {
|
||||||
|
const ret = await NTQQMsgApi.getTempChatInfo(ChatType.KCHATTYPETEMPC2CFROMGROUP, Uid);
|
||||||
|
if (ret.tmpChatInfo?.groupCode) {
|
||||||
return {
|
return {
|
||||||
chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP,
|
chatType: ChatType.KCHATTYPETEMPC2CFROMGROUP,
|
||||||
|
peerUid: Uid,
|
||||||
|
guildId: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (payload.group_id) {
|
||||||
|
return {
|
||||||
|
chatType: ChatType.KCHATTYPETEMPC2CFROMGROUP,
|
||||||
|
peerUid: Uid,
|
||||||
|
guildId: payload.group_id.toString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
chatType: ChatType.KCHATTYPEC2C,
|
||||||
peerUid: Uid!,
|
peerUid: Uid!,
|
||||||
guildId: payload.group_id?.toString() || '',
|
guildId: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
chatType: ChatType.KCHATTYPEC2C,
|
||||||
|
peerUid: Uid!,
|
||||||
|
guildId: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
throw '请指定 group_id 或 user_id';
|
throw '请指定 group_id 或 user_id';
|
||||||
|
@ -65,11 +65,12 @@ export class OneBotMsgApi {
|
|||||||
name = content.replace('@', '');
|
name = content.replace('@', '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message_data = {
|
message_data = {
|
||||||
type: OB11MessageDataType.at,
|
type: OB11MessageDataType.at,
|
||||||
data: {
|
data: {
|
||||||
qq: qq!,
|
qq: qq!,
|
||||||
name,
|
//name,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return message_data;
|
return message_data;
|
||||||
|
@ -3,13 +3,14 @@ import {
|
|||||||
BuddyReqType,
|
BuddyReqType,
|
||||||
ChatType,
|
ChatType,
|
||||||
GroupListener,
|
GroupListener,
|
||||||
GroupNotifyTypes,
|
|
||||||
InstanceContext,
|
InstanceContext,
|
||||||
MsgListener,
|
MsgListener,
|
||||||
NapCatCore,
|
NapCatCore,
|
||||||
RawMessage,
|
RawMessage,
|
||||||
SendStatusType,
|
SendStatusType,
|
||||||
GroupMemberRole,
|
GroupMemberRole,
|
||||||
|
GroupNotifyMsgType,
|
||||||
|
GroupNotifyMsgStatus,
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import { OB11Config, OB11ConfigLoader } from '@/onebot/helper/config';
|
import { OB11Config, OB11ConfigLoader } from '@/onebot/helper/config';
|
||||||
import { OneBotApiContextType } from '@/onebot/types';
|
import { OneBotApiContextType } from '@/onebot/types';
|
||||||
@ -283,8 +284,16 @@ export class NapCatOneBot11Adapter {
|
|||||||
private initBuddyListener() {
|
private initBuddyListener() {
|
||||||
const buddyListener = new BuddyListener();
|
const buddyListener = new BuddyListener();
|
||||||
|
|
||||||
buddyListener.onBuddyReqChange = reqs => {
|
buddyListener.onBuddyReqChange = async reqs => {
|
||||||
reqs.buddyReqs.forEach(async req => {
|
this.core.apis.FriendApi.clearBuddyReqUnreadCnt();
|
||||||
|
for (let i = 0; i < reqs.unreadNums; i++) {
|
||||||
|
const req = reqs.buddyReqs[i];
|
||||||
|
//req.isBuddy === false是单向好友 null为常规情况
|
||||||
|
// if (req.isBuddy === false && ) {
|
||||||
|
// const NTQQFriendApi = this.core.apis.FriendApi;
|
||||||
|
// await NTQQFriendApi.handleFriendRequest(req.friendUid + '|' + req.reqTime, true);
|
||||||
|
// }
|
||||||
|
|
||||||
if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM)) {
|
if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -299,7 +308,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.context.logger.logDebug('获取加好友者QQ号失败', e);
|
this.context.logger.logDebug('获取加好友者QQ号失败', e);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.context.session.getBuddyService().addKernelBuddyListener(
|
this.context.session.getBuddyService().addKernelBuddyListener(
|
||||||
@ -313,9 +322,9 @@ export class NapCatOneBot11Adapter {
|
|||||||
groupListener.onGroupNotifiesUpdated = async (_, notifies) => {
|
groupListener.onGroupNotifiesUpdated = async (_, notifies) => {
|
||||||
//console.log('ob11 onGroupNotifiesUpdated', notifies[0]);
|
//console.log('ob11 onGroupNotifiesUpdated', notifies[0]);
|
||||||
if (![
|
if (![
|
||||||
GroupNotifyTypes.ADMIN_SET,
|
GroupNotifyMsgType.SET_ADMIN,
|
||||||
GroupNotifyTypes.ADMIN_UNSET,
|
GroupNotifyMsgType.CANCEL_ADMIN_NOTIFY_CANCELED,
|
||||||
GroupNotifyTypes.ADMIN_UNSET_OTHER,
|
GroupNotifyMsgType.CANCEL_ADMIN_NOTIFY_ADMIN,
|
||||||
].includes(notifies[0]?.type)) {
|
].includes(notifies[0]?.type)) {
|
||||||
for (const notify of notifies) {
|
for (const notify of notifies) {
|
||||||
notify.time = Date.now();
|
notify.time = Date.now();
|
||||||
@ -329,9 +338,9 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.context.logger.logDebug('收到群通知', notify);
|
this.context.logger.logDebug('收到群通知', notify);
|
||||||
|
|
||||||
if ([
|
if ([
|
||||||
GroupNotifyTypes.ADMIN_SET,
|
GroupNotifyMsgType.SET_ADMIN,
|
||||||
GroupNotifyTypes.ADMIN_UNSET,
|
GroupNotifyMsgType.CANCEL_ADMIN_NOTIFY_CANCELED,
|
||||||
GroupNotifyTypes.ADMIN_UNSET_OTHER,
|
GroupNotifyMsgType.CANCEL_ADMIN_NOTIFY_ADMIN,
|
||||||
].includes(notify.type)) {
|
].includes(notify.type)) {
|
||||||
const member1 = await this.core.apis.GroupApi.getGroupMember(notify.group.groupCode, notify.user1.uid);
|
const member1 = await this.core.apis.GroupApi.getGroupMember(notify.group.groupCode, notify.user1.uid);
|
||||||
this.context.logger.logDebug('有管理员变动通知');
|
this.context.logger.logDebug('有管理员变动通知');
|
||||||
@ -340,20 +349,21 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.context.logger.logDebug('开始获取变动的管理员');
|
this.context.logger.logDebug('开始获取变动的管理员');
|
||||||
if (member1) {
|
if (member1) {
|
||||||
this.context.logger.logDebug('变动管理员获取成功');
|
this.context.logger.logDebug('变动管理员获取成功');
|
||||||
// member1.role = notify.type == GroupNotifyTypes.ADMIN_SET ? GroupMemberRole.admin : GroupMemberRole.normal;
|
|
||||||
|
|
||||||
const groupAdminNoticeEvent = new OB11GroupAdminNoticeEvent(
|
const groupAdminNoticeEvent = new OB11GroupAdminNoticeEvent(
|
||||||
this.core,
|
this.core,
|
||||||
parseInt(notify.group.groupCode),
|
parseInt(notify.group.groupCode),
|
||||||
parseInt(member1.uin),
|
parseInt(member1.uin),
|
||||||
[GroupNotifyTypes.ADMIN_UNSET, GroupNotifyTypes.ADMIN_UNSET_OTHER].includes(notify.type) ? 'unset' : 'set',
|
[
|
||||||
|
GroupNotifyMsgType.CANCEL_ADMIN_NOTIFY_CANCELED,
|
||||||
|
GroupNotifyMsgType.CANCEL_ADMIN_NOTIFY_ADMIN
|
||||||
|
].includes(notify.type) ? 'unset' : 'set',
|
||||||
);
|
);
|
||||||
this.networkManager.emitEvent(groupAdminNoticeEvent)
|
this.networkManager.emitEvent(groupAdminNoticeEvent)
|
||||||
.catch(e => this.context.logger.logError('处理群管理员变动失败', e));
|
.catch(e => this.context.logger.logError('处理群管理员变动失败', e));
|
||||||
} else {
|
} else {
|
||||||
this.context.logger.logDebug('获取群通知的成员信息失败', notify, this.core.apis.GroupApi.getGroup(notify.group.groupCode));
|
this.context.logger.logDebug('获取群通知的成员信息失败', notify, this.core.apis.GroupApi.getGroup(notify.group.groupCode));
|
||||||
}
|
}
|
||||||
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
|
} else if (notify.type == GroupNotifyMsgType.MEMBER_LEAVE_NOTIFY_ADMIN || notify.type == GroupNotifyMsgType.KICK_MEMBER_NOTIFY_ADMIN) {
|
||||||
this.context.logger.logDebug('有成员退出通知', notify);
|
this.context.logger.logDebug('有成员退出通知', notify);
|
||||||
const member1Uin = (await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid))!;
|
const member1Uin = (await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid))!;
|
||||||
let operatorId = member1Uin;
|
let operatorId = member1Uin;
|
||||||
@ -377,8 +387,8 @@ export class NapCatOneBot11Adapter {
|
|||||||
.catch(e => this.context.logger.logError('处理群成员退出失败', e));
|
.catch(e => this.context.logger.logError('处理群成员退出失败', e));
|
||||||
// notify.status == 1 表示未处理 2表示处理完成
|
// notify.status == 1 表示未处理 2表示处理完成
|
||||||
} else if ([
|
} else if ([
|
||||||
GroupNotifyTypes.JOIN_REQUEST,
|
GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS,
|
||||||
].includes(notify.type) && notify.status == 1) {
|
].includes(notify.type) && notify.status == GroupNotifyMsgStatus.KUNHANDLE) {
|
||||||
this.context.logger.logDebug('有加群请求');
|
this.context.logger.logDebug('有加群请求');
|
||||||
try {
|
try {
|
||||||
let requestUin = (await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid))!;
|
let requestUin = (await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid))!;
|
||||||
@ -398,7 +408,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.context.logger.logError('获取加群人QQ号失败 Uid:', notify.user1.uid, e);
|
this.context.logger.logError('获取加群人QQ号失败 Uid:', notify.user1.uid, e);
|
||||||
}
|
}
|
||||||
} else if (notify.type == GroupNotifyTypes.INVITE_ME && notify.status == 1) {
|
} else if (notify.type == GroupNotifyMsgType.INVITED_BY_MEMBER && notify.status == GroupNotifyMsgStatus.KUNHANDLE) {
|
||||||
this.context.logger.logDebug(`收到邀请我加群通知:${notify}`);
|
this.context.logger.logDebug(`收到邀请我加群通知:${notify}`);
|
||||||
const groupInviteEvent = new OB11GroupRequestEvent(
|
const groupInviteEvent = new OB11GroupRequestEvent(
|
||||||
this.core,
|
this.core,
|
||||||
|
@ -30,7 +30,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">Napcat</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
undefined,
|
undefined,
|
||||||
SettingButton('V2.2.2', 'napcat-update-button', 'secondary'),
|
SettingButton('V2.2.5', 'napcat-update-button', 'secondary'),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
@ -164,7 +164,7 @@ async function onSettingWindowCreated(view) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">Napcat</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
void 0,
|
void 0,
|
||||||
SettingButton("V2.2.2", "napcat-update-button", "secondary")
|
SettingButton("V2.2.5", "napcat-update-button", "secondary")
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user