UNPKG

koishi-plugin-njcard

Version:

Koishi插件,提供单抽和十连抽卡功能

66 lines (65 loc) 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Config = exports.usage = exports.name = void 0; exports.apply = apply; const koishi_1 = require("koishi"); // 插件配置项 exports.name = 'njcard'; exports.usage = '提供单抽和十连抽卡功能'; exports.Config = koishi_1.Schema.object({}); // 基础URL const BASE_URL = 'http://182.160.1.20:81'; const SINGLE_DRAW_URL = `${BASE_URL}/index.php?count=1&format=text`; const MULTI_DRAW_URL = `${BASE_URL}/index.php?count=10&format=text`; // 处理图片链接,添加http:前缀 function processImageUrl(url) { if (url.startsWith('//')) { return `http:${url.trim()}`; } return url.trim(); } // 插件主函数 function apply(ctx) { // 注册单抽指令 ctx.command('单抽', '抽取一张卡片') .action(async ({ session }) => { try { // 发送"抽卡中..."消息 await session.send('抽卡中...'); // 获取单抽结果 const data = await ctx.http.get(SINGLE_DRAW_URL, { responseType: 'text' }); const imageUrl = processImageUrl(data); // 发送图片 return koishi_1.h.image(imageUrl); } catch (error) { console.error('单抽请求出错:', error); return '抽卡失败,请稍后再试'; } }); // 注册十连指令 ctx.command('十连', '抽取十张卡片') .action(async ({ session }) => { try { // 发送"抽卡中..."消息 await session.send('抽卡中...'); // 获取十连结果 const data = await ctx.http.get(MULTI_DRAW_URL, { responseType: 'text' }); const imageUrls = data.split('\n') .filter(url => url.trim()) .map(processImageUrl); // 如果没有获取到图片链接,返回错误信息 if (!imageUrls.length) { return '抽卡失败,未获取到图片'; } // 创建图片元素数组 const images = imageUrls.map(url => koishi_1.h.image(url)); // 发送所有图片 return (0, koishi_1.h)('message', images); } catch (error) { console.error('十连请求出错:', error); return '抽卡失败,请稍后再试'; } }); }