Ver Fonte

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/lib/Plugins.ts
Sakulin há 3 meses atrás
pai
commit
a0a2d377a5
4 ficheiros alterados com 68 adições e 68 exclusões
  1. 3 3
      src/config/load.yml
  2. 1 1
      src/lib/Permission.ts
  3. 2 4
      src/lib/Plugins.ts
  4. 62 60
      src/plugins/sakulin.ts

+ 3 - 3
src/config/load.yml

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

+ 1 - 1
src/lib/Permission.ts

@@ -1,6 +1,6 @@
 import { PermissionConfig, saveConfig } from "./config.js";
 import botlogger from "./logger.js";
-
+export const IsAdmin = function (id:number){return  PermissionConfig.admins.some((admin: string) => admin === String(id)) }
 export async function IsPermission(id: number, plugin: string, command: string): Promise<boolean> {
     try {
         // 检查用户是否在白名单中

+ 2 - 4
src/lib/Plugins.ts

@@ -262,11 +262,9 @@ export async function runplugins() {
                             }
 
                             botlogger.info("开始安装插件: " + pluginName);
-
+                            const __dirname = path.dirname(fileURLToPath(import.meta.url));
                             // @ts-ignore
-                            fs.writeFile(`../plugins/${pluginName}`, msg, "utf8", (e) => {
-                                botlogger.error("插件安装失败: " + JSON.stringify(e));
-                            });
+                            fs.writeFileSync(path.join(__dirname, "..", "plugins", pluginName), msg, "utf8");
 
                             context.quick_action([{
                                 type: 'text',

+ 62 - 60
src/plugins/sakulin.ts

@@ -1,61 +1,63 @@
-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",
-    version: "1.0.0",
-    describe: "This is a plugin by Sakulin",
-    author: "活性红磷",
-    help: {
-        enabled: true,
-        description: "显示帮助信息"
-    }
-})
-export class sakulass {
-    @runcod(["ping", "test"], "测试接口")
-    async test() {
-        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)}`;
-        }
-    }
+//PLUGIN sakulin.ts
+
+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",
+    version: "1.0.0",
+    describe: "This is a plugin by Sakulin",
+    author: "活性红磷",
+    help: {
+        enabled: true,
+        description: "显示帮助信息"
+    }
+})
+export class sakulass {
+    @runcod(["ping", "test"], "测试接口")
+    async test() {
+        await (new Promise((resolve) => {
+            setTimeout(resolve, 5000);
+        }));
+        return "pong";
+    }
+
+    @runcod(["图", "tu"], "看看图,可添加不同图源作为参数,例如发送 “#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)}`;
+        }
+    }
 }