koishi-plugin-wulijonc-help 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { Context, Schema } from 'koishi';
2
+ export declare const name = "wulijonc-help";
3
+ interface CommandEntry {
4
+ command: string;
5
+ description: string;
6
+ imagePath?: string;
7
+ imageUrl?: string;
8
+ message: string;
9
+ }
10
+ export interface Config {
11
+ commands: CommandEntry[];
12
+ }
13
+ export declare const Config: Schema<Config>;
14
+ export declare function apply(ctx: Context, config: Config): void;
15
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,90 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Config: () => Config,
24
+ apply: () => apply,
25
+ name: () => name
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+ var import_koishi = require("koishi");
29
+ var import_promises = require("fs/promises");
30
+ var import_path = require("path");
31
+ var name = "wulijonc-help";
32
+ var Config = import_koishi.Schema.object({
33
+ commands: import_koishi.Schema.array(import_koishi.Schema.object({
34
+ command: import_koishi.Schema.string().required().description("命令名称(用户在聊天中输入的触发词)"),
35
+ description: import_koishi.Schema.string().default("自定义回复").description("命令描述(显示在 help 列表中)"),
36
+ imageUrl: import_koishi.Schema.string().description('图片 URL(推荐,零内存开销。与下方"本地路径"二选一)'),
37
+ imagePath: import_koishi.Schema.path({
38
+ filters: [{
39
+ name: "图片文件",
40
+ extensions: [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp"]
41
+ }]
42
+ }).description("本地图片路径(大图会在每次发送时临时读取,不常驻内存)"),
43
+ message: import_koishi.Schema.string().default("").description("附带的文字消息(可留空)")
44
+ })).default([]).description("命令列表 —— 每条命令可发送不同的图片和/或文字")
45
+ });
46
+ function getMimeType(filePath) {
47
+ const ext = (0, import_path.extname)(filePath).toLowerCase();
48
+ const mimeMap = {
49
+ ".png": "image/png",
50
+ ".jpg": "image/jpeg",
51
+ ".jpeg": "image/jpeg",
52
+ ".gif": "image/gif",
53
+ ".webp": "image/webp",
54
+ ".bmp": "image/bmp",
55
+ ".svg": "image/svg+xml"
56
+ };
57
+ return mimeMap[ext] || "image/png";
58
+ }
59
+ __name(getMimeType, "getMimeType");
60
+ function apply(ctx, config) {
61
+ for (const entry of config.commands) {
62
+ if (!entry.command) continue;
63
+ ctx.command(entry.command, entry.description).action(async () => {
64
+ let result = "";
65
+ if (entry.message) {
66
+ result += entry.message;
67
+ }
68
+ if (entry.imageUrl) {
69
+ result += import_koishi.h.image(entry.imageUrl);
70
+ } else if (entry.imagePath) {
71
+ const absolutePath = (0, import_path.resolve)(entry.imagePath);
72
+ try {
73
+ const buffer = await (0, import_promises.readFile)(absolutePath);
74
+ const mime = getMimeType(absolutePath);
75
+ result += import_koishi.h.image(`data:${mime};base64,${buffer.toString("base64")}`);
76
+ } catch {
77
+ return `无法读取图片文件:${absolutePath}`;
78
+ }
79
+ }
80
+ return result || "该命令未配置任何内容";
81
+ });
82
+ }
83
+ }
84
+ __name(apply, "apply");
85
+ // Annotate the CommonJS export names for ESM import in node:
86
+ 0 && (module.exports = {
87
+ Config,
88
+ apply,
89
+ name
90
+ });
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "koishi-plugin-wulijonc-help",
3
+ "description": "一个自用的help插件",
4
+ "version": "0.0.1",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "dist"
10
+ ],
11
+ "license": "MIT",
12
+ "scripts": {},
13
+ "keywords": [
14
+ "chatbot",
15
+ "koishi",
16
+ "plugin"
17
+ ],
18
+ "devDependencies": {},
19
+ "peerDependencies": {
20
+ "koishi": "^4.18.7"
21
+ }
22
+ }
package/readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # koishi-plugin-wulijonc-help
2
+
3
+ [![npm](https://img.shields.io/npm/v/koishi-plugin-wulijonc-help?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-wulijonc-help)
4
+
5
+ 一个自用的help插件