mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
71ae08706b | ||
![]() |
50dd798757 | ||
![]() |
0c8cf73746 | ||
![]() |
1bee811312 | ||
![]() |
b4c0068637 | ||
![]() |
f484c6e5fe | ||
![]() |
7a08187c5f | ||
![]() |
c4d7d5a0d4 | ||
![]() |
d22f5d369c | ||
![]() |
d76503995c | ||
![]() |
eab930c083 | ||
![]() |
42b23a6c9c | ||
![]() |
8d94f24c71 | ||
![]() |
6ac74c39d9 | ||
![]() |
836eb7b708 | ||
![]() |
698624b4dc | ||
![]() |
5c1df82076 | ||
![]() |
5d649b3687 | ||
![]() |
a6a3d71155 | ||
![]() |
1cc9d501ab | ||
![]() |
7a98025df8 | ||
![]() |
44d6ed5e80 | ||
![]() |
b5f2226bef | ||
![]() |
ddbffe55d2 | ||
![]() |
9676b1d0e9 | ||
![]() |
8142d3bfeb | ||
![]() |
755ad27a0a | ||
![]() |
5afa2dcdf1 | ||
![]() |
7eb80646ba | ||
![]() |
6fd24e57d3 | ||
![]() |
22c90adb47 | ||
![]() |
df0c6fafbe | ||
![]() |
dc30321b04 | ||
![]() |
63dd98d2df | ||
![]() |
caaa6ed506 |
6
LICENSE
6
LICENSE
@@ -1,4 +1,4 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
GNU GENERAL PUBLIC Without Social media promotion LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
@@ -111,6 +111,10 @@ above, provided that you also meet all of these conditions:
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
d)You may use this software in accordance with the above terms,
|
||||
but you are not allowed to promote this project or your projects
|
||||
based on this project on any public social media.
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
|
@@ -3,6 +3,10 @@
|
||||
</div>
|
||||
|
||||
---
|
||||
## To Be Continued
|
||||
当前版本请使用内核构建版本(版本号最后的五位数)为 26702 至 26909 的 PC NTQQ 运行。
|
||||
|
||||
高版本QQ NapCat已完成兼容 暂时不发布 直至版本2.0.x结束。
|
||||
|
||||
## 项目介绍
|
||||
NapCatQQ 是现代化的基于 NTQQ 的 Bot 协议端实现。
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"name": "NapCatQQ",
|
||||
"slug": "NapCat.Framework",
|
||||
"description": "高性能的 OneBot 11 协议实现",
|
||||
"version": "2.0.29",
|
||||
"version": "2.0.35",
|
||||
"icon": "./logo.png",
|
||||
"authors": [
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"name": "napcat",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"version": "2.0.29",
|
||||
"version": "2.0.35",
|
||||
"scripts": {
|
||||
"build:framework": "vite build --mode framework",
|
||||
"build:shell": "vite build --mode shell",
|
||||
|
@@ -2,7 +2,7 @@ import path, { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
|
||||
export const napcat_version = '2.0.29';
|
||||
export const napcat_version = '2.0.35';
|
||||
|
||||
export class NapCatPathWrapper {
|
||||
binaryPath: string;
|
||||
|
File diff suppressed because one or more lines are too long
@@ -253,22 +253,45 @@ export class NTQQGroupApi {
|
||||
}
|
||||
|
||||
async getGroupMemberV2(GroupCode: string, uid: string, forced = false) {
|
||||
type ListenerType = NodeIKernelGroupListener['onMemberInfoChange'];
|
||||
//type ListenerType = NodeIKernelGroupListener['onMemberInfoChange'];
|
||||
type EventType = NodeIKernelGroupService['getMemberInfo'];
|
||||
// NTEventDispatch.CreatListenerFunction('NodeIKernelGroupListener/onGroupMemberInfoUpdate',
|
||||
//return napCatCore.session.getGroupService().getMemberInfo(GroupCode, [uid], forced);
|
||||
const [, , , _members] = await this.core.eventWrapper.CallNormalEvent<EventType, ListenerType>
|
||||
const Listener = this.core.eventWrapper.RegisterListen<(params: any) => void>
|
||||
(
|
||||
'NodeIKernelGroupService/getMemberInfo',
|
||||
'NodeIKernelGroupListener/onMemberInfoChange',
|
||||
1,
|
||||
5000,
|
||||
(groupCode: string, changeType: number, members: Map<string, GroupMember>) => {
|
||||
return groupCode == GroupCode && members.has(uid);
|
||||
forced ? 5000 : 250,
|
||||
(params) => {
|
||||
return params === GroupCode;
|
||||
},
|
||||
GroupCode, [uid], forced,
|
||||
);
|
||||
return _members.get(uid);
|
||||
const EventFunc = this.core.eventWrapper.createEventFunction<EventType>('NodeIKernelGroupService/getMemberInfo');
|
||||
const retData = await EventFunc!(GroupCode, [uid], forced);
|
||||
if (retData.result !== 0) {
|
||||
throw new Error(`${retData.errMsg}`);
|
||||
}
|
||||
const result = await Listener as unknown;
|
||||
let member: GroupMember | undefined;
|
||||
if (Array.isArray(result) && result?.[2] instanceof Map) {
|
||||
let members = result[2] as Map<string, GroupMember>;
|
||||
member = members.get(uid);
|
||||
};
|
||||
return member;
|
||||
|
||||
// 原本的方法: (no_cache 下效率很高, cache 下效率一致)
|
||||
// const [, , , _members] = await this.core.eventWrapper.CallNormalEvent<EventType, ListenerType>
|
||||
// (
|
||||
// 'NodeIKernelGroupService/getMemberInfo',
|
||||
// 'NodeIKernelGroupListener/onMemberInfoChange',
|
||||
// 1,
|
||||
// 5000,
|
||||
// (groupCode: string, changeType: number, members: Map<string, GroupMember>) => {
|
||||
// return groupCode == GroupCode && members.has(uid);
|
||||
// },
|
||||
// GroupCode, [uid], forced,
|
||||
// );
|
||||
// return _members.get(uid);
|
||||
}
|
||||
|
||||
async getGroupMembers(groupQQ: string, num = 3000): Promise<Map<string, GroupMember>> {
|
||||
|
@@ -16,6 +16,9 @@ export class NTQQMsgApi {
|
||||
return this.context.session.getMsgService().fetchLongMsg(peer, msgId);
|
||||
}
|
||||
|
||||
async sendShowInputStatusReq(peer: Peer, eventType: number) {
|
||||
return this.context.session.getMsgService().sendShowInputStatusReq(peer.chatType, eventType, peer.peerUid);
|
||||
}
|
||||
async getMsgEmojiLikesList(peer: Peer, msgSeq: string, emojiId: string, emojiType: string, count: number = 20) {
|
||||
//console.log(peer, msgSeq, emojiId, emojiType, count);
|
||||
//注意此处emojiType 可选值一般为1-2 2好像是unicode表情dec值 大部分情况 Taged M likiowa
|
||||
|
@@ -100,7 +100,7 @@ export class NTQQUserApi {
|
||||
return retData;
|
||||
}
|
||||
|
||||
async fetchUserDetailInfo(uid: string) {
|
||||
async fetchUserDetailInfo(uid: string, mode: UserDetailSource = UserDetailSource.KDB) {
|
||||
type EventService = NodeIKernelProfileService['fetchUserDetailInfo'];
|
||||
type EventListener = NodeIKernelProfileListener['onUserDetailInfoChanged'];
|
||||
const [_retData, profile] = await this.core.eventWrapper.CallNormalEvent<EventService, EventListener>(
|
||||
@@ -111,7 +111,7 @@ export class NTQQUserApi {
|
||||
(profile) => profile.uid === uid,
|
||||
'BuddyProfileStore',
|
||||
[uid],
|
||||
UserDetailSource.KSERVER,
|
||||
mode,
|
||||
[ProfileBizType.KALL],
|
||||
);
|
||||
const RetUser: User = {
|
||||
@@ -120,14 +120,23 @@ export class NTQQUserApi {
|
||||
...profile.simpleInfo.vasInfo,
|
||||
...profile.commonExt,
|
||||
...profile.simpleInfo.baseInfo,
|
||||
qqLevel: profile.commonExt.qqLevel,
|
||||
qqLevel: profile.commonExt?.qqLevel,
|
||||
age: profile.simpleInfo.baseInfo.age,
|
||||
pendantId: '',
|
||||
};
|
||||
return RetUser;
|
||||
}
|
||||
|
||||
async getUserDetailInfo(uid: string) {
|
||||
return this.fetchUserDetailInfo(uid);
|
||||
async getUserDetailInfo(uid: string): Promise<User> {
|
||||
try {
|
||||
let retUser = await this.fetchUserDetailInfo(uid, UserDetailSource.KDB);
|
||||
if (retUser.uin !== '0') {
|
||||
return retUser;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
this.context.logger.logDebug('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.');
|
||||
return this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER);
|
||||
}
|
||||
|
||||
async modifySelfProfile(param: ModifyProfileParams) {
|
||||
@@ -187,9 +196,9 @@ export class NTQQUserApi {
|
||||
|
||||
//后期改成流水线处理
|
||||
async getUidByUinV2(Uin: string) {
|
||||
let uid = (await this.context.session.getProfileService().getUidByUin('FriendsServiceImpl', [Uin])).get(Uin);
|
||||
let uid = (await this.context.session.getGroupService().getUidByUins([Uin])).uids.get(Uin);
|
||||
if (uid) return uid;
|
||||
uid = (await this.context.session.getGroupService().getUidByUins([Uin])).uids.get(Uin);
|
||||
uid = (await this.context.session.getProfileService().getUidByUin('FriendsServiceImpl', [Uin])).get(Uin);
|
||||
if (uid) return uid;
|
||||
uid = (await this.context.session.getUixConvertService().getUid([Uin])).uidInfo.get(Uin);
|
||||
if (uid) return uid;
|
||||
@@ -201,9 +210,9 @@ export class NTQQUserApi {
|
||||
|
||||
//后期改成流水线处理
|
||||
async getUinByUidV2(Uid: string) {
|
||||
let uin = (await this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [Uid])).get(Uid);
|
||||
let uin = (await this.context.session.getGroupService().getUinByUids([Uid])).uins.get(Uid);
|
||||
if (uin) return uin;
|
||||
uin = (await this.context.session.getGroupService().getUinByUids([Uid])).uins.get(Uid);
|
||||
uin = (await this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [Uid])).get(Uid);
|
||||
if (uin) return uin;
|
||||
uin = (await this.context.session.getUixConvertService().getUin([Uid])).uinInfo.get(Uid);
|
||||
if (uin) return uin;
|
||||
|
@@ -196,6 +196,9 @@ export class NapCatCore {
|
||||
this.apis.GroupApi.groupMemberCache.set(groupCode, members);
|
||||
}
|
||||
};
|
||||
this.context.session.getGroupService().addKernelGroupListener(
|
||||
new this.context.wrapper.NodeIKernelGroupListener(proxiedListenerOf(groupListener, this.context.logger)),
|
||||
);
|
||||
}
|
||||
checkAdminEvent(groupCode: string, memberNew: GroupMember, memberOld: GroupMember | undefined): boolean {
|
||||
if (memberNew.role !== memberOld?.role) {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { QQLevel, Sex } from './user';
|
||||
import { QQLevel, Sex, User } from './user';
|
||||
|
||||
export enum GroupListUpdateType {
|
||||
REFRESHALL,
|
||||
@@ -65,6 +65,7 @@ export interface GroupMember {
|
||||
uin: string; // QQ号
|
||||
isRobot: boolean;
|
||||
sex?: Sex;
|
||||
age?: number;
|
||||
qqLevel?: QQLevel;
|
||||
isChangeRole: boolean;
|
||||
joinTime: string;
|
||||
|
@@ -231,6 +231,7 @@ export interface User {
|
||||
longNick?: string; // 签名
|
||||
remark?: string;
|
||||
sex?: Sex;
|
||||
age?: number;
|
||||
qqLevel?: QQLevel;
|
||||
qid?: string;
|
||||
birthday_year?: number;
|
||||
|
44
src/onebot/action/extends/SetInputStatus.ts
Normal file
44
src/onebot/action/extends/SetInputStatus.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { ChatType, Peer } from '@/core';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
eventType: { type: 'string' },
|
||||
group_id: { type: 'string' },
|
||||
user_id: { type: 'string' }
|
||||
},
|
||||
required: ['eventType'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SetInputStatus extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetInputStatus;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.apis.UserApi;
|
||||
const NTQQMsgApi = this.CoreContext.apis.MsgApi;
|
||||
let peer: Peer;
|
||||
if (payload.group_id) {
|
||||
peer = {
|
||||
chatType: ChatType.group,
|
||||
peerUid: payload.group_id
|
||||
}
|
||||
} else if (payload.user_id) {
|
||||
let uid = await NTQQUserApi.getUidByUinV2(payload.user_id);
|
||||
if (!uid) throw new Error('uid is empty');
|
||||
peer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: uid
|
||||
}
|
||||
} else {
|
||||
throw new Error('请指定 group_id 或 user_id');
|
||||
}
|
||||
|
||||
const ret = await NTQQMsgApi.sendShowInputStatusReq(peer, parseInt(payload.eventType));
|
||||
return ret;
|
||||
}
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
nick: { type: 'string' },
|
||||
longNick: { type: 'string' },
|
||||
sex: { type: ['number', 'string'] },//传Sex值?建议传0
|
||||
},
|
||||
required: ['nick', 'longNick', 'sex'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SetSelfProfile extends BaseAction<Payload, any | null> {
|
||||
actionName = ActionName.SetSelfProfile;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.apis.UserApi;
|
||||
const ret = await NTQQUserApi.modifySelfProfile({
|
||||
nick: payload.nick,
|
||||
longNick: payload.longNick,
|
||||
sex: parseInt(payload.sex.toString()),
|
||||
birthday: { birthday_year: '', birthday_month: '', birthday_day: '' },
|
||||
location: undefined,
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
}
|
@@ -34,7 +34,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
||||
sex: OB11UserSex.unknown,
|
||||
age: extendData.detail.simpleInfo.baseInfo.age || 0,
|
||||
qid: extendData.detail.simpleInfo.baseInfo.qid,
|
||||
level: calcQQLevel(extendData.detail.commonExt.qqLevel) || 0,
|
||||
level: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? 0) || 0,
|
||||
login_days: 0,
|
||||
uid: ''
|
||||
};
|
||||
|
@@ -7,18 +7,18 @@ import { checkFileReceived, uri2local } from '@/common/utils/file';
|
||||
|
||||
interface Payload {
|
||||
file: string,
|
||||
groupCode: string
|
||||
group_id: number
|
||||
}
|
||||
|
||||
export default class SetGroupHeader extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetGroupHeader;
|
||||
export default class SetGroupPortrait extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetGroupPortrait;
|
||||
|
||||
// 用不着复杂检测
|
||||
protected async check(payload: Payload): Promise<BaseCheckResult> {
|
||||
if (!payload.file || typeof payload.file != 'string' || !payload.groupCode || typeof payload.groupCode != 'string') {
|
||||
if (!payload.file || typeof payload.file != 'string' || !payload.group_id || typeof payload.group_id != 'number') {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'file和groupCode字段不能为空或者类型错误',
|
||||
message: 'file和group_id字段不能为空或者类型错误',
|
||||
};
|
||||
}
|
||||
return {
|
||||
@@ -34,7 +34,7 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
|
||||
}
|
||||
if (path) {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQGroupApi.setGroupAvatar(payload.groupCode, path);
|
||||
const ret = await NTQQGroupApi.setGroupAvatar(payload.group_id.toString(), path) as any;
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => {
|
||||
});
|
||||
@@ -43,11 +43,11 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
|
||||
throw `头像${payload.file}设置失败,api无返回`;
|
||||
}
|
||||
// log(`头像设置返回:${JSON.stringify(ret)}`)
|
||||
// if (ret['result'] == 1004022) {
|
||||
// throw `头像${payload.file}设置失败,文件可能不是图片格式`;
|
||||
// } else if (ret['result'] != 0) {
|
||||
// throw `头像${payload.file}设置失败,未知的错误,${ret['result']}:${ret['errMsg']}`;
|
||||
// }
|
||||
if (ret['result'] == 1004022) {
|
||||
throw `头像${payload.file}设置失败,文件可能不是图片格式或权限不足`;
|
||||
} else if (ret['result'] != 0) {
|
||||
throw `头像${payload.file}设置失败,未知的错误,${ret['result']}:${ret['errMsg']}`;
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
if (!isLocal) {
|
34
src/onebot/action/go-cqhttp/SetQQProfile.ts
Normal file
34
src/onebot/action/go-cqhttp/SetQQProfile.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
nickname: { type: 'string' },
|
||||
personal_note: { type: 'string' },
|
||||
sex: { type: ['number', 'string'] },//传Sex值?建议传0
|
||||
},
|
||||
required: ['nickname'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SetQQProfile extends BaseAction<Payload, any | null> {
|
||||
actionName = ActionName.SetQQProfile;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.apis.UserApi;
|
||||
const self = this.CoreContext.selfInfo;
|
||||
const OldProfile = await NTQQUserApi.getUserDetailInfo(self.uid);
|
||||
const ret = await NTQQUserApi.modifySelfProfile({
|
||||
nick: payload.nickname,
|
||||
longNick: payload?.personal_note ?? OldProfile?.longNick!,
|
||||
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.sex!.toString()),
|
||||
birthday: { birthday_year: OldProfile?.birthday_year!.toString(), birthday_month: OldProfile?.birthday_month!.toString(), birthday_day: OldProfile?.birthday_day!.toString() },
|
||||
location: undefined,
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ import { OB11Constructor } from '../../helper/data';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { GroupMember } from '@/core';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
@@ -23,39 +24,25 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
||||
async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.apis.UserApi;
|
||||
const NTQQGroupApi = this.CoreContext.apis.GroupApi;
|
||||
const NTQQWebApi = this.CoreContext.apis.WebApi;
|
||||
const isNocache = typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache;
|
||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
||||
if (!uid) throw (`Uin2Uid Error ${payload.user_id}不存在`);
|
||||
const member = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache);
|
||||
if (!member) throw (`群(${payload.group_id})成员${payload.user_id}不存在`);
|
||||
try {
|
||||
const info = (await NTQQUserApi.getUserDetailInfo(member.uid));
|
||||
this.CoreContext.context.logger.logDebug('群成员详细信息结果', info);
|
||||
Object.assign(member, info);
|
||||
} catch (e) {
|
||||
this.CoreContext.context.logger.logDebug('获取群成员详细信息失败, 只能返回基础信息', e);
|
||||
const [member, info] = await Promise.allSettled([
|
||||
NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache),
|
||||
NTQQUserApi.getUserDetailInfo(uid),
|
||||
]);
|
||||
if (member.status !== 'fulfilled') throw (`群(${payload.group_id})成员${payload.user_id}不存在 ${member.reason}`);
|
||||
if (info.status === 'fulfilled') {
|
||||
this.CoreContext.context.logger.logDebug("群成员详细信息结果", info.value);
|
||||
Object.assign(member, info.value);
|
||||
} else {
|
||||
this.CoreContext.context.logger.logDebug(`获取群成员详细信息失败, 只能返回基础信息 ${info.reason}`);
|
||||
}
|
||||
const date = Math.round(Date.now() / 1000);
|
||||
const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member);
|
||||
const SelfInfoInGroup = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), this.CoreContext.selfInfo.uid, isNocache);
|
||||
let isPrivilege = false;
|
||||
if (SelfInfoInGroup) {
|
||||
isPrivilege = SelfInfoInGroup.role === 3 || SelfInfoInGroup.role === 4;
|
||||
}
|
||||
if (isPrivilege) {
|
||||
const webGroupMembers = await NTQQWebApi.getGroupMembers(payload.group_id.toString());
|
||||
for (let i = 0, len = webGroupMembers.length; i < len; i++) {
|
||||
if (webGroupMembers[i]?.uin && webGroupMembers[i].uin === retMember.user_id) {
|
||||
retMember.join_time = webGroupMembers[i]?.join_time;
|
||||
retMember.last_sent_time = webGroupMembers[i]?.last_speak_time;
|
||||
retMember.qage = webGroupMembers[i]?.qage;
|
||||
retMember.level = webGroupMembers[i]?.lv.level.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
retMember.last_sent_time = parseInt((await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id))?.lastSpeakTime || date.toString());
|
||||
retMember.join_time = parseInt((await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id))?.joinTime || date.toString());
|
||||
const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member.value as GroupMember);
|
||||
const Member = await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id);
|
||||
retMember.last_sent_time = parseInt(Member?.lastSpeakTime || date.toString());
|
||||
retMember.join_time = parseInt(Member?.joinTime || date.toString());
|
||||
return retMember;
|
||||
}
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ import { TranslateEnWordToZn } from './extends/TranslateEnWordToZn';
|
||||
import { SetGroupFileFolder } from './file/SetGroupFileFolder';
|
||||
import { DelGroupFile } from './file/DelGroupFile';
|
||||
import { DelGroupFileFolder } from './file/DelGroupFileFolder';
|
||||
import { SetSelfProfile } from './extends/SetSelfProfile';
|
||||
import { SetQQProfile } from './go-cqhttp/SetQQProfile'
|
||||
import { ShareGroupEx, SharePeer } from './extends/ShareContact';
|
||||
import { CreateCollection } from './extends/CreateCollection';
|
||||
import { SetLongNick } from './extends/SetLongNick';
|
||||
@@ -69,7 +69,7 @@ import DelEssenceMsg from './group/DelEssenceMsg';
|
||||
import SetEssenceMsg from './group/SetEssenceMsg';
|
||||
import GetRecentContact from './user/GetRecentContact';
|
||||
import { GetProfileLike } from './extends/GetProfileLike';
|
||||
import SetGroupHeader from './extends/SetGroupHeader';
|
||||
import SetGroupPortrait from './go-cqhttp/SetGroupPortrait';
|
||||
import { FetchCustomFace } from './extends/FetchCustomFace';
|
||||
import GoCQHTTPUploadPrivateFile from './go-cqhttp/UploadPrivareFile';
|
||||
import { FetchEmojiLike } from './extends/FetchEmojiLike';
|
||||
@@ -78,6 +78,7 @@ import { NapCatCore } from '@/core';
|
||||
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||
import GetGuildProfile from './guild/GetGuildProfile';
|
||||
import SetModelShow from './go-cqhttp/SetModelShow';
|
||||
import { SetInputStatus } from './extends/SetInputStatus';
|
||||
|
||||
export type ActionMap = Map<string, BaseAction<any, any>>;
|
||||
|
||||
@@ -85,7 +86,7 @@ export function createActionMap(onebotContext: NapCatOneBot11Adapter, coreContex
|
||||
const actionHandlers = [
|
||||
new FetchEmojiLike(onebotContext, coreContext),
|
||||
new GetFile(onebotContext, coreContext),
|
||||
new SetSelfProfile(onebotContext, coreContext),
|
||||
new SetQQProfile(onebotContext, coreContext),
|
||||
new ShareGroupEx(onebotContext, coreContext),
|
||||
new SharePeer(onebotContext, coreContext),
|
||||
new CreateCollection(onebotContext, coreContext),
|
||||
@@ -160,11 +161,12 @@ export function createActionMap(onebotContext: NapCatOneBot11Adapter, coreContex
|
||||
new GetRecentContact(onebotContext, coreContext),
|
||||
new MarkAllMsgAsRead(onebotContext, coreContext),
|
||||
new GetProfileLike(onebotContext, coreContext),
|
||||
new SetGroupHeader(onebotContext, coreContext),
|
||||
new SetGroupPortrait(onebotContext, coreContext),
|
||||
new FetchCustomFace(onebotContext, coreContext),
|
||||
new GoCQHTTPUploadPrivateFile(onebotContext, coreContext),
|
||||
new GetGuildProfile(onebotContext, coreContext),
|
||||
new SetModelShow(onebotContext, coreContext),
|
||||
new SetInputStatus(onebotContext, coreContext),
|
||||
];
|
||||
const actionMap = new Map();
|
||||
for (const action of actionHandlers) {
|
||||
|
@@ -56,7 +56,7 @@ const _handlers: {
|
||||
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
||||
|
||||
// then the qq is a group member
|
||||
// Mlikiowa V2.0.29 Refactor Todo
|
||||
// Mlikiowa V2.0.35 Refactor Todo
|
||||
const uid = await coreContext.apis.UserApi.getUidByUinV2(`${atQQ}`);
|
||||
if (!uid) throw new Error('Get Uid Error');
|
||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
|
||||
@@ -161,7 +161,7 @@ const _handlers: {
|
||||
} else {
|
||||
postData = data;
|
||||
}
|
||||
// Mlikiowa V2.0.29 Refactor Todo
|
||||
// Mlikiowa V2.0.35 Refactor Todo
|
||||
const signUrl = obContext.configLoader.configData.musicSignUrl;
|
||||
if (!signUrl) {
|
||||
if (data.type === 'qq') {
|
||||
|
@@ -88,11 +88,9 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
|
||||
// This function determines the type of message by the existence of user_id / group_id,
|
||||
// not message_type.
|
||||
// This redundant design of Ob11 here should be blamed.
|
||||
const NTQQGroupApi = coreContext.apis.GroupApi;
|
||||
const NTQQFriendApi = coreContext.apis.FriendApi;
|
||||
const NTQQUserApi = coreContext.apis.UserApi;
|
||||
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
||||
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id?.toString());
|
||||
return {
|
||||
chatType: ChatType.group,
|
||||
peerUid: payload.group_id.toString(),
|
||||
|
@@ -91,7 +91,7 @@ export enum ActionName {
|
||||
GetOnlineClient = 'get_online_clients',
|
||||
OCRImage = 'ocr_image',
|
||||
IOCRImage = '.ocr_image',
|
||||
SetSelfProfile = 'set_self_profile',
|
||||
SetQQProfile = 'set_qq_profile',
|
||||
CreateCollection = 'create_collection',
|
||||
GetCollectionList = 'get_collection_list',
|
||||
SetLongNick = 'set_self_longnick',
|
||||
@@ -100,11 +100,12 @@ export enum ActionName {
|
||||
GetRecentContact = 'get_recent_contact',
|
||||
_MarkAllMsgAsRead = '_mark_all_as_read',
|
||||
GetProfileLike = 'get_profile_like',
|
||||
SetGroupHeader = 'set_group_head',
|
||||
SetGroupPortrait = 'set_group_portrait',
|
||||
FetchCustomFace = 'fetch_custom_face',
|
||||
GOCQHTTP_UploadPrivateFile = 'upload_private_file',
|
||||
TestApi01 = 'test_api_01',
|
||||
FetchEmojiLike = 'fetch_emoji_like',
|
||||
GetGuildProfile = "get_guild_service_profile",
|
||||
SetModelShow = "_set_model_show"
|
||||
SetModelShow = "_set_model_show",
|
||||
SetInputStatus = "set_input_status"
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import { EventType } from '../event/OB11BaseEvent';
|
||||
import { encodeCQCode } from './cqcode';
|
||||
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
||||
import { OB11GroupBanEvent } from '../event/notice/OB11GroupBanEvent';
|
||||
import { OB11GroupCardEvent } from '../event/notice/OB11GroupCardEvent';
|
||||
import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent';
|
||||
import { OB11GroupNoticeEvent } from '../event/notice/OB11GroupNoticeEvent';
|
||||
import { calcQQLevel, sleep, UUIDConverter } from '@/common/utils/helper';
|
||||
@@ -169,7 +170,11 @@ export class OB11Constructor {
|
||||
//合并消息内侧 消息具体定位不到
|
||||
}
|
||||
if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') {
|
||||
throw new Error('回复消息消息验证失败');
|
||||
const replyMsgList = (await NTQQMsgApi.getMsgExBySeq(peer, records.msgSeq)).msgList;
|
||||
if (replyMsgList.length < 1) {
|
||||
throw new Error('回复消息消息验证失败');
|
||||
}
|
||||
replyMsg = replyMsgList.filter(e => e.msgSeq == records.msgSeq).sort((a, b) => parseInt(a.msgTime) - parseInt(b.msgTime))[0];
|
||||
}
|
||||
message_data['data']['id'] = MessageUnique.createMsg({
|
||||
peerUid: msg.peerUid,
|
||||
@@ -417,16 +422,15 @@ export class OB11Constructor {
|
||||
return;
|
||||
}
|
||||
//log("group msg", msg);
|
||||
// Mlikiowa V2.0.29 Refactor Todo
|
||||
// if (msg.senderUin && msg.senderUin !== '0') {
|
||||
// const member = await getGroupMember(msg.peerUid, msg.senderUin);
|
||||
// if (member && member.cardName !== msg.sendMemberName) {
|
||||
// const newCardName = msg.sendMemberName || '';
|
||||
// const event = new OB11GroupCardEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), newCardName, member.cardName);
|
||||
// member.cardName = newCardName;
|
||||
// return event;
|
||||
// }
|
||||
// }
|
||||
if (msg.senderUin && msg.senderUin !== '0') {
|
||||
const member = await NTQQGroupApi.getGroupMember(msg.peerUid, msg.senderUin);
|
||||
if (member && member.cardName !== msg.sendMemberName) {
|
||||
const newCardName = msg.sendMemberName || '';
|
||||
const event = new OB11GroupCardEvent(core, parseInt(msg.peerUid), parseInt(msg.senderUin), newCardName, member.cardName);
|
||||
member.cardName = newCardName;
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
||||
for (const element of msg.elements) {
|
||||
const grayTipElement = element.grayTipElement;
|
||||
@@ -709,7 +713,7 @@ export class OB11Constructor {
|
||||
nickname: member.nick,
|
||||
card: member.cardName,
|
||||
sex: OB11Constructor.sex(member.sex!),
|
||||
age: 0,
|
||||
age: member.age ?? 0,
|
||||
area: '',
|
||||
level: '0',
|
||||
qq_level: member.qqLevel && calcQQLevel(member.qqLevel) || 0,
|
||||
|
@@ -18,10 +18,11 @@ import {
|
||||
SendVideoElement,
|
||||
viedo_type,
|
||||
} from '@/core';
|
||||
import * as fsnormal from 'node:fs';
|
||||
import { promises as fs } from 'node:fs';
|
||||
import ffmpeg from 'fluent-ffmpeg';
|
||||
import { calculateFileMD5, isGIF } from '@/common/utils/file';
|
||||
import { getVideoInfo } from '@/common/utils/video';
|
||||
import { defaultVideoThumbB64, getVideoInfo } from '@/common/utils/video';
|
||||
import { encodeSilk } from '@/common/utils/audio';
|
||||
import faceConfig from '@/core/external/face_config.json';
|
||||
import * as pathLib from 'node:path';
|
||||
@@ -140,11 +141,7 @@ export class SendMsgElementConstructor {
|
||||
}
|
||||
|
||||
static async video(coreContext: NapCatCore, filePath: string, fileName: string = '', diyThumbPath: string = '', videotype: viedo_type = viedo_type.VIDEO_FORMAT_MP4): Promise<SendVideoElement> {
|
||||
const NTQQGroupApi = coreContext.apis.GroupApi;
|
||||
const NTQQUserApi = coreContext.apis.UserApi;
|
||||
const NTQQFileApi = coreContext.apis.FileApi;
|
||||
const NTQQMsgApi = coreContext.apis.MsgApi;
|
||||
const NTQQFriendApi = coreContext.apis.FriendApi;
|
||||
const logger = coreContext.context.logger;
|
||||
const { fileName: _fileName, path, fileSize, md5 } = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO);
|
||||
if (fileSize === 0) {
|
||||
@@ -179,7 +176,8 @@ export class SendMsgElementConstructor {
|
||||
resolve(thumbPath);
|
||||
}).catch(reject);
|
||||
} else {
|
||||
resolve(undefined);
|
||||
fsnormal.writeFileSync(thumbPath, Buffer.from(defaultVideoThumbB64, 'base64'));
|
||||
resolve(thumbPath);
|
||||
}
|
||||
})
|
||||
.screenshots({
|
||||
@@ -224,6 +222,21 @@ export class SendMsgElementConstructor {
|
||||
// sourceVideoCodecFormat: 2
|
||||
},
|
||||
};
|
||||
// "fileElement": {
|
||||
// "fileMd5": "",
|
||||
// "fileName": "1.mp4",
|
||||
// "filePath": "C:\\Users\\nanae\\OneDrive\\Desktop\\1.mp4",
|
||||
// "fileSize": "1847007",
|
||||
// "picHeight": 1280,
|
||||
// "picWidth": 720,
|
||||
// "picThumbPath": {},
|
||||
// "file10MMd5": "",
|
||||
// "fileSha": "",
|
||||
// "fileSha3": "",
|
||||
// "fileUuid": "",
|
||||
// "fileSubId": "",
|
||||
// "thumbFileSize": 750
|
||||
// }
|
||||
return element;
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,7 @@ import {
|
||||
NapCatCore,
|
||||
RawMessage,
|
||||
SendStatusType,
|
||||
GroupMemberRole,
|
||||
} from '@/core';
|
||||
import { OB11Config, OB11ConfigLoader } from '@/onebot/helper/config';
|
||||
import { OneBotApiContextType } from '@/onebot/types';
|
||||
@@ -413,6 +414,29 @@ export class NapCatOneBot11Adapter {
|
||||
}
|
||||
};
|
||||
|
||||
groupListener.onMemberInfoChange = async (groupCode, changeType, members) => {
|
||||
//this.context.logger.logDebug('收到群成员信息变动通知', groupCode, changeType);
|
||||
if (changeType === 0) {
|
||||
const existMembers = this.core.apis.GroupApi.groupMemberCache.get(groupCode);
|
||||
if (!existMembers) return;
|
||||
members.forEach((member) => {
|
||||
const existMember = existMembers.get(member.uid);
|
||||
if (!existMember?.isChangeRole) return;
|
||||
this.context.logger.logDebug('变动管理员获取成功');
|
||||
const groupAdminNoticeEvent = new OB11GroupAdminNoticeEvent(
|
||||
this.core,
|
||||
parseInt(groupCode),
|
||||
parseInt(member.uin),
|
||||
member.role === GroupMemberRole.admin ? 'set' : 'unset',
|
||||
);
|
||||
this.networkManager.emitEvent(groupAdminNoticeEvent)
|
||||
.catch(e => this.context.logger.logError('处理群管理员变动失败', e));
|
||||
existMember.isChangeRole = false;
|
||||
this.context.logger.logDebug('群管理员变动处理完毕');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.context.session.getGroupService().addKernelGroupListener(
|
||||
new this.context.wrapper.NodeIKernelGroupListener(proxiedListenerOf(groupListener, this.context.logger)),
|
||||
);
|
||||
|
@@ -79,6 +79,12 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
},
|
||||
|
||||
});
|
||||
this.connection.on('ping', () => {
|
||||
this.connection?.pong();
|
||||
});
|
||||
this.connection.on('pong', () => {
|
||||
//this.logger.logDebug('[OneBot] [WebSocket Client] 收到pong');
|
||||
});
|
||||
this.connection.on('open', () => {
|
||||
try {
|
||||
this.connectEvent(this.coreContext);
|
||||
|
@@ -50,6 +50,12 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
wsClient.on('message', (message) => {
|
||||
this.handleMessage(wsClient, message).then().catch(this.logger.logError);
|
||||
});
|
||||
wsClient.on('ping', () => {
|
||||
wsClient.pong();
|
||||
});
|
||||
wsClient.on('pong', () => {
|
||||
//this.logger.logDebug('[OneBot] [WebSocket Server] Pong received');
|
||||
});
|
||||
wsClient.once('close', () => {
|
||||
this.wsClientsMutex.runExclusive(async () => {
|
||||
const index = this.wsClients.indexOf(wsClient);
|
||||
|
@@ -30,7 +30,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
SettingItem(
|
||||
'<span id="napcat-update-title">Napcat</span>',
|
||||
undefined,
|
||||
SettingButton('V2.0.29', 'napcat-update-button', 'secondary'),
|
||||
SettingButton('V2.0.35', 'napcat-update-button', 'secondary'),
|
||||
),
|
||||
]),
|
||||
SettingList([
|
||||
|
@@ -164,7 +164,7 @@ async function onSettingWindowCreated(view) {
|
||||
SettingItem(
|
||||
'<span id="napcat-update-title">Napcat</span>',
|
||||
void 0,
|
||||
SettingButton("V2.0.29", "napcat-update-button", "secondary")
|
||||
SettingButton("V2.0.35", "napcat-update-button", "secondary")
|
||||
)
|
||||
]),
|
||||
SettingList([
|
||||
|
Reference in New Issue
Block a user