Skip to content

Commit

Permalink
optimize load Task
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Aug 28, 2024
1 parent bad3569 commit 0832e74
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 42 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.0.2
* 优化Task加载

# 2.0.1
* 规范版本号
* 调整渲染出图类型为webp格式,减小发送图片消息带宽压力
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
})
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yz-yuki-plugin",
"version": "2.0.1",
"version": "2.0.2",
"description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
"author": "snowtafir",
"type": "module",
Expand Down
22 changes: 4 additions & 18 deletions src/apps/bilibili.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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|哔哩|哔哩哔哩)任务$/]
)
Expand Down
21 changes: 4 additions & 17 deletions src/apps/weibo.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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)任务$/]
)
Expand Down
42 changes: 40 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 = []
Expand Down Expand Up @@ -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) {
// 存储
Expand Down
4 changes: 2 additions & 2 deletions src/models/version/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
}
}
Expand Down

0 comments on commit 0832e74

Please sign in to comment.