2
0
mirror of https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git synced 2024-12-23 03:20:52 +08:00

优化模板选择以及消息发送

This commit is contained in:
Ctrlcvs 2022-08-03 21:25:29 +08:00 committed by leiyilu
parent 98a28713a4
commit f85e110452
4 changed files with 122 additions and 46 deletions

View File

@ -5,16 +5,20 @@ import { checkAuth, getMysApi } from './mys.js'
export class atlas extends plugin { export class atlas extends plugin {
constructor () { constructor () {
let rule = {
reg: '.+',
fnc: 'dispatch'
}
super({ super({
name: 'xiaoyao-cvs-plugin', name: 'xiaoyao-cvs-plugin',
desc: '图鉴插件', desc: '图鉴插件',
event: 'message', event: 'message',
priority: 50, priority: 50,
rule: [{ rule: [rule]
reg: '.+',
fnc: 'dispatch'
}]
}) })
Object.defineProperty(rule, 'log', {
get: () => !!this.isDispatch
})
} }
accept () { accept () {
this.e.original_msg = this.e.original_msg || this.e.msg this.e.original_msg = this.e.original_msg || this.e.msg

View File

@ -4,12 +4,16 @@ import {
import fetch from "node-fetch"; import fetch from "node-fetch";
import Common from "../components/Common.js"; import Common from "../components/Common.js";
import fs from "fs"; import fs from "fs";
import { isV3 } from '../components/Changelog.js' import {
isV3
} from '../components/Changelog.js'
import MysInfo from '../model/mys/mysInfo.js' import MysInfo from '../model/mys/mysInfo.js'
// import { MysUser } from "../../../lib/components/Models.js"; // import { MysUser } from "../../../lib/components/Models.js";
// import common from "../../../lib/common.js"; // import common from "../../../lib/common.js";
import lodash from "lodash"; import lodash from "lodash";
import { getPluginRender } from "./render.js"; import {
getPluginRender
} from "./render.js";
import gsCfg from '../model/gsCfg.js' import gsCfg from '../model/gsCfg.js'
import { import {
@ -26,6 +30,7 @@ let path_img = ["background_image", "/icon/bg"];
let tempDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/NoteTemp` let tempDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/NoteTemp`
let tempData = {}; let tempData = {};
init() init()
function init() { function init() {
Data.createDir("", tempDataUrl, false); Data.createDir("", tempDataUrl, false);
tempData = Data.readJSON(tempDataUrl, "tempData") tempData = Data.readJSON(tempDataUrl, "tempData")
@ -34,16 +39,16 @@ function init() {
//#体力 //#体力
export async function Note(e, { export async function Note(e, {
render render
},poke) { }, poke) {
if (!Cfg.get("sys.Note")&&!poke) { if (!Cfg.get("sys.Note") && !poke) {
return false; return false;
} }
let cookie, uid,res; let cookie, uid, res;
if(isV3){ if (isV3) {
res = await MysInfo.get(e, 'dailyNote') res = await MysInfo.get(e, 'dailyNote')
if (!res || res.retcode !== 0) return true if (!res || res.retcode !== 0) return true
uid=e.uid; uid = e.uid;
}else{ } else {
if (NoteCookie[e.user_id]) { if (NoteCookie[e.user_id]) {
cookie = NoteCookie[e.user_id].cookie; cookie = NoteCookie[e.user_id].cookie;
uid = NoteCookie[e.user_id].uid; uid = NoteCookie[e.user_id].uid;
@ -116,7 +121,7 @@ export async function Note(e, {
if (data.resin_recovery_time > 0) { if (data.resin_recovery_time > 0) {
resinMaxTime = new Date().getTime() + data.resin_recovery_time * 1000; resinMaxTime = new Date().getTime() + data.resin_recovery_time * 1000;
let maxDate = new Date(resinMaxTime); let maxDate = new Date(resinMaxTime);
resinMaxTime =moment(maxDate).format("HH:mm"); resinMaxTime = moment(maxDate).format("HH:mm");
let Time_day = await dateTime_(maxDate) let Time_day = await dateTime_(maxDate)
resinMaxTime_mb2 = Time_day + moment(maxDate).format("hh:mm"); resinMaxTime_mb2 = Time_day + moment(maxDate).format("hh:mm");
// console.log(format("dd", maxDate)) // console.log(format("dd", maxDate))
@ -194,7 +199,7 @@ export async function Note(e, {
coinTime_mb2 = Time_day + moment(coinDate).format("hh:mm"); coinTime_mb2 = Time_day + moment(coinDate).format("hh:mm");
} else { } else {
coinTime_mb2 = moment(coinDate).format("hh:mm"); coinTime_mb2 = moment(coinDate).format("hh:mm");
if ( moment(coinDate).format("DD") != nowDay) { if (moment(coinDate).format("DD") != nowDay) {
coinTime_mb2Day = "明天"; coinTime_mb2Day = "明天";
coinTime = `明天 ${ moment(coinDate).format("hh:mm")}`; coinTime = `明天 ${ moment(coinDate).format("hh:mm")}`;
} else { } else {
@ -204,10 +209,10 @@ export async function Note(e, {
} }
} }
let day = moment(new Date()).format("MM-DD HH:mm"); let day = moment(new Date()).format("MM-DD HH:mm");
let week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; let week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
day += " " + week[new Date().getDay()]; day += " " + week[new Date().getDay()];
let day_mb2 = moment(new Date()).format("yyyy年MM月DD日 HH:mm") + " " + week[new Date().getDay()]; let day_mb2 = moment(new Date()).format("yyyy年MM月DD日 HH:mm") + " " + week[new Date().getDay()];
//参量质变仪 //参量质变仪
if (data?.transformer?.obtained) { if (data?.transformer?.obtained) {
data.transformer.reached = data.transformer.recovery_time.reached; data.transformer.reached = data.transformer.recovery_time.reached;
@ -233,7 +238,7 @@ export async function Note(e, {
urlType = urlType[lodash.random(0, urlType.length - 1)] urlType = urlType[lodash.random(0, urlType.length - 1)]
} }
let img_path = `./plugins/xiaoyao-cvs-plugin/resources/dailyNote/${path_img[mb]}`; let img_path = `./plugins/xiaoyao-cvs-plugin/resources/dailyNote/${path_img[mb]}`;
if (tempData[e.user_id] && tempData[e.user_id].type > 0) { if (tempData[e.user_id] && tempData[e.user_id].type > -1) {
mb = tempData[e.user_id].type; mb = tempData[e.user_id].type;
urlType = tempData[e.user_id].temp; urlType = tempData[e.user_id].temp;
} }
@ -254,6 +259,9 @@ export async function Note(e, {
list_img.push(val) list_img.push(val)
} }
var imgs = list_img.length == 1 ? list_img[0] : list_img[lodash.random(0, list_img.length - 1)]; var imgs = list_img.length == 1 ? list_img[0] : list_img[lodash.random(0, list_img.length - 1)];
if (mb == 0 && urlType.includes(".")) {
imgs = urlType
}
return await Common.render(`dailyNote/${path_url[mb]}`, { return await Common.render(`dailyNote/${path_url[mb]}`, {
save_id: uid, save_id: uid,
uid: uid, uid: uid,
@ -278,10 +286,12 @@ export async function Note(e, {
} }
async function dateTime_(time) { async function dateTime_(time) {
return moment(time).format("HH") < 6 ? "凌晨" : moment(time).format("HH") < 12 ? "上午" : moment(time).format("HH") < 17.5 ? "下午" : moment(time).format("HH") < 19.5 ? "傍晚" : moment(time).format("HH") < 22 ? "晚上" : "深夜"; return moment(time).format("HH") < 6 ? "凌晨" : moment(time).format("HH") < 12 ? "上午" : moment(time).format(
"HH") < 17.5 ? "下午" : moment(time).format("HH") < 19.5 ? "傍晚" : moment(time).format("HH") < 22 ? "晚上" :
"深夜";
} }
async function getDailyNote(uid, cookie) { async function getDailyNote(uid, cookie) {
let mysApi = new MysApi(uid, cookie) let mysApi = new MysApi(uid, cookie)
let { let {
url, url,
headers, headers,
@ -329,8 +339,8 @@ export async function DailyNoteTask() {
}; };
e.reply = (msg) => { e.reply = (msg) => {
Bot.pickUser(user_id*1).sendMsg(msg).catch((err) => { Bot.pickUser(user_id * 1).sendMsg(msg).catch((err) => {
logger.mark(err) logger.mark(err)
}) })
// common.relpyPrivate(user_id, msg); // common.relpyPrivate(user_id, msg);
}; };
@ -346,51 +356,77 @@ export async function DailyNoteTask() {
} }
} }
export async function pokeNote(e){ export async function pokeNote(e) {
if (!Cfg.get("note.poke")) { if (!Cfg.get("note.poke")) {
return false; return false;
} }
return await Note(e, getPluginRender("xiaoyao-cvs-plugin"),"poke"); return await Note(e, getPluginRender("xiaoyao-cvs-plugin"), "poke");
} }
export async function Note_appoint(e) { export async function Note_appoint(e) {
let mbPath=`${_path}/plugins/xiaoyao-cvs-plugin/resources/dailyNote/Template/`; let mbPath = `${_path}/plugins/xiaoyao-cvs-plugin/resources/dailyNote/`;
let msg = e.msg.replace(/#|井|体力|模板|设置/g, ""); let msg = e.msg.replace(/#|井|体力|模板|设置/g, "");
let All = ["默认", "随机", "0"]; let All = ["默认", "随机", "0"];
let urlType = note_file(); let urlType = note_file();
if (!isNaN(msg) && msg != 0) {
if (msg > urlType.length) {
e.reply(`没有${msg}的索引序号哦~`)
return true;
}
msg = urlType[msg - 1];
}
let type = 0; let type = 0;
let nickname = Bot.nickname;
if (e.isGroup) {
let info = await Bot.getGroupMemberInfo(e.group_id, Bot.uin)
nickname = info.card ?? info.nickname
}
if (msg.includes("列表")) { if (msg.includes("列表")) {
let mstList=[]; let mstList = [];
urlType.unshift(`当前支持选择的模板有:`) urlType.unshift(`请选择序号~~\n当前支持选择的模板有:`)
for (let item of urlType) { for (let [index, item] of urlType.entries()) {
let msg_pass=[]; let msg_pass = [];
msg_pass.push(item) let imgurl;
if(item!=urlType[0]){ if (index != 0) {
msg_pass.push( segment.image(`file:///${mbPath}${item}/icon/bg/${fs.readdirSync(`${mbPath}${item}/icon/bg/`)[0]}`)) if (item.includes(".")) {
imgurl = await segment.image(`file:///${mbPath}background_image/${item}`);
item = item.split(".")[0];
} else {
imgurl = await segment.image(
`file:///${mbPath}Template/${item}/icon/bg/${fs.readdirSync(`${mbPath}/Template/${item}/icon/bg/`)[0]}`
)
}
item = index + "." + item
} }
let botqq; msg_pass.push(item)
if(isV3){ if (imgurl) {
let cfg = await import(`file://${_path}/lib/config/config.js`) msg_pass.push(imgurl)
botqq=cfg.default.qq
}else{
botqq=BotConfig?.account?.qq
} }
mstList.push({ mstList.push({
message: msg_pass, message: msg_pass,
nickname: "云崽", nickname: nickname,
user_id: botqq user_id: Bot.uin
}) })
} }
e.reply(await Bot.makeForwardMsg(mstList)); e.reply(await Bot.makeForwardMsg(mstList));
return true; return true;
} }
if(urlType.includes(msg+".png")){
msg=msg+".png";
}
if (!urlType.includes(msg) && !All.includes(msg)) { if (!urlType.includes(msg) && !All.includes(msg)) {
e.reply("没有找到你想要的模板昵!可输入 【#体力模板列表】 查询当前支持的模板哦~~") e.reply("没有找到你想要的模板昵!可输入 【#体力模板列表】 查询当前支持的模板哦~~")
return true; return true;
} else if (All.includes(msg)) { } else if (All.includes(msg)) {
type = -1; type = -1;
} else type = 1; } else {
type = 1
if (msg.includes(".")) {
type = 0
}
}
tempData[e.user_id] = { tempData[e.user_id] = {
temp: msg, temp: msg,
type: type, type: type,
@ -408,5 +444,11 @@ const note_file = function() {
if (val.includes(".")) continue; if (val.includes(".")) continue;
urlType.push(val) urlType.push(val)
} }
var urlFileOne = fs.readdirSync(`./plugins/xiaoyao-cvs-plugin/resources/dailyNote/background_image/`);
for (let val of urlFileOne) {
if (!val.includes(".")) continue;
urlType.push(val)
}
return urlType; return urlType;
} }

View File

@ -289,7 +289,7 @@ export async function allMysSign() {
e.reply = (msg) => { e.reply = (msg) => {
//关闭签到消息推送 //关闭签到消息推送
if (!isPushSign) { if (!isPushSign||ismysbool) {
return; return;
} }
if (msg.includes("签到成功") && (cookie.isSignPush === true || cookie.isSignPush === undefined)) { if (msg.includes("签到成功") && (cookie.isSignPush === true || cookie.isSignPush === undefined)) {
@ -331,7 +331,7 @@ export async function allSign() {
if (!msg.includes("OK")) { if (!msg.includes("OK")) {
return; return;
} }
if (!isAllSign) { if (!isAllSign||isbool) {
return; return;
} }
if (msg.includes("签到成功") && (cookie.isSignPush === true || cookie.isSignPush === undefined)) { if (msg.includes("签到成功") && (cookie.isSignPush === true || cookie.isSignPush === undefined)) {

View File

@ -207,6 +207,15 @@ export default class MihoYoApi {
let resObj = JSON.parse(res.text); let resObj = JSON.parse(res.text);
return resObj; return resObj;
} }
async yunGenshen() {
const url = `https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/login`;
let res = await superagent.post(url).set(this.getyunHeader()).timeout(10000);
url = `https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get`;
res = await superagent.get(url).set(this.getyunHeader()).timeout(10000);
}
async stoken(cookie, e) { async stoken(cookie, e) {
this.e = e; this.e = e;
if (Object.keys(this.getStoken(e.user_id)).length != 0) { if (Object.keys(this.getStoken(e.user_id)).length != 0) {
@ -300,6 +309,27 @@ export default class MihoYoApi {
// 'DS': `1602569298,k0xfEh,07f4545f5d88eac59cb1257aef74a570` // 'DS': `1602569298,k0xfEh,07f4545f5d88eac59cb1257aef74a570`
} }
} }
//云原神签到头
getyunHeader() {
return {
"x-rpc-combo_token": token, //这里填你的ck
"x-rpc-client_type": "2",
"x-rpc-app_version": "1.3.0",
"x-rpc-sys_version": "11",
"x-rpc-channel": "mihoyo",
"x-rpc-device_id": device_id, //这里填获取到的设备Id
"x-rpc-device_name": "Xiaomi Mi 10 Pro",
"x-rpc-device_model": "Mi 10 Pro",
"x-rpc-app_id": "1953439974",
"Referer": "https://app.mihoyo.com",
"Content-Length": "0",
"Host": "api-cloudgame.mihoyo.com",
"Connection": "Keep-Alive",
"Accept-Encoding": "gzip",
"User-Agent": "okhttp/3.14.9"
}
}
getCookieMap(cookie) { getCookieMap(cookie) {
let cookiePattern = /^(\S+)=(\S+)$/; let cookiePattern = /^(\S+)=(\S+)$/;
let cookieArray = cookie.replace(/\s*/g, "").split(";"); let cookieArray = cookie.replace(/\s*/g, "").split(";");