mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: 旧代码移除
This commit is contained in:
parent
fa70eec3d8
commit
de64b03054
File diff suppressed because one or more lines are too long
@ -320,7 +320,7 @@ export class NTQQFileApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, timeout = 1000 * 60 * 2, force: boolean = false) {
|
async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, timeout = 1000 * 60 * 2, force: boolean = false) {
|
||||||
// 用于下载收到的消息中的图片等
|
// 用于下载文件
|
||||||
if (sourcePath && fs.existsSync(sourcePath)) {
|
if (sourcePath && fs.existsSync(sourcePath)) {
|
||||||
if (force) {
|
if (force) {
|
||||||
try {
|
try {
|
||||||
|
@ -147,14 +147,11 @@ export class NTQQGroupApi {
|
|||||||
if (!members) {
|
if (!members) {
|
||||||
try {
|
try {
|
||||||
members = await this.getGroupMembers(groupCodeStr);
|
members = await this.getGroupMembers(groupCodeStr);
|
||||||
// 更新群成员列表
|
|
||||||
this.groupMemberCache.set(groupCodeStr, members);
|
this.groupMemberCache.set(groupCodeStr, members);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// log('getGroupMember', members);
|
|
||||||
function getMember() {
|
function getMember() {
|
||||||
let member: GroupMember | undefined;
|
let member: GroupMember | undefined;
|
||||||
if (isNumeric(memberUinOrUidStr)) {
|
if (isNumeric(memberUinOrUidStr)) {
|
||||||
@ -367,7 +364,6 @@ export class NTQQGroupApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.context.session.getGroupService().destroyMemberListScene(sceneId);
|
this.context.session.getGroupService().destroyMemberListScene(sceneId);
|
||||||
//console.log('GetGroupMembersV3 len :', result.result.infos.size, resMode2?.infos.size, groupQQ);
|
|
||||||
return {
|
return {
|
||||||
infos: new Map([...(resMode2?.infos ?? []), ...result.result.infos]),
|
infos: new Map([...(resMode2?.infos ?? []), ...result.result.infos]),
|
||||||
finish: result.result.finish,
|
finish: result.result.finish,
|
||||||
@ -430,7 +426,7 @@ export class NTQQGroupApi {
|
|||||||
return this.context.session.getGroupService().operateSysNotify(
|
return this.context.session.getGroupService().operateSysNotify(
|
||||||
false,
|
false,
|
||||||
{
|
{
|
||||||
operateType: operateType, // 2 拒绝
|
operateType: operateType,
|
||||||
targetMsg: {
|
targetMsg: {
|
||||||
seq: seq, // 通知序列号
|
seq: seq, // 通知序列号
|
||||||
type: type,
|
type: type,
|
||||||
|
@ -3,12 +3,7 @@ import { GroupFileInfoUpdateItem, InstanceContext, NapCatCore } from '@/core';
|
|||||||
import { GeneralCallResult } from '@/core/services/common';
|
import { GeneralCallResult } from '@/core/services/common';
|
||||||
|
|
||||||
export class NTQQMsgApi {
|
export class NTQQMsgApi {
|
||||||
getMsgByClientSeqAndTime(peer: Peer, replyMsgClientSeq: string, replyMsgTime: string) {
|
|
||||||
return this.context.session.getMsgService().getMsgByClientSeqAndTime(peer, replyMsgClientSeq, replyMsgTime);
|
|
||||||
}
|
|
||||||
// nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览
|
|
||||||
// nt_qq\global\nt_data\Emoji\emoji-resource\face_config.json 里面有所有表情的id, 自带表情id是QSid, 标准emoji表情id是QCid
|
|
||||||
// 其实以官方文档为准是最好的,https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType
|
|
||||||
|
|
||||||
context: InstanceContext;
|
context: InstanceContext;
|
||||||
core: NapCatCore;
|
core: NapCatCore;
|
||||||
@ -17,7 +12,10 @@ export class NTQQMsgApi {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.core = core;
|
this.core = core;
|
||||||
}
|
}
|
||||||
|
getMsgByClientSeqAndTime(peer: Peer, replyMsgClientSeq: string, replyMsgTime: string) {
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType 可以用过特殊方式拉取
|
||||||
|
return this.context.session.getMsgService().getMsgByClientSeqAndTime(peer, replyMsgClientSeq, replyMsgTime);
|
||||||
|
}
|
||||||
async getAioFirstViewLatestMsgs(peer: Peer, MsgCount: number) {
|
async getAioFirstViewLatestMsgs(peer: Peer, MsgCount: number) {
|
||||||
return this.context.session.getMsgService().getAioFirstViewLatestMsgs(peer, MsgCount);
|
return this.context.session.getMsgService().getAioFirstViewLatestMsgs(peer, MsgCount);
|
||||||
}
|
}
|
||||||
|
@ -1,65 +1,68 @@
|
|||||||
import { ChatType } from './msg';
|
import { ChatType } from './msg';
|
||||||
|
|
||||||
export interface CacheScanResult {
|
/**
|
||||||
result: number;
|
* 聊天缓存列表
|
||||||
size: [ // 单位为字节
|
*/
|
||||||
string, // 系统总存储空间
|
|
||||||
string, // 系统可用存储空间
|
|
||||||
string, // 系统已用存储空间
|
|
||||||
string, // QQ总大小
|
|
||||||
string, // 「聊天与文件」大小
|
|
||||||
string, // 未知
|
|
||||||
string, // 「缓存数据」大小
|
|
||||||
string, // 「其他数据」大小
|
|
||||||
string, // 未知
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChatCacheList {
|
export interface ChatCacheList {
|
||||||
pageCount: number;
|
pageCount: number; // 页数
|
||||||
infos: ChatCacheListItem[];
|
infos: ChatCacheListItem[]; // 聊天缓存项列表
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天缓存列表项
|
||||||
|
*/
|
||||||
export interface ChatCacheListItem {
|
export interface ChatCacheListItem {
|
||||||
chatType: ChatType;
|
chatType: ChatType; // 聊天类型
|
||||||
basicChatCacheInfo: ChatCacheListItemBasic;
|
basicChatCacheInfo: ChatCacheListItemBasic; // 基本聊天缓存信息
|
||||||
guildChatCacheInfo: unknown[]; // TODO: 没用过频道所以不知道这里边的详细内容
|
guildChatCacheInfo: unknown[]; // 公会聊天缓存信息
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基本聊天缓存信息
|
||||||
|
*/
|
||||||
export interface ChatCacheListItemBasic {
|
export interface ChatCacheListItemBasic {
|
||||||
chatSize: string;
|
chatSize: string; // 聊天大小
|
||||||
chatTime: string;
|
chatTime: string; // 聊天时间
|
||||||
uid: string;
|
uid: string; // 用户ID
|
||||||
uin: string;
|
uin: string; // 用户号码
|
||||||
remarkName: string;
|
remarkName: string; // 备注名
|
||||||
nickName: string;
|
nickName: string; // 昵称
|
||||||
chatType?: ChatType;
|
chatType?: ChatType; // 聊天类型(可选)
|
||||||
isChecked?: boolean;
|
isChecked?: boolean; // 是否已检查(可选)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存文件类型枚举
|
||||||
|
*/
|
||||||
export enum CacheFileType {
|
export enum CacheFileType {
|
||||||
IMAGE = 0,
|
IMAGE = 0, // 图片
|
||||||
VIDEO = 1,
|
VIDEO = 1, // 视频
|
||||||
AUDIO = 2,
|
AUDIO = 2, // 音频
|
||||||
DOCUMENT = 3,
|
DOCUMENT = 3, // 文档
|
||||||
OTHER = 4,
|
OTHER = 4, // 其他
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存文件列表
|
||||||
|
*/
|
||||||
export interface CacheFileList {
|
export interface CacheFileList {
|
||||||
infos: CacheFileListItem[],
|
infos: CacheFileListItem[]; // 缓存文件项列表
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存文件列表项
|
||||||
|
*/
|
||||||
export interface CacheFileListItem {
|
export interface CacheFileListItem {
|
||||||
fileSize: string;
|
fileSize: string; // 文件大小
|
||||||
fileTime: string;
|
fileTime: string; // 文件时间
|
||||||
fileKey: string;
|
fileKey: string; // 文件键
|
||||||
elementId: string;
|
elementId: string; // 元素ID
|
||||||
elementIdStr: string;
|
elementIdStr: string; // 元素ID字符串
|
||||||
fileType: CacheFileType;
|
fileType: CacheFileType; // 文件类型
|
||||||
path: string;
|
path: string; // 路径
|
||||||
fileName: string;
|
fileName: string; // 文件名
|
||||||
senderId: string;
|
senderId: string; // 发送者ID
|
||||||
previewPath: string;
|
previewPath: string; // 预览路径
|
||||||
senderName: string;
|
senderName: string; // 发送者名称
|
||||||
isChecked?: boolean;
|
isChecked?: boolean; // 是否已检查(可选)
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
|
|
||||||
export default class GetGuildList extends OneBotAction<null, null> {
|
export class GetGuildList extends OneBotAction<null, null> {
|
||||||
actionName = ActionName.GetGuildList;
|
actionName = ActionName.GetGuildList;
|
||||||
|
|
||||||
async _handle(payload: null): Promise<null> {
|
async _handle(payload: null): Promise<null> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
|
|
||||||
export default class GetGuildProfile extends OneBotAction<null, null> {
|
export class GetGuildProfile extends OneBotAction<null, null> {
|
||||||
actionName = ActionName.GetGuildProfile;
|
actionName = ActionName.GetGuildProfile;
|
||||||
|
|
||||||
async _handle(payload: null): Promise<null> {
|
async _handle(payload: null): Promise<null> {
|
||||||
|
@ -22,7 +22,6 @@ import GoCQHTTPGetStrangerInfo from './go-cqhttp/GetStrangerInfo';
|
|||||||
import SendLike from './user/SendLike';
|
import SendLike from './user/SendLike';
|
||||||
import SetGroupAddRequest from './group/SetGroupAddRequest';
|
import SetGroupAddRequest from './group/SetGroupAddRequest';
|
||||||
import SetGroupLeave from './group/SetGroupLeave';
|
import SetGroupLeave from './group/SetGroupLeave';
|
||||||
import GetGuildList from './guild/GetGuildList';
|
|
||||||
import SetFriendAddRequest from './user/SetFriendAddRequest';
|
import SetFriendAddRequest from './user/SetFriendAddRequest';
|
||||||
import SetGroupWholeBan from './group/SetGroupWholeBan';
|
import SetGroupWholeBan from './group/SetGroupWholeBan';
|
||||||
import SetGroupName from './group/SetGroupName';
|
import SetGroupName from './group/SetGroupName';
|
||||||
@ -70,7 +69,6 @@ import { FetchEmojiLike } from './extends/FetchEmojiLike';
|
|||||||
import { FetchUserProfileLike } from './extends/FetchUserProfileLike';
|
import { FetchUserProfileLike } from './extends/FetchUserProfileLike';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { NapCatOneBot11Adapter } from '@/onebot';
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||||
import GetGuildProfile from './guild/GetGuildProfile';
|
|
||||||
import { SetInputStatus } from './extends/SetInputStatus';
|
import { SetInputStatus } from './extends/SetInputStatus';
|
||||||
import { GetCSRF } from './system/GetCSRF';
|
import { GetCSRF } from './system/GetCSRF';
|
||||||
import { DelGroupNotice } from './group/DelGroupNotice';
|
import { DelGroupNotice } from './group/DelGroupNotice';
|
||||||
@ -102,6 +100,8 @@ import { GetMiniAppArk } from "@/onebot/action/extends/GetMiniAppArk";
|
|||||||
import { GetAiRecord } from "@/onebot/action/group/GetAiRecord";
|
import { GetAiRecord } from "@/onebot/action/group/GetAiRecord";
|
||||||
import { SendGroupAiRecord } from "@/onebot/action/group/SendGroupAiRecord";
|
import { SendGroupAiRecord } from "@/onebot/action/group/SendGroupAiRecord";
|
||||||
import { GetAiCharacters } from "@/onebot/action/extends/GetAiCharacters";
|
import { GetAiCharacters } from "@/onebot/action/extends/GetAiCharacters";
|
||||||
|
import { GetGuildList } from './guild/GetGuildList';
|
||||||
|
import { GetGuildProfile } from './guild/GetGuildProfile';
|
||||||
|
|
||||||
|
|
||||||
export type ActionMap = Map<string, OneBotAction<any, any>>;
|
export type ActionMap = Map<string, OneBotAction<any, any>>;
|
||||||
|
@ -27,19 +27,18 @@ export class SetMsgEmojiLike extends OneBotAction<Payload, any> {
|
|||||||
if (!payload.emoji_id) {
|
if (!payload.emoji_id) {
|
||||||
throw new Error('emojiId not found');
|
throw new Error('emojiId not found');
|
||||||
}
|
}
|
||||||
if (!payload.set) {
|
payload.set = payload.set ?? true;
|
||||||
payload.set = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const msgData = (await this.core.apis.MsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId])).msgList;
|
const msgData = (await this.core.apis.MsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId])).msgList;
|
||||||
if (!msgData || msgData.length == 0 || !msgData[0].msgSeq) {
|
if (!msgData || msgData.length === 0 || !msgData[0].msgSeq) {
|
||||||
throw new Error('find msg by msgid error');
|
throw new Error('find msg by msgid error');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.core.apis.MsgApi.setEmojiLike(
|
return await this.core.apis.MsgApi.setEmojiLike(
|
||||||
msg.Peer,
|
msg.Peer,
|
||||||
msgData[0].msgSeq,
|
msgData[0].msgSeq,
|
||||||
payload.emoji_id.toString(),
|
payload.emoji_id.toString(),
|
||||||
typeof payload.set == 'string' ? payload.set === 'true' : !!payload
|
typeof payload.set === 'string' ? payload.set === 'true' : !!payload.set
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ function from(source: string) {
|
|||||||
return { type, data, capture };
|
return { type, data, capture };
|
||||||
}
|
}
|
||||||
|
|
||||||
function h(type: string, data: any) {
|
function convert(type: string, data: any) {
|
||||||
return {
|
return {
|
||||||
type,
|
type,
|
||||||
data,
|
data,
|
||||||
@ -37,31 +37,29 @@ export function decodeCQCode(source: string): OB11MessageData[] {
|
|||||||
while ((result = from(source))) {
|
while ((result = from(source))) {
|
||||||
const { type, data, capture } = result;
|
const { type, data, capture } = result;
|
||||||
if (capture.index) {
|
if (capture.index) {
|
||||||
elements.push(h('text', { text: unescape(source.slice(0, capture.index)) }));
|
elements.push(convert('text', { text: unescape(source.slice(0, capture.index)) }));
|
||||||
}
|
}
|
||||||
elements.push(h(type, data));
|
elements.push(convert(type, data));
|
||||||
source = source.slice(capture.index + capture[0].length);
|
source = source.slice(capture.index + capture[0].length);
|
||||||
}
|
}
|
||||||
if (source) elements.push(h('text', { text: unescape(source) }));
|
if (source) elements.push(convert('text', { text: unescape(source) }));
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CQCodeEscapeText(text: string) {
|
||||||
|
return text.replace(/&/g, '&')
|
||||||
|
.replace(/\[/g, '[')
|
||||||
|
.replace(/]/g, ']');
|
||||||
|
}
|
||||||
|
|
||||||
|
function CQCodeEscape(text: string) {
|
||||||
|
return text.replace(/&/g, '&')
|
||||||
|
.replace(/\[/g, '[')
|
||||||
|
.replace(/]/g, ']')
|
||||||
|
.replace(/,/g, ',');
|
||||||
|
}
|
||||||
|
|
||||||
export function encodeCQCode(data: OB11MessageData) {
|
export function encodeCQCode(data: OB11MessageData) {
|
||||||
const CQCodeEscapeText = (text: string) => {
|
|
||||||
return text.replace(/&/g, '&')
|
|
||||||
.replace(/\[/g, '[')
|
|
||||||
.replace(/]/g, ']');
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const CQCodeEscape = (text: string) => {
|
|
||||||
return text.replace(/&/g, '&')
|
|
||||||
.replace(/\[/g, '[')
|
|
||||||
.replace(/]/g, ']')
|
|
||||||
.replace(/,/g, ',');
|
|
||||||
};
|
|
||||||
|
|
||||||
if (data.type === 'text') {
|
if (data.type === 'text') {
|
||||||
return CQCodeEscapeText(data.data.text);
|
return CQCodeEscapeText(data.data.text);
|
||||||
}
|
}
|
||||||
@ -74,11 +72,13 @@ export function encodeCQCode(data: OB11MessageData) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const text = value?.toString();
|
const text = value?.toString();
|
||||||
if (text) result += `,${name}=${CQCodeEscape(text)}`;
|
if (text) {
|
||||||
|
result += `,${name}=${CQCodeEscape(text)}`;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If it can't be converted, skip this name-value pair
|
console.error(`Error encoding CQCode for ${name}:`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result += ']';
|
result += ']';
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ import { NapCatCore } from '@/core';
|
|||||||
|
|
||||||
export class OB11GroupAdminNoticeEvent extends OB11GroupNoticeEvent {
|
export class OB11GroupAdminNoticeEvent extends OB11GroupNoticeEvent {
|
||||||
notice_type = 'group_admin';
|
notice_type = 'group_admin';
|
||||||
sub_type: 'set' | 'unset'; // "set" | "unset"
|
sub_type: 'set' | 'unset';
|
||||||
|
|
||||||
constructor(core: NapCatCore, group_id: number, user_id: number, sub_type: 'set' | 'unset') {
|
constructor(core: NapCatCore, group_id: number, user_id: number, sub_type: 'set' | 'unset') {
|
||||||
super(core, group_id, user_id);
|
super(core, group_id, user_id);
|
||||||
|
@ -5,13 +5,13 @@ export type GroupDecreaseSubType = 'leave' | 'kick' | 'kick_me';
|
|||||||
|
|
||||||
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
|
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
|
||||||
notice_type = 'group_decrease';
|
notice_type = 'group_decrease';
|
||||||
sub_type: GroupDecreaseSubType = 'leave'; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
|
sub_type: GroupDecreaseSubType = 'leave';
|
||||||
operator_id: number;
|
operator_id: number;
|
||||||
|
|
||||||
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
|
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
|
||||||
super(core, groupId, userId);
|
super(core, groupId, userId);
|
||||||
this.group_id = groupId;
|
this.group_id = groupId;
|
||||||
this.operator_id = operatorId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
|
this.operator_id = operatorId;
|
||||||
this.user_id = userId;
|
this.user_id = userId;
|
||||||
this.sub_type = subType;
|
this.sub_type = subType;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user