UNPKG

koishi-plugin-kbot

Version:
75 lines (74 loc) 3.09 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.apply = exports.Config = void 0; /* * @Author: Kabuda-czh * @Date: 2023-01-29 14:43:27 * @LastEditors: Kabuda-czh * @LastEditTime: 2023-07-24 12:00:16 * @FilePath: \KBot-App\plugins\kbot\src\plugins\bilibili\index.ts * @Description: * * Copyright (c) 2023 by Kabuda-czh, All Rights Reserved. */ const node_fs_1 = __importDefault(require("node:fs")); const koishi_1 = require("koishi"); const config_1 = __importDefault(require("../../config")); const dynamic = __importStar(require("./dynamic")); const url = __importStar(require("./url")); exports.Config = koishi_1.Schema.object({ dynamic: dynamic.Config.description('动态监听 (使用 dynamic 指令管理监听对象)'), url: koishi_1.Schema.boolean().default(true).description('是否启用 URL 自动解析'), quester: koishi_1.Quester.Config.description('Bilibili 请求配置'), }); async function apply(context, config) { context.guild().command('kbot/bilibili', 'Bilibili 相关功能'); context.model.extend('channel', { bilibili: { type: 'json', initial: {}, }, }); const { kbotDir, bilibiliDir } = config_1.default.getInstance(context.baseDir).getGeneratePathData(); const fileNames = await node_fs_1.default.promises.readdir(kbotDir); if (!fileNames.includes('bilibili')) await node_fs_1.default.promises.mkdir(bilibiliDir, { recursive: true }); const ctx = context.isolate(['http']); ctx.http = context.http.extend({ headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36', ...config.quester.headers, }, ...config.quester, }); ctx.plugin(dynamic, config.dynamic); if (config.url) ctx.plugin(url); } exports.apply = apply;