From ca62e5dab4a43275e506007d7158cc93a6b760fa Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Sun, 19 Feb 2023 18:05:33 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=84=20refactor:=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/daily.js | 20 ++++---------------- apps/tools.js | 13 +------------ utils/common.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ utils/constant.js | 23 +++++++++++++++++++++++ utils/f.js | 14 -------------- 5 files changed, 74 insertions(+), 42 deletions(-) create mode 100644 utils/common.js create mode 100644 utils/constant.js delete mode 100644 utils/f.js diff --git a/apps/daily.js b/apps/daily.js index 9727494..c13cebc 100644 --- a/apps/daily.js +++ b/apps/daily.js @@ -1,28 +1,16 @@ -import common from "../../../lib/common/common.js"; import fetch from "node-fetch"; -import schedule from "node-schedule"; import { Group, segment } from "oicq"; +import { autoTask } from "../utils/common.js" // 指定定时发送的群号 const groupList = ["169721415"]; // 是否开启定时推送,默认为 true -let isAutoPush = true; -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); - } - }); - } -} +let isAutoPush = false; // 定时任务合集 -autoTask(pushDailyWorld, "0 30 8 * * ?"); -autoTask(pushTouchFish, "0 31 8 * * ?"); +autoTask(pushDailyWorld, "0 30 8 * * ?", groupList, isAutoPush); +autoTask(pushTouchFish, "0 31 8 * * ?", groupList, isAutoPush); export class daily extends plugin { constructor(e) { diff --git a/apps/tools.js b/apps/tools.js index 763b0e0..125d0e4 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -12,20 +12,9 @@ import HttpProxyAgent from "https-proxy-agent"; import { mkdirsSync } from "../utils/file.js"; import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js"; import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js"; +import { transMap, douyinTypeMap } from "../utils/constant.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 { constructor() { diff --git a/utils/common.js b/utils/common.js new file mode 100644 index 0000000..657f012 --- /dev/null +++ b/utils/common.js @@ -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 }; diff --git a/utils/constant.js b/utils/constant.js new file mode 100644 index 0000000..412d163 --- /dev/null +++ b/utils/constant.js @@ -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", +}; \ No newline at end of file diff --git a/utils/f.js b/utils/f.js deleted file mode 100644 index 7489ed8..0000000 --- a/utils/f.js +++ /dev/null @@ -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();