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,15 +5,19 @@ 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 () {

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")
@ -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,7 +286,9 @@ 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)
@ -355,42 +365,68 @@ export async function pokeNote(e){
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}`);
let botqq; item = item.split(".")[0];
if(isV3){
let cfg = await import(`file://${_path}/lib/config/config.js`)
botqq=cfg.default.qq
} else { } else {
botqq=BotConfig?.account?.qq imgurl = await segment.image(
`file:///${mbPath}Template/${item}/icon/bg/${fs.readdirSync(`${mbPath}/Template/${item}/icon/bg/`)[0]}`
)
}
item = index + "." + item
}
msg_pass.push(item)
if (imgurl) {
msg_pass.push(imgurl)
} }
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(";");