diff --git a/CHANGELOG.md b/CHANGELOG.md index 35da24a..a64340d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.0.5 +* 新增了一个体力模板 +* 设置功能新增模板切换`图鉴设置模板(0-2)` +* 新版清新的模板背景路径**/plugins/xiaoyao-cvs-plugin/resources/dailyNote/icon/bg/** + * 模板背景可以自定义具体看内容 + */ + # 1.0.4 * 新增了`版本号` * 新增`图鉴目录`可以输入图鉴目录查看图鉴大概操作 diff --git a/apps/Note.js b/apps/Note.js index b20412d..c686cfd 100644 --- a/apps/Note.js +++ b/apps/Note.js @@ -8,9 +8,11 @@ import format from "date-format"; import puppeteer from "puppeteer"; import common from "../../../lib/common.js"; import lodash from "lodash"; +import Data from "../components/Data.js" import { Cfg } from "../components/index.js"; +import moment from 'moment'; // import MysApi from "../components/MysApi.js" import { @@ -19,6 +21,10 @@ import { } from "../../../lib/app/mysApi.js"; const _path = process.cwd(); +let role_user = Data.readJSON(`${_path}/plugins/xiaoyao-cvs-plugin/resources/dailyNote/json/`, "dispatch_time"); + +let path_url = ["dailyNote", "xiaoyao_Note"]; +let path_img = ["background_image", "/icon/bg"]; //#体力 export async function Note(e, { @@ -87,7 +93,6 @@ export async function Note(e, { } let data = res.data; - //推送任务 if (e.isTask && data.current_resin < e.sendResin) { return; @@ -99,23 +104,43 @@ export async function Note(e, { let nowDay = format("dd", new Date()); let resinMaxTime; + let resinMaxTime_mb2; + let resinMaxTime_mb2Day; if (data.resin_recovery_time > 0) { resinMaxTime = new Date().getTime() + data.resin_recovery_time * 1000; let maxDate = new Date(resinMaxTime); resinMaxTime = format("hh:mm", maxDate); - + let Time_day = await dateTime_(maxDate) + resinMaxTime_mb2 = Time_day + moment(maxDate).format("hh:mm"); + // console.log(format("dd", maxDate)) if (format("dd", maxDate) != nowDay) { + resinMaxTime_mb2Day = `明天`; resinMaxTime = `明天 ${resinMaxTime}`; } else { + resinMaxTime_mb2Day = `今天`; resinMaxTime = ` ${resinMaxTime}`; } } + // console.log(data.expeditions) for (let val of data.expeditions) { - // console.log(val.remained_time) if (val.remained_time > 0) { + // console.log(val.remained_time) + val.dq_time = val.remained_time; val.remained_time = new Date().getTime() + val.remained_time * 1000; + // console.log(val.remained_time) + var urls_avatar_side = val.avatar_side_icon.split("_"); + let id = YunzaiApps.mysInfo.roleIdToName(urls_avatar_side[urls_avatar_side.length - 1].replace( + /(.png|.jpg)/g, "")); + let name = YunzaiApps.mysInfo.roleIdToName(id, true); + var time_cha = 20; + if (role_user["12"].includes(name)) { + time_cha = 12; + } + val.percentage = ((val.dq_time / 60 / 60 * 1 / time_cha) * 100 / 10).toFixed(0) * 10; let remainedDate = new Date(val.remained_time); val.remained_time = format("hh:mm", remainedDate); + let Time_day = await dateTime_(remainedDate) + val.remained_mb2 = Time_day + moment(remainedDate).format("hh:mm" ); if (format("dd", remainedDate) != nowDay) { val.remained_time = `明天 ${val.remained_time}`; } else { @@ -139,18 +164,27 @@ export async function Note(e, { } } + let coinTime_mb2 = ""; + let coinTime_mb2Day = ""; let coinTime = ""; + var chnNumChar = ["零", "一", "后", "三", "四", "五", "六", "七", "八", "九"]; if (data.home_coin_recovery_time > 0) { + let coinDate = new Date(new Date().getTime() + data.home_coin_recovery_time * 1000); let coinDay = Math.floor(data.home_coin_recovery_time / 3600 / 24); let coinHour = Math.floor((data.home_coin_recovery_time / 3600) % 24); let coinMin = Math.floor((data.home_coin_recovery_time / 60) % 60); if (coinDay > 0) { coinTime = `${coinDay}天${coinHour}小时${coinMin}分钟`; + coinTime_mb2Day = chnNumChar[coinDay * 1] + "天"; + let Time_day = await dateTime_(coinDate) + coinTime_mb2 = Time_day + moment(coinDate).format("hh:mm"); } else { - let coinDate = new Date(new Date().getTime() + data.home_coin_recovery_time * 1000); + coinTime_mb2 = moment(coinDate).format("hh:mm"); if (format("dd", coinDate) != nowDay) { + coinTime_mb2Day = "明天"; coinTime = `明天 ${format("hh:mm", coinDate)}`; } else { + coinTime_mb2Day = "今天"; coinTime = format("hh:mm", coinDate); } } @@ -159,12 +193,11 @@ export async function Note(e, { let day = format("MM-dd hh:mm", new Date()); let week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; day += " " + week[new Date().getDay()]; - + let day_mb2 = format("yyyy年MM月dd日 hh:mm", new Date()) + " " + week[new Date().getDay()]; //参量质变仪 if (data?.transformer?.obtained) { data.transformer.reached = data.transformer.recovery_time.reached; let recovery_time = ""; - if (data.transformer.recovery_time.Day > 0) { recovery_time += `${data.transformer.recovery_time.Day}天`; } @@ -176,19 +209,28 @@ export async function Note(e, { } data.transformer.recovery_time = recovery_time; } - var image = fs.readdirSync(`./plugins/xiaoyao-cvs-plugin/resources/dailyNote/background_image`); + let mb=Cfg.get("mb.len", 0)-1; + if(mb<0){ + mb=lodash.random(0,path_url.length-1); + } + var image = fs.readdirSync(`./plugins/xiaoyao-cvs-plugin/resources/dailyNote/${path_img[mb]}`); var list_img = []; for (let val of image) { list_img.push(val) } var imgs = list_img.length == 1 ? list_img[0] : list_img[lodash.random(0, list_img.length - 1)]; - return await Common.render("dailyNote/dailyNote", { + return await Common.render(`dailyNote/${path_url[mb]}`, { save_id: uid, uid: uid, + coinTime_mb2Day, + coinTime_mb2, + resinMaxTime_mb2Day, resinMaxTime, + resinMaxTime_mb2, remained_time, coinTime, imgs, + day_mb2, day, ...data, }, { @@ -199,6 +241,10 @@ export async function Note(e, { return true; } +async function dateTime_(time) { + return format("hh", time) < 6 ? "凌晨" : format("hh", time) < 12 ? "上午" : format("hh", + time) < 16 ? "下午" : "傍晚"; +} async function getDailyNote(uid, cookie) { let { @@ -221,3 +267,52 @@ export async function saveJson() { let path = "data/NoteCookie/NoteCookie.json"; fs.writeFileSync(path, JSON.stringify(NoteCookie, "", "\t")); } + + +//体力定时推送 +export async function DailyNoteTask() { + //体力大于多少时推送 + let sendResin = 120; + //推送cd,12小时一次 + let sendCD = 12 * 3600; + + //获取需要推送的用户 + for (let [user_id, cookie] of Object.entries(NoteCookie)) { + user_id = cookie.qq || user_id; + //没有开启推送 + if (!cookie.isPush) { + continue; + } + + //今天已经提醒 + let sendkey = `genshin:dailyNote:send:${user_id}`; + let send = await redis.get(sendkey); + if (send) { + continue; + } + + let e = { + sendResin, + user_id, + isTask: true + }; + + e.reply = (msg) => { + common.relpyPrivate(user_id, msg); + }; + + //判断今天是否推送 + if (cookie.maxTime && cookie.maxTime > 0 && new Date().getTime() > cookie.maxTime - (160 - sendResin) * 8 * + 60 * 1000) { + //Bot.logger.mark(`体力推送:${user_id}`); + + redis.set(sendkey, "1", { + EX: sendCD + }); + + await Note(e, { + render + }); + } + } +} diff --git a/apps/admin.js b/apps/admin.js index 9c76e87..2941fa8 100644 --- a/apps/admin.js +++ b/apps/admin.js @@ -23,6 +23,7 @@ let cfgMap = { "体力": "sys.Note", "帮助": "sys.help", "匹配": "sys.Atlas", + "模板": "mb.len", }; let sysCfgReg = `^#图鉴设置\s*(${lodash.keys(cfgMap).join("|")})?\s*(.*)$`; export const rule = { @@ -61,20 +62,21 @@ export async function sysCfg(e, { if (!regRet) { return true; } - console.log(regRet) if (regRet[1]) { + // 设置模式 let val = regRet[2] || ""; - + let cfgKey = cfgMap[regRet[1]]; if (cfgKey === "sys.scale") { val = Math.min(200, Math.max(50, val * 1 || 100)); + }else if(cfgKey === "mb.len"){ + val= Math.min(2,Math.max(val,0)); } else { val = !/关闭/.test(val); } if (cfgKey) { - console.log(val) Cfg.set(cfgKey, val); } } @@ -84,8 +86,9 @@ export async function sysCfg(e, { help: getStatus("sys.help", false), Note: getStatus("sys.Note"), Atlas: getStatus("sys.Atlas"), + len:Cfg.get("mb.len", 0), imgPlus: fs.existsSync(plusPath), - bg:await rodom(), //获取底图 + bg: await rodom(), //获取底图 } console.log(cfg) //渲染图像 @@ -98,7 +101,7 @@ export async function sysCfg(e, { }); } -const rodom=async function(){ +const rodom = async function() { var image = fs.readdirSync(`./plugins/xiaoyao-cvs-plugin/resources/admin/imgs/bg`); var list_img = []; for (let val of image) { @@ -135,6 +138,7 @@ export async function updateRes(e) { let isForce = e.msg.includes("强制"); if (isForce) { command = "git checkout . && git pull"; + // command="git fetch --all && git reset --hard origin/master && git pull " e.reply("正在执行强制更新操作,请稍等"); } else { e.reply("正在执行更新操作,请稍等"); @@ -195,7 +199,7 @@ export async function updateMiaoPlugin(e) { cwd: `${_path}/plugins/xiaoyao-cvs-plugin/` }, function(error, stdout, stderr) { //console.log(stdout); - if (/Already up[ -]to[ -]date/.test(stdout)) { + if (/Already up[ -]to[ -]date/.test(stdout)) { e.reply("目前已经是最新版图鉴插件了~"); return true; } @@ -211,22 +215,23 @@ export async function updateMiaoPlugin(e) { }), { EX: 30 }); - timer = setTimeout(function () { - let command = `npm run start`; - if (process.argv[1].includes("pm2")) { - command = `npm run restart`; - } - exec(command, function (error, stdout, stderr) { - if (error) { - e.reply("自动重启失败,请手动重启以应用新版图鉴插件。\nError code: " + error.code + "\n" + error.stack + "\n"); - Bot.logger.error('重启失败\n${error.stack}'); - return true; - } else if (stdout) { - Bot.logger.mark("重启成功,运行已转为后台,查看日志请用命令:npm run log"); - Bot.logger.mark("停止后台运行命令:npm stop"); - process.exit(); - } - }) + timer = setTimeout(function() { + let command = `npm run start`; + if (process.argv[1].includes("pm2")) { + command = `npm run restart`; + } + exec(command, function(error, stdout, stderr) { + if (error) { + e.reply("自动重启失败,请手动重启以应用新版图鉴插件。\nError code: " + error.code + "\n" + + error.stack + "\n"); + Bot.logger.error('重启失败\n${error.stack}'); + return true; + } else if (stdout) { + Bot.logger.mark("重启成功,运行已转为后台,查看日志请用命令:npm run log"); + Bot.logger.mark("停止后台运行命令:npm stop"); + process.exit(); + } + }) }, 1000); }); diff --git a/apps/xiaoyao_image.js b/apps/xiaoyao_image.js index 47edcf1..76179d6 100644 --- a/apps/xiaoyao_image.js +++ b/apps/xiaoyao_image.js @@ -26,7 +26,7 @@ export async function AtlasAlias(e) { // if (await foodInfo(e)) return true; // if (await RelicsInfo(e)) return true; // if (await monsterInfo(e)) return true; - var name = e.msg.replace(/#|#|信息|图鉴|命座|天赋|突破|圣遗物|食物|食材|特殊|材|料|特色|料理|理/g, ""); + var name = e.msg.replace(/#|#|信息|图鉴|圣遗物|食物|食材|特殊|特色|料理/g, ""); return send_Msg(e, "all", name); } diff --git a/resources/admin/index.html b/resources/admin/index.html index ca06904..53fabdb 100644 --- a/resources/admin/index.html +++ b/resources/admin/index.html @@ -100,6 +100,14 @@