diff --git a/CHANGELOG.md b/CHANGELOG.md index 79ba50e..4648c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.2 +* 优化Task加载 + # 2.0.1 * 规范版本号 * 调整渲染出图类型为webp格式,减小发送图片消息带宽压力 diff --git a/README.md b/README.md index 0b8a3f0..c70892b 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,12 @@ >``` 接着修改 `yunzaijs/yunzai.config.js`,按版本选择修改方式: -Yunzai-Next v4.1.28+及以上版本: +Yunzai-Next v4.1.33+及以上版本: ```js import { defineConfig } from 'yunzai' export default defineConfig({ applications: ['yz-system', 'yz-yuki-plugin'], //该行添加 'yz-yuki-plugin' - middlewares: ['yz-mw-runtime', 'yunzai-mys/mw'] + middlewares: ['yunzai-mys/runtime', 'yunzai-mys/message'] }) ``` diff --git a/package.json b/package.json index 587e876..710c992 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yz-yuki-plugin", - "version": "2.0.1", + "version": "2.0.2", "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件", "author": "snowtafir", "type": "module", diff --git a/src/apps/bilibili.ts b/src/apps/bilibili.ts index a9353b9..fcbf974 100644 --- a/src/apps/bilibili.ts +++ b/src/apps/bilibili.ts @@ -1,6 +1,6 @@ import JSON from 'json5'; import lodash from 'lodash'; -import { Bot, Messages, Redis, setBotTask, EventType } from 'yunzai'; +import { Bot, Messages, Redis, EventType } from 'yunzai'; import { BiliQuery } from '@/models/bilibili/bilibili.query'; import { BiliTask } from '@/models/bilibili/bilibili.task'; import Config from '@/utils/config'; @@ -24,31 +24,17 @@ declare const logger: any; const message = new Messages('message'); -let biliConfigData = Config.getConfigData("config", "bilibili", "config"); let biliPushData = Config.getConfigData("config", "bilibili", "push"); - -/** B站动态推送定时任务 */ -setBotTask(async (Bot) => { - try { - newPushTask(); - if (biliConfigData.pushTaskLog) { - Bot.logger.mark("yuki插件---B站动态推送定时任务"); - } - } catch (err) { - console.error('B站动态推送定时任务', err); - } -}, biliConfigData.pushStatus ? biliConfigData.pushTime : "") - /** 推送任务 函数 */ -async function newPushTask(e?: EventType) { +async function biliNewPushTask(e?: EventType) { await new BiliTask(e).runTask(); } - +/**B站动态推送 */ message.use( async e => { - await newPushTask(e) + await biliNewPushTask(e) }, [/^(#|\/)(yuki|优纪)?执行(b站|B站|bili|bilibili|哔哩|哔哩哔哩)任务$/] ) diff --git a/src/apps/weibo.ts b/src/apps/weibo.ts index 58ddfe5..3920b2c 100644 --- a/src/apps/weibo.ts +++ b/src/apps/weibo.ts @@ -1,4 +1,4 @@ -import { Messages, setBotTask, EventType } from 'yunzai'; +import { Messages, EventType } from 'yunzai'; import { WeiboQuery } from '@/models/weibo/weibo.query'; import { WeiboTask } from '@/models/weibo/weibo.task'; import Config from '@/utils/config'; @@ -9,30 +9,17 @@ declare const logger: any; const message = new Messages('message') -let weiboConfigData = Config.getConfigData("config", "weibo", "config"); let weiboPushData = Config.getConfigData("config", "weibo", "push"); -/** 微博动态推送定时任务 */ -setBotTask(async (Bot) => { - try { - await newPushTask(); - if (weiboConfigData.pushTaskLog) { - Bot.logger.mark("yuki插件---微博动态推送定时任务"); - } - } catch (err) { - console.error('微博动态推送定时任务', err); - } -}, weiboConfigData.pushStatus ? weiboConfigData.pushTime : ""); - /** 定义 动态任务 函数 */ -async function newPushTask(e?: EventType) { +async function weiboNewPushTask(e?: EventType) { await new WeiboTask(e).runTask(); } - +/**微博动态推送 */ message.use( async e => { - await newPushTask(e) + await weiboNewPushTask(e) }, [/^(#|\/)(yuki|优纪)?执行(微博|weibo|WEIBO)任务$/] ) diff --git a/src/index.ts b/src/index.ts index 184ab23..4d7c325 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,28 @@ import chalk from 'chalk'; -import { Application, applicationOptions, useEvent } from 'yunzai' +import { Application, applicationOptions, EventType, setBotTask, useEvent } from 'yunzai' import Config from '@/utils/config'; -import * as apps from '@/apps/index' +import * as apps from '@/apps/index'; +import { BiliTask } from '@/models/bilibili/bilibili.task'; +import { WeiboTask } from '@/models/weibo/weibo.task'; declare const logger: any; type RulesType = { reg: RegExp | string key: string }[] +let biliConfigData = Config.getConfigData("config", "bilibili", "config"); +let weiboConfigData = Config.getConfigData("config", "weibo", "config"); + +/** B站动态任务 函数 */ +async function biliNewPushTask(e?: EventType) { + await new BiliTask(e).runTask(); +} + +/** 微博动态任务 函数 */ +async function weiboNewPushTask(e?: EventType) { + await new WeiboTask(e).runTask(); +} + export default () => { // 预先存储 const rules: RulesType = [] @@ -35,6 +50,29 @@ export default () => { logger.info(chalk.rgb(0, 190, 255)(`-----------------------------------------`)); logger.info(chalk.rgb(0, 190, 255)(`★ 优纪插件加载完成了喵~`)); + /** B站动态推送定时任务 */ + setBotTask(async (Bot) => { + try { + biliNewPushTask(); + if (biliConfigData.pushTaskLog) { + Bot.logger.mark("yuki插件---B站动态推送定时任务"); + } + } catch (err) { + console.error('B站动态推送定时任务', err); + } + }, biliConfigData.pushStatus ? biliConfigData.pushTime : "") + + /** 微博动态推送定时任务 */ + setBotTask(async (Bot) => { + try { + await weiboNewPushTask(); + if (weiboConfigData.pushTaskLog) { + Bot.logger.mark("yuki插件---微博动态推送定时任务"); + } + } catch (err) { + console.error('微博动态推送定时任务', err); + } + }, weiboConfigData.pushStatus ? weiboConfigData.pushTime : ""); }, async mounted(e) { // 存储 diff --git a/src/models/version/version.ts b/src/models/version/version.ts index ccdc5ce..7006c2b 100644 --- a/src/models/version/version.ts +++ b/src/models/version/version.ts @@ -56,7 +56,7 @@ export default class VersionData { }); } - // 对版本进行排序并截取最新的5个版本 + // 对版本进行排序并截取最新的10个版本 result.sort((a, b) => { let aParts = a.version.split('.').map(Number); let bParts = b.version.split('.').map(Number); @@ -70,7 +70,7 @@ export default class VersionData { return 0; }); - this.cache[key] = result.slice(0, 5); + this.cache[key] = result.slice(0, 10); return this.cache[key]; } }