koishi-plugin-yesimbot-extension-sticker-manager
Version:
YesImBot 表情包管理扩展
123 lines (122 loc) • 3.43 kB
TypeScript
import { Context, h, Logger, Session } from "koishi";
import { StickerConfig } from "./index";
interface StickerRecord {
id: string;
category: string;
filePath: string;
source: {
platform: string;
channelId: string;
userId: string;
messageId: string;
};
createdAt: Date;
}
declare const TableName = "yesimbot.stickers";
declare module "koishi" {
interface Tables {
[TableName]: StickerRecord;
}
}
export declare class StickerService {
private ctx;
private config;
logger: Logger;
private static tablesRegistered;
isReady: boolean;
constructor(ctx: Context, config: StickerConfig);
private start;
whenReady(): Promise<void>;
private registerPromptSnippet;
private initStorage;
private registerModels;
/**
* 偷取表情包
* @param image_id string
* @param session
* @returns
*/
stealSticker(image_id: string, session: Session): Promise<StickerRecord>;
private classifySticker;
/**
* 从外部文件夹导入表情包
* @param sourceDir 源文件夹路径
* @param session 会话对象(用于日志记录)
* @returns 导入结果统计信息
*/
importFromDirectory(sourceDir: string, session: Session): Promise<ImportStats>;
/** 获取有效的子目录列表 */
private getValidSubdirectories;
/** 获取目录下的所有图片文件 */
private getImageFiles;
/** 校验文件类型 */
private isValidImageType;
/** 计算文件哈希值 */
private calculateFileHash;
private saveImageToLocal;
/**
* 规范化 emojihub-bili URL
* 处理特定格式的部分 URL
*/
private normalizeEmojiHubUrl;
/** 检查目录是否存在 */
private dirExists;
getCategories(): Promise<string[]>;
getRandomSticker(category: string): Promise<h>;
getStickersByCategory(category: string): Promise<StickerRecord[]>;
importEmojiHubTxt(filePath: string, category: string, session: Session): Promise<ImportStats>;
/**
* 根据Content-Type获取文件扩展名
*/
private getExtensionFromContentType;
/**
* 自定义 fetch 方法,带超时控制
*/
private fetchWithTimeout;
/**
* 清理临时目录
*/
private cleanupTempDir;
/**
* 增强版 importSingleSticker 方法
*/
private importSingleSticker;
/**
* 增强版文件类型验证
*/
private isValidImageFile;
renameCategory(oldName: string, newName: string): Promise<number>;
deleteCategory(category: string): Promise<number>;
/**
* 合并两个分类
*/
mergeCategories(sourceCategory: string, targetCategory: string): Promise<number>;
/**
* 移动表情包到新分类
*/
moveSticker(stickerId: string, newCategory: string): Promise<number>;
/**
* 获取分类中的表情包数量
*/
getStickerCount(category: string): Promise<number>;
/**
* 获取指定表情包
*/
getSticker(stickerId: string): Promise<StickerRecord | null>;
/**
* 清理未使用的表情包
*/
cleanupUnreferenced(): Promise<number>;
}
interface ImportStats {
total: number;
success: number;
failed: number;
skipped: number;
failedFiles?: string[];
failedUrls?: {
url: string;
error: string;
}[];
}
export {};