UNPKG

koishi-plugin-lcp-locker

Version:

个人自用测试插件,点击头像查看本人所有插件

223 lines (220 loc) 10.2 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name2 in all) __defProp(target, name2, { get: all[name2], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { Config: () => Config, apply: () => apply, name: () => name, usage: () => usage }); module.exports = __toCommonJS(src_exports); var import_koishi = require("koishi"); var path = __toESM(require("path")); var fs = __toESM(require("fs/promises")); var name = "lcp-locker"; var usage = ` <div style="border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);"> <h2 style="margin-top: 0; color: #4a6ee0;">📌 插件说明</h2> <p>📖 <strong>使用文档</strong>:请点击左上角的 <strong>插件主页</strong> 查看插件使用文档</p> <p>🔍 <strong>更多插件</strong>:可访问 <a href="https://github.com/YisRime" style="color:#4a6ee0;text-decoration:none;">苡淞的 GitHub</a> 查看本人的所有插件</p> </div> <div style="border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);"> <h2 style="margin-top: 0; color: #e0574a;">❤️ 支持与反馈</h2> <p>🌟 喜欢这个插件?请在 <a href="https://github.com/YisRime" style="color:#e0574a;text-decoration:none;">GitHub</a> 上给我一个 Star!</p> <p>🐛 遇到问题?请通过 <strong>Issues</strong> 提交反馈,或加入 QQ 群 <a href="https://qm.qq.com/q/PdLMx9Jowq" style="color:#e0574a;text-decoration:none;"><strong>855571375</strong></a> 进行交流</p> </div> `; var THEME_MAP = { "orange": "活跃橙", "blue": "极客蓝", "pink": "铁杆粉", "lucky": "欧皇彩", "gold": "秋仪金", "all": "全部主题" }; var Config = import_koishi.Schema.object({ apiEndpoint: import_koishi.Schema.string().description("API Endpoint").required(), apiKey: import_koishi.Schema.string().description("API Key").required(), hidePrefix: import_koishi.Schema.boolean().description("禁用描述文本显示").default(false), enableLucky: import_koishi.Schema.boolean().description("启用欧皇彩解锁日期获取").default(true), enableBlue: import_koishi.Schema.boolean().description("启用极客蓝解锁码获取").default(true), enablePink: import_koishi.Schema.boolean().description("启用铁杆粉解锁键值获取").default(true), enableOrange: import_koishi.Schema.boolean().description("启用活跃橙解锁码获取").default(true), enableGold: import_koishi.Schema.boolean().description("启用秋仪金解锁码获取").default(true), enableAll: import_koishi.Schema.boolean().description("启用全部主题解锁键值获取").default(true), enableCryptography: import_koishi.Schema.boolean().description("启用内容加解密").default(true) }); function apply(ctx, config) { async function request(action, code, content) { try { const params = new URLSearchParams(); params.append("identify", config.apiKey); params.append("code", code); params.append("action", action); if (content) params.append("content", content); const url = `${config.apiEndpoint}?${params.toString()}`; const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } catch { return { result: "" }; } } __name(request, "request"); async function handleThemeCommand(session, themeKey) { if (!session?.userId) return ""; const code = await DataManager.getCode(ctx.baseDir, session.userId); if (!code) return ""; try { const response = await request(themeKey, code); if (!response?.result) return ""; if (config.hidePrefix) { let result2 = response.result; if (themeKey === "all" && config.enableGold && response.goldKey) { result2 += ` ${response.goldKey}`; } return result2; } let result = `${THEME_MAP[themeKey]}${themeKey === "lucky" ? "解锁日期" : themeKey === "pink" ? "解锁键值(SystemCount)" : themeKey === "all" ? "解锁键值(UiLauncherThemeHide2)" : "解锁码"}: ${response.result}`; if (themeKey === "all" && config.enableGold && response.goldKey) { result += ` 秋仪金解锁键值(UiLauncherThemeGold): ${response.goldKey}`; } return result; } catch { return ""; } } __name(handleThemeCommand, "handleThemeCommand"); const unlk = ctx.command("unlk", "主题解锁").usage("根据识别码生成对应解锁码或键值,解锁相应主题"); unlk.subcommand(".code <code>", "绑定识别码").usage(`输入识别码绑定`).example(`unlk.code ABCD-EFGH-IJKL-MNOP 绑定新的识别码`).action(async ({ session }, code) => { if (!session?.userId) return ""; if (!/^[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}$/i.test(code)) { return ``; } const formattedCode = code.toUpperCase(); await DataManager.addCode(ctx.baseDir, session.userId, formattedCode); return ``; }); [ { key: "lucky", enabled: config.enableLucky, desc: "获取欧皇彩解锁日期", usage: '在指定日期使用"今日人品"功能解锁欧皇彩主题' }, { key: "blue", enabled: config.enableBlue, desc: "获取极客蓝解锁码", usage: "使用解锁码解锁极客蓝主题" }, { key: "pink", enabled: config.enablePink, desc: "获取铁杆粉解锁键值", usage: "修改注册表对应键值解锁铁杆粉主题" }, { key: "orange", enabled: config.enableOrange, desc: "获取活跃橙解锁码", usage: "使用解锁码解锁活跃橙主题" }, { key: "gold", enabled: config.enableGold, desc: "获取秋仪金解锁码", usage: "使用解锁码解锁秋仪金主题" }, { key: "all", enabled: config.enableAll, desc: "获取全部主题解锁键值", usage: "修改注册表对应键值解锁全部主题" } ].filter((theme) => theme.enabled).forEach((theme) => { unlk.subcommand(`.${theme.key}`, theme.desc).usage(theme.usage).action(async ({ session }) => handleThemeCommand(session, theme.key)); }); if (config.enableCryptography) { async function handleCryptography(session, text, action) { if (!session?.userId || !text) return ""; const code = await DataManager.getCode(ctx.baseDir, session.userId); if (!code) return ""; try { const response = await request(action, code, text); return response?.result ? `${action === "encrypt" ? "加密" : "解密"}结果: ${response.result}` : ""; } catch { return ""; } } __name(handleCryptography, "handleCryptography"); unlk.subcommand(".enpt <text>", "加密自定义内容").usage("使用与主题相同的加密逻辑加密自定义内容").action(async ({ session }, text) => handleCryptography(session, text, "encrypt")); unlk.subcommand(".dept <text>", "解密自定义内容").usage("使用与主题相同的解密逻辑解密自定义内容").action(async ({ session }, text) => handleCryptography(session, text, "decrypt")); } } __name(apply, "apply"); var DataManager = class { static { __name(this, "DataManager"); } /** * 从文件中加载用户数据 * @param dataDir - 数据目录路径 * @returns 用户数据对象 */ static async loadData(dataDir) { try { const content = await fs.readFile(path.join(dataDir, "data", "lcp-locker.json"), "utf-8"); return JSON.parse(content); } catch { return {}; } } /** * 保存用户数据到文件 * @param dataDir - 数据目录路径 * @param data - 用户数据对象 */ static async saveData(dataDir, data) { try { const dataPath = path.join(dataDir, "data"); await fs.writeFile(path.join(dataPath, "lcp-locker.json"), JSON.stringify(data, null, 2), "utf-8"); } catch { return; } } /** * 添加或更新用户的识别码 * @param dataDir - 数据目录路径 * @param userId - 用户ID * @param code - 识别码 */ static async addCode(dataDir, userId, code) { const data = await this.loadData(dataDir); if (!data[userId]) data[userId] = { current: null, codes: [] }; if (!data[userId].codes.includes(code)) data[userId].codes.push(code); data[userId].current = code; await this.saveData(dataDir, data); } /** * 获取用户当前绑定的识别码 * @param dataDir - 数据目录路径 * @param userId - 用户ID * @returns 用户当前的识别码,不存在则返回null */ static async getCode(dataDir, userId) { const data = await this.loadData(dataDir); return data[userId]?.current || null; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Config, apply, name, usage });