UNPKG

koishi-plugin-vv

Version:
64 lines (63 loc) 2.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Config = exports.name = void 0; exports.apply = apply; const koishi_1 = require("koishi"); const axios_1 = __importDefault(require("axios")); exports.name = "vv"; exports.Config = koishi_1.Schema.object({ apiBaseUrl: koishi_1.Schema.string() .default("https://api.zvv.quest") .description("API地址"), defaultImageCount: koishi_1.Schema.number() .default(10) .min(1) .max(20) .description("默认图片数量"), timeout: koishi_1.Schema.number().default(10000).description("请求超时时间(毫秒)"), }); function apply(ctx, config) { ctx.command("vv <text> [n:number]", "搜索 VV 梗图") .example("vv 我喜欢你 5") .action(async ({ session }, text, n) => { if (!text || text.trim() === "") { return "请输入要搜索的文本"; } // 如果未指定n,则使用配置中的默认值 n = n || config.defaultImageCount; try { const response = await axios_1.default.get(`${config.apiBaseUrl}/search`, { params: { q: text, n: n, }, timeout: config.timeout, }); if (response.data.code === 200 && response.data.data?.length > 0) { const images = response.data.data; // 创建转发消息的元素数组 const messages = []; // 添加文字说明消息 const infoMessage = `关键词:${text}\n数量:${images.length}\nAPI:${config.apiBaseUrl}`; messages.push((0, koishi_1.h)("message", infoMessage)); // 添加图片消息 images.forEach((url) => { messages.push((0, koishi_1.h)("message", koishi_1.h.image(url))); }); // 返回转发消息 return (0, koishi_1.h)("message", { forward: true }, messages); } else { return `没有找到与"${text}"相关的梗图`; } } catch (error) { console.error("搜索VV梗图出错:", error); return `搜索出错: ${error.message || "未知错误"}`; } }); }