mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
🦄 refactor: 重构部分代码
This commit is contained in:
parent
1775a773dd
commit
ca62e5dab4
@ -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) {
|
||||
|
@ -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() {
|
||||
|
46
utils/common.js
Normal file
46
utils/common.js
Normal 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
23
utils/constant.js
Normal 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",
|
||||
};
|
14
utils/f.js
14
utils/f.js
@ -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();
|
Loading…
x
Reference in New Issue
Block a user