refactor: 旧代码移除

This commit is contained in:
手瓜一十雪 2024-11-21 11:01:35 +08:00
parent fa70eec3d8
commit de64b03054
12 changed files with 143 additions and 139 deletions

File diff suppressed because one or more lines are too long

View File

@ -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) {
// 用于下载收到的消息中的图片等
// 用于下载文件
if (sourcePath && fs.existsSync(sourcePath)) {
if (force) {
try {

View File

@ -147,14 +147,11 @@ export class NTQQGroupApi {
if (!members) {
try {
members = await this.getGroupMembers(groupCodeStr);
// 更新群成员列表
this.groupMemberCache.set(groupCodeStr, members);
} catch (e) {
return null;
}
}
// log('getGroupMember', members);
function getMember() {
let member: GroupMember | undefined;
if (isNumeric(memberUinOrUidStr)) {
@ -367,7 +364,6 @@ export class NTQQGroupApi {
}
}
this.context.session.getGroupService().destroyMemberListScene(sceneId);
//console.log('GetGroupMembersV3 len :', result.result.infos.size, resMode2?.infos.size, groupQQ);
return {
infos: new Map([...(resMode2?.infos ?? []), ...result.result.infos]),
finish: result.result.finish,
@ -430,7 +426,7 @@ export class NTQQGroupApi {
return this.context.session.getGroupService().operateSysNotify(
false,
{
operateType: operateType, // 2 拒绝
operateType: operateType,
targetMsg: {
seq: seq, // 通知序列号
type: type,

View File

@ -3,12 +3,7 @@ import { GroupFileInfoUpdateItem, InstanceContext, NapCatCore } from '@/core';
import { GeneralCallResult } from '@/core/services/common';
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;
core: NapCatCore;
@ -17,7 +12,10 @@ export class NTQQMsgApi {
this.context = context;
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) {
return this.context.session.getMsgService().getAioFirstViewLatestMsgs(peer, MsgCount);
}

View File

@ -1,65 +1,68 @@
import { ChatType } from './msg';
export interface CacheScanResult {
result: number;
size: [ // 单位为字节
string, // 系统总存储空间
string, // 系统可用存储空间
string, // 系统已用存储空间
string, // QQ总大小
string, // 「聊天与文件」大小
string, // 未知
string, // 「缓存数据」大小
string, // 「其他数据」大小
string, // 未知
];
}
/**
*
*/
export interface ChatCacheList {
pageCount: number;
infos: ChatCacheListItem[];
pageCount: number; // 页数
infos: ChatCacheListItem[]; // 聊天缓存项列表
}
/**
*
*/
export interface ChatCacheListItem {
chatType: ChatType;
basicChatCacheInfo: ChatCacheListItemBasic;
guildChatCacheInfo: unknown[]; // TODO: 没用过频道所以不知道这里边的详细内容
chatType: ChatType; // 聊天类型
basicChatCacheInfo: ChatCacheListItemBasic; // 基本聊天缓存信息
guildChatCacheInfo: unknown[]; // 公会聊天缓存信息
}
/**
*
*/
export interface ChatCacheListItemBasic {
chatSize: string;
chatTime: string;
uid: string;
uin: string;
remarkName: string;
nickName: string;
chatType?: ChatType;
isChecked?: boolean;
chatSize: string; // 聊天大小
chatTime: string; // 聊天时间
uid: string; // 用户ID
uin: string; // 用户号码
remarkName: string; // 备注名
nickName: string; // 昵称
chatType?: ChatType; // 聊天类型(可选)
isChecked?: boolean; // 是否已检查(可选)
}
/**
*
*/
export enum CacheFileType {
IMAGE = 0,
VIDEO = 1,
AUDIO = 2,
DOCUMENT = 3,
OTHER = 4,
IMAGE = 0, // 图片
VIDEO = 1, // 视频
AUDIO = 2, // 音频
DOCUMENT = 3, // 文档
OTHER = 4, // 其他
}
/**
*
*/
export interface CacheFileList {
infos: CacheFileListItem[],
infos: CacheFileListItem[]; // 缓存文件项列表
}
/**
*
*/
export interface CacheFileListItem {
fileSize: string;
fileTime: string;
fileKey: string;
elementId: string;
elementIdStr: string;
fileType: CacheFileType;
path: string;
fileName: string;
senderId: string;
previewPath: string;
senderName: string;
isChecked?: boolean;
}
fileSize: string; // 文件大小
fileTime: string; // 文件时间
fileKey: string; // 文件键
elementId: string; // 元素ID
elementIdStr: string; // 元素ID字符串
fileType: CacheFileType; // 文件类型
path: string; // 路径
fileName: string; // 文件名
senderId: string; // 发送者ID
previewPath: string; // 预览路径
senderName: string; // 发送者名称
isChecked?: boolean; // 是否已检查(可选)
}

View File

@ -1,7 +1,7 @@
import { OneBotAction } from '@/onebot/action/OneBotAction';
import { ActionName } from '../types';
export default class GetGuildList extends OneBotAction<null, null> {
export class GetGuildList extends OneBotAction<null, null> {
actionName = ActionName.GetGuildList;
async _handle(payload: null): Promise<null> {

View File

@ -1,7 +1,7 @@
import { OneBotAction } from '@/onebot/action/OneBotAction';
import { ActionName } from '../types';
export default class GetGuildProfile extends OneBotAction<null, null> {
export class GetGuildProfile extends OneBotAction<null, null> {
actionName = ActionName.GetGuildProfile;
async _handle(payload: null): Promise<null> {

View File

@ -22,7 +22,6 @@ import GoCQHTTPGetStrangerInfo from './go-cqhttp/GetStrangerInfo';
import SendLike from './user/SendLike';
import SetGroupAddRequest from './group/SetGroupAddRequest';
import SetGroupLeave from './group/SetGroupLeave';
import GetGuildList from './guild/GetGuildList';
import SetFriendAddRequest from './user/SetFriendAddRequest';
import SetGroupWholeBan from './group/SetGroupWholeBan';
import SetGroupName from './group/SetGroupName';
@ -70,7 +69,6 @@ import { FetchEmojiLike } from './extends/FetchEmojiLike';
import { FetchUserProfileLike } from './extends/FetchUserProfileLike';
import { NapCatCore } from '@/core';
import { NapCatOneBot11Adapter } from '@/onebot';
import GetGuildProfile from './guild/GetGuildProfile';
import { SetInputStatus } from './extends/SetInputStatus';
import { GetCSRF } from './system/GetCSRF';
import { DelGroupNotice } from './group/DelGroupNotice';
@ -102,6 +100,8 @@ import { GetMiniAppArk } from "@/onebot/action/extends/GetMiniAppArk";
import { GetAiRecord } from "@/onebot/action/group/GetAiRecord";
import { SendGroupAiRecord } from "@/onebot/action/group/SendGroupAiRecord";
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>>;

View File

@ -27,19 +27,18 @@ export class SetMsgEmojiLike extends OneBotAction<Payload, any> {
if (!payload.emoji_id) {
throw new Error('emojiId not found');
}
if (!payload.set) {
payload.set = true;
}
payload.set = payload.set ?? true;
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');
}
return await this.core.apis.MsgApi.setEmojiLike(
msg.Peer,
msgData[0].msgSeq,
payload.emoji_id.toString(),
typeof payload.set == 'string' ? payload.set === 'true' : !!payload
typeof payload.set === 'string' ? payload.set === 'true' : !!payload.set
);
}
}
}

View File

@ -24,7 +24,7 @@ function from(source: string) {
return { type, data, capture };
}
function h(type: string, data: any) {
function convert(type: string, data: any) {
return {
type,
data,
@ -37,31 +37,29 @@ export function decodeCQCode(source: string): OB11MessageData[] {
while ((result = from(source))) {
const { type, data, capture } = result;
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);
}
if (source) elements.push(h('text', { text: unescape(source) }));
if (source) elements.push(convert('text', { text: unescape(source) }));
return elements;
}
function CQCodeEscapeText(text: string) {
return text.replace(/&/g, '&amp;')
.replace(/\[/g, '&#91;')
.replace(/]/g, '&#93;');
}
function CQCodeEscape(text: string) {
return text.replace(/&/g, '&amp;')
.replace(/\[/g, '&#91;')
.replace(/]/g, '&#93;')
.replace(/,/g, '&#44;');
}
export function encodeCQCode(data: OB11MessageData) {
const CQCodeEscapeText = (text: string) => {
return text.replace(/&/g, '&amp;')
.replace(/\[/g, '&#91;')
.replace(/]/g, '&#93;');
};
const CQCodeEscape = (text: string) => {
return text.replace(/&/g, '&amp;')
.replace(/\[/g, '&#91;')
.replace(/]/g, '&#93;')
.replace(/,/g, '&#44;');
};
if (data.type === 'text') {
return CQCodeEscapeText(data.data.text);
}
@ -74,11 +72,13 @@ export function encodeCQCode(data: OB11MessageData) {
}
try {
const text = value?.toString();
if (text) result += `,${name}=${CQCodeEscape(text)}`;
if (text) {
result += `,${name}=${CQCodeEscape(text)}`;
}
} catch (error) {
// If it can't be converted, skip this name-value pair
console.error(`Error encoding CQCode for ${name}:`, error);
}
}
result += ']';
return result;
}
}

View File

@ -3,7 +3,7 @@ import { NapCatCore } from '@/core';
export class OB11GroupAdminNoticeEvent extends OB11GroupNoticeEvent {
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') {
super(core, group_id, user_id);

View File

@ -5,13 +5,13 @@ export type GroupDecreaseSubType = 'leave' | 'kick' | 'kick_me';
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
notice_type = 'group_decrease';
sub_type: GroupDecreaseSubType = 'leave'; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
sub_type: GroupDecreaseSubType = 'leave';
operator_id: number;
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
super(core, groupId, userId);
this.group_id = groupId;
this.operator_id = operatorId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
this.operator_id = operatorId;
this.user_id = userId;
this.sub_type = subType;
}