UNPKG

koishi-plugin-royale

Version:
63 lines (62 loc) 2.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Config = exports.name = void 0; exports.apply = apply; const koishi_1 = require("koishi"); const playerinfo_1 = require("./player/playerinfo/playerinfo"); const claninfo_1 = require("./clan/claninfo/claninfo"); const response_1 = require("./utils/response"); const usage_1 = require("./usage"); exports.name = "royale"; exports.Config = koishi_1.Schema.object({ apiKey: koishi_1.Schema.string() .description("Clash Royale API密钥 (可从开发者官网 https://developer.clashroyale.com 申请)") .default("") .required(false), }); function apply(ctx, config) { // 检查API密钥是否设置 if (!config.apiKey || config.apiKey.trim() === "") { console.error("未设置API密钥,请在插件配置中设置 Clash Royale API密钥"); } const cmd = ctx.command("royale", "Clash Royale相关功能").usage(usage_1.usage); // 添加设置 API 密钥的子命令 cmd.subcommand(".setkey <key:string>", "设置API密钥") .option("admin", "-a 需要管理员权限", { authority: 3 }) .action(async ({ session, options }, key) => { if (!key || key.trim() === "") { return (0, response_1.formatResponse)((0, response_1.failure)("参数不足", "请提供有效的API密钥")); } // 更新配置 config.apiKey = key.trim(); return (0, response_1.formatResponse)((0, response_1.success)("配置成功", "API密钥已成功设置,此设置将在重启后失效")); }); cmd.subcommand(".playerinfo <tag>", "查询一些玩家个人信息") .example("/royale.playerinfo #CJ2L9PGLG") .action(async (_, tag) => { if (!tag || tag.trim() === "") { return (0, response_1.formatResponse)((0, response_1.failure)("参数不足", "请提供玩家标签")); } try { const result = await (0, playerinfo_1.playerinfo)(tag, config.apiKey); return result; // playerinfo 函数内部已经处理了标准响应格式 } catch (error) { return (0, response_1.formatResponse)((0, response_1.failure)("查询玩家信息失败", error.message)); } }); cmd.subcommand(".claninfo <tag>", "查询部落信息") .example("/royale.claninfo #2LUGUPJ") .action(async (_, tag) => { if (!tag || tag.trim() === "") { return (0, response_1.formatResponse)((0, response_1.failure)("参数不足", "请提供部落标签")); } try { const result = await (0, claninfo_1.claninfo)(tag, config.apiKey); return result; // claninfo 函数内部已经处理了标准响应格式 } catch (error) { return (0, response_1.formatResponse)((0, response_1.failure)("查询部落信息失败", error.message)); } }); }