Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki committed Mar 16, 2022
1 parent b6e0ff8 commit 339148a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kokkoro-plugin-bilibili",
"version": "0.0.1",
"version": "0.0.2",
"description": "哔哩哔哩 (゜-゜)つロ 干杯~-bilibili",
"main": "./lib/index.js",
"scripts": {
Expand Down
28 changes: 16 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { writeFile, readFile } from 'fs/promises';
import { Job, scheduleJob } from 'node-schedule';
import { Extension, Bot, deepMerge, deepClone, section } from 'kokkoro';

import { addMid, bilibili_path, getDynamicInfo, getNickname } from './service';
import { addMid, bilibili_path, cancelUpdateSchedule, getDynamicInfo, getNickname } from './service';

// Map<mid, dynamic_id>
const dynamicInfo: Map<number, number> = new Map();
Expand Down Expand Up @@ -59,6 +59,7 @@ export default class Bilibili implements Extension {
// 销毁定时任务
cancelSendSchedule() {
this.send_job.cancel();
cancelUpdateSchedule();
}

onInit() {
Expand All @@ -77,10 +78,20 @@ export default class Bilibili implements Extension {

async initBili() {
const gl = this.bot.getGroupList();
const mids = [
353840826, // 公主连结ReDive
1731293061, // PCR公主连结日服情报站
];

try {
const config_data = await readFile(this.path, 'utf8');
this.dynamic_config = parse(config_data);
} catch (error) {
const mids = [
353840826, // 公主连结ReDive
1731293061, // PCR公主连结日服情报站
];

this.dynamic_config = { mids };
}

const mids = this.dynamic_config.mids;
const mids_length = mids.length;
const default_config: DynamicConfig = { mids };
const mid_list: MidList = {};
Expand All @@ -99,13 +110,6 @@ export default class Bilibili implements Extension {
default_config[group_id] = { group_name, mid_list: deepClone(mid_list) };
}

try {
const config_data = await readFile(this.path, 'utf8');
this.dynamic_config = parse(config_data);
} catch (error) {
this.dynamic_config = { mids };
}

this.dynamic_config = deepMerge(default_config, this.dynamic_config);

for (const mid of this.dynamic_config.mids) {
Expand Down
2 changes: 1 addition & 1 deletion src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const update_job: Job = scheduleJob('0 0/5 * * * ?', async () => {
});

// 销毁更新任务
function cancelUpdateSchedule() {
export function cancelUpdateSchedule() {
update_job.cancel();
}

Expand Down

0 comments on commit 339148a

Please sign in to comment.