|
@@ -98,76 +98,4 @@ export class PluginsFile {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @runcod(["logs", "日志"], "获取日志")
|
|
|
- async getloglist() {
|
|
|
- // pluName += ".ts"
|
|
|
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
- // 查找插件目录下的文件
|
|
|
- const pluginsDir = path.join(__dirname, '..', '..','logs');
|
|
|
- try {
|
|
|
- const files = await fs.readdir(pluginsDir);
|
|
|
- const foundFiles = files.filter(file =>
|
|
|
- (file.endsWith('.log'))
|
|
|
- );
|
|
|
- foundFiles.forEach((file, index) => {
|
|
|
- foundFiles[index] = path.parse(file).name;
|
|
|
- })
|
|
|
- return `找到插件文件:${foundFiles.join(', ')}`;
|
|
|
- } catch (error) {
|
|
|
- botlogger.error('文件查找失败:', error);
|
|
|
- return '插件查找服务暂不可用';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @runcod(["downloadlog", "getlog"], "下载日志")
|
|
|
- async getlogs(
|
|
|
- @param("日志名称", ParamType.String) logName: string,
|
|
|
- context: PrivateFriendMessage | PrivateGroupMessage | GroupMessage
|
|
|
- ): Promise<any> {
|
|
|
- // pluName += ".ts"
|
|
|
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
- // 查找插件目录下的文件
|
|
|
- const pluginsDir = path.join(__dirname, '..', '..','logs');
|
|
|
- try {
|
|
|
- const files = await fs.readdir(pluginsDir);
|
|
|
- const foundFiles = files.filter(file =>
|
|
|
- (file.endsWith('.log'))
|
|
|
- );
|
|
|
-
|
|
|
- // 根据文件名查找具体插件
|
|
|
- const targetFile = foundFiles.find((file: string) =>
|
|
|
- path.parse(file).name.toLowerCase() === logName.toLowerCase()
|
|
|
- );
|
|
|
-
|
|
|
- if (!targetFile) {
|
|
|
- return `未找到名为 ${logName} 的日志`;
|
|
|
- }
|
|
|
-
|
|
|
- // 返回文件完整路径
|
|
|
- const fullPath = path.join(pluginsDir, targetFile);
|
|
|
- //.toString('base64'
|
|
|
-
|
|
|
- const file = Buffer.from(await fs.readFile(fullPath, { encoding: "utf-8" })).toString('base64')
|
|
|
- const isGroupMessage = context.message_type === 'group';
|
|
|
- if (isGroupMessage && context.group_id) {
|
|
|
- await qqBot.upload_group_file({
|
|
|
- group_id: Number(context.group_id),
|
|
|
- file: 'data:file;base64,' + file,
|
|
|
- name: logName+'.log'
|
|
|
- })
|
|
|
-
|
|
|
- } else {
|
|
|
- await qqBot.upload_private_file({
|
|
|
- user_id: Number(context.sender.user_id),
|
|
|
- file: 'data:file;base64,' + file,
|
|
|
- name: logName+'.log'
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- return '上传成功';
|
|
|
- } catch (error) {
|
|
|
- botlogger.error('文件查找失败:', error);
|
|
|
- return '插件查找服务暂不可用';
|
|
|
- }
|
|
|
- }
|
|
|
}
|