瀏覽代碼

Merge branch 'master' of https://github.com/liuqianpan2008/FengbotQQ

Sakulin 3 月之前
父節點
當前提交
a9cbdbf80e
共有 6 個文件被更改,包括 103 次插入7 次删除
  1. 4 0
      src/config/load.yml
  2. 1 0
      src/config/permission.yml
  3. 31 3
      src/lib/Bot.ts
  4. 24 2
      src/lib/Plugins.ts
  5. 1 0
      src/lib/config.ts
  6. 42 2
      src/plugins/sakulin.ts

+ 4 - 0
src/config/load.yml

@@ -0,0 +1,4 @@
+isuplad: false
+name: reload.ts
+id: 211249983
+isGroupMessage: true

+ 1 - 0
src/config/permission.yml

@@ -25,6 +25,7 @@ users:
         commands:
           ping: true
           help: true
+          图: true
   default:
     plugins:
       test:

+ 31 - 3
src/lib/Bot.ts

@@ -1,5 +1,5 @@
 import { NCWebsocket } from 'node-napcat-ts'
-import {Botconfig as config} from './config.js'
+import {Botconfig as config, load, saveConfig} from './config.js'
 import { runplugins } from './Plugins.js';
 
 export class Bot extends NCWebsocket{
@@ -17,11 +17,39 @@ export class Bot extends NCWebsocket{
             }
         });
     }
-
+    async reload(){
+        let isload = await load
+        if(isload.isuplad){
+         isload.isuplad=false;
+         if (isload.isGroupMessage) {
+            this.send_group_msg({
+             group_id: Number(isload.id),
+             message:[{
+                 type:"text",
+                 data:{
+                     text:  `加载插件 ${isload.name} 成功`
+                 }
+             }]
+            }) 
+         }else{
+             this.send_private_msg({
+                 user_id:Number(isload.id),
+                 message:[{
+                     type:"text",
+                     data:{
+                         text:`加载插件 ${isload.name} 成功`
+                     }
+                 }]
+             })
+         }
+         saveConfig("load", isload)
+        }
+    }
     async run(){
         try {
            await this.connect()
-           runplugins()
+           await runplugins()
+           await this.reload()
            console.log('启动成功!')
         } catch (error) {
             console.error(error)

+ 24 - 2
src/lib/Plugins.ts

@@ -1,3 +1,4 @@
+
 import botlogger from "./logger.js";
 import {promises as fsPromises} from 'fs';
 import {HtmlImg} from "./Puppeteer.js";
@@ -18,7 +19,7 @@ import {
 import * as fs from 'fs'
 import * as path from 'path'
 // 获取指令前缀
-import {Botconfig as config, PermissionConfig} from './config.js'
+import {Botconfig as config, load, PermissionConfig, saveConfig} from './config.js'
 import {ImageSegment, ReplySegment, TextSegment} from "node-napcat-ts/dist/Structs.js";
 import {fileURLToPath} from 'node:url';
 import {qqBot} from "../app.js";
@@ -85,6 +86,7 @@ function findCommand(plugin: Plugin, cmdName: string): Command | undefined {
 }
 
 
+
 // 添加插件加载函数
 async function loadPlugins(): Promise<void> {
     try {
@@ -182,6 +184,7 @@ async function initializeScheduledTasks(instance: any): Promise<void> {
 }
 
 
+
 // 修改 runplugins 函数
 export async function runplugins() {
     try {
@@ -224,6 +227,16 @@ export async function runplugins() {
                             type: 'text',
                             data: {text: `插件下载完成,开始重载`}
                         }]);
+                        let isload = load
+                            isload.isuplad=true;
+                            isload.name=file.file
+                            if((context.message_type === 'group')){
+                                isload.id = context.group_id
+                            }else{
+                                isload.id = context.sender.user_id
+                            }
+                            isload.isGroupMessage = (context.message_type === 'group');
+                            saveConfig("load", isload)
                     }
                     return;
                 }
@@ -250,7 +263,16 @@ export async function runplugins() {
                                 type: 'text',
                                 data: {text: `插件下载完成,开始重载`}
                             }]);
-                            return;
+                            let isload = load
+                            isload.isuplad=true;
+                            isload.name=pluginName
+                            if((context.message_type === 'group')){
+                                isload.id = context.group_id
+                            }else{
+                                isload.id = context.sender.user_id
+                            }
+                            isload.isGroupMessage = (context.message_type === 'group');
+                            saveConfig("load", isload)
                         }
                     }
                 }

+ 1 - 0
src/lib/config.ts

@@ -15,3 +15,4 @@ export function saveConfig(file: string, data: any): void {
 }
 export const Botconfig = await loadConfig('bot');
 export const PermissionConfig = await loadConfig('permission');
+export const load = await loadConfig('load')

+ 42 - 2
src/plugins/sakulin.ts

@@ -1,6 +1,21 @@
-import { plugins, runcod } from '../lib/decorators.js';
+import {param, ParamType, plugins, runcod} from '../lib/decorators.js';
 import 'reflect-metadata';
 
+
+const imgSourceMap: { [key: string]: string } = {
+    "二次元": "https://app.zichen.zone/api/acg/api.php",
+    "原神": "https://t.alcy.cc/ysz",
+    "三次元": "https://api.lolimi.cn/API/tup/xjj.php",
+    "碧蓝档案": "https://image.anosu.top/pixiv/direct?r18=0&keyword=bluearchive",
+    "碧蓝航线": "https://image.anosu.top/pixiv/direct?r18=0&keyword=azurlane",
+    "明日方舟": "https://image.anosu.top/pixiv/direct?r18=0&keyword=arknights",
+    "公主连接": "https://image.anosu.top/pixiv/direct?r18=0&keyword=princess",
+    "东方": "https://image.anosu.top/pixiv/direct?r18=0&keyword=touhou"
+};
+
+const defaultSource = "二次元";
+
+
 @plugins({
     id: "saku",
     name: "Sakulin Helper",
@@ -15,7 +30,32 @@ import 'reflect-metadata';
 export class sakulass {
     @runcod(["ping", "test"], "测试接口")
     async test() {
-        await ((ms) => new Promise((resolve) => {setTimeout(resolve, ms);}))(500);
+        await (new Promise((resolve) => {
+            setTimeout(resolve, 5000);
+        }));
         return "pong";
     }
+
+    @runcod(["图"], "看看图,可添加不同图源作为参数,例如 “#saku 图 原神” ,可选的图源有:" + Object.keys(imgSourceMap).map(e => ((e == defaultSource) ? (e + "(默认)") : e)).join("、"))
+    async image(
+        @param("图源", ParamType.String) type: string,
+    ) {
+
+        const source = imgSourceMap[type] ?? imgSourceMap[defaultSource];
+
+        try {
+            const response = await fetch(source);
+            const blob = await response.blob();
+
+            return {
+                picture: {
+                    enabled: true,
+                    supplement: "测试图片",
+                    base64: Buffer.from(await blob.arrayBuffer()).toString("base64")
+                }
+            }
+        } catch (e) {
+            return `获取时发生错误:${JSON.stringify(e)}`;
+        }
+    }
 }