🦄 refactor: 重构部分代码

This commit is contained in:
zhiyu1998 2023-02-19 18:05:33 +08:00
parent 1775a773dd
commit ca62e5dab4
5 changed files with 74 additions and 42 deletions

View File

@ -1,28 +1,16 @@
import common from "../../../lib/common/common.js";
import fetch from "node-fetch"; import fetch from "node-fetch";
import schedule from "node-schedule";
import { Group, segment } from "oicq"; import { Group, segment } from "oicq";
import { autoTask } from "../utils/common.js"
// 指定定时发送的群号 // 指定定时发送的群号
const groupList = ["169721415"]; const groupList = ["169721415"];
// 是否开启定时推送,默认为 true // 是否开启定时推送,默认为 true
let isAutoPush = true; let isAutoPush = false;
function autoTask(func, time) {
if (isAutoPush) {
schedule.scheduleJob(time, () => {
for (let i = 0; i < groupList.length; i++) {
let group = Bot.pickGroup(groupList[i]);
func(group);
common.sleep(1000);
}
});
}
}
// 定时任务合集 // 定时任务合集
autoTask(pushDailyWorld, "0 30 8 * * ?"); autoTask(pushDailyWorld, "0 30 8 * * ?", groupList, isAutoPush);
autoTask(pushTouchFish, "0 31 8 * * ?"); autoTask(pushTouchFish, "0 31 8 * * ?", groupList, isAutoPush);
export class daily extends plugin { export class daily extends plugin {
constructor(e) { constructor(e) {

View File

@ -12,20 +12,9 @@ import HttpProxyAgent from "https-proxy-agent";
import { mkdirsSync } from "../utils/file.js"; import { mkdirsSync } from "../utils/file.js";
import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js"; import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js";
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js"; import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
import { transMap, douyinTypeMap } from "../utils/constant.js"
import config from "../model/index.js"; import config from "../model/index.js";
const transMap = { : "zh", : "jp", : "wyw", : "en" };
const douyinTypeMap = {
2: "image",
4: "video",
68: "image",
0: "video",
51: "video",
55: "video",
58: "video",
61: "video",
150: "image",
};
export class tools extends plugin { export class tools extends plugin {
constructor() { constructor() {

46
utils/common.js Normal file
View File

@ -0,0 +1,46 @@
import schedule from "node-schedule";
import common from "../../../lib/common/common.js";
/**
* 请求模板
*/
class jFeatch {
async get(url) {
const r = await fetch(url);
return await r.json();
}
async post(url, params) {
const r = await fetch(url, { ...params, method: "POST" });
return await r.json();
}
}
/**
* 每日推送函数
* @param func 回调函数
* @param time cron
* @param isAutoPush 是否推送开关
*/
function autoTask(func, time, groupList, isAutoPush = false) {
if (isAutoPush) {
schedule.scheduleJob(time, () => {
// 正常传输
if (groupList instanceof Array) {
for (let i = 0; i < groupList.length; i++) {
const group = Bot.pickGroup(groupList[i]);
func(group);
common.sleep(1000);
}
// 防止恶意破坏函数
} else if (groupList instanceof String) {
const group = Bot.pickGroup(groupList[i]);
func(group);
common.sleep(1000);
} else {
throw Error("错误传入每日推送参数!");
}
});
}
}
export { jFeatch, autoTask };

23
utils/constant.js Normal file
View File

@ -0,0 +1,23 @@
/**
* 用于翻译的常量控制
*
* @type {{: string, : string, : string, : string}}
*/
export const transMap = { : "zh", : "jp", : "wyw", : "en" };
/**
* 以下为抖音/TikTok类型代码
*
* @type {{"0": string, "55": string, "2": string, "68": string, "58": string, "4": string, "61": string, "51": string, "150": string}}
*/
export const douyinTypeMap = {
2: "image",
4: "video",
68: "image",
0: "video",
51: "video",
55: "video",
58: "video",
61: "video",
150: "image",
};

View File

@ -1,14 +0,0 @@
//import xx from f.js
class jFeatch {
async get(url) {
const r = await fetch(url);
return await r.json();
}
async post(url, params) {
const r = await fetch(url, { ...params, method: "POST" });
return await r.json();
}
}
export default new jFeatch();