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 {
constructor () {
let rule = {
reg: '.+',
fnc: 'dispatch'
}
super({
name: 'xiaoyao-cvs-plugin',
desc: '图鉴插件',
event: 'message',
priority: 50,
rule: [{
reg: '.+',
fnc: 'dispatch'
}]
rule: [rule]
})
Object.defineProperty(rule, 'log', {
get: () => !!this.isDispatch
})
}
accept () {

View File

@ -4,12 +4,16 @@ import {
import fetch from "node-fetch";
import Common from "../components/Common.js";
import fs from "fs";
import { isV3 } from '../components/Changelog.js'
import {
isV3
} from '../components/Changelog.js'
import MysInfo from '../model/mys/mysInfo.js'
// import { MysUser } from "../../../lib/components/Models.js";
// import common from "../../../lib/common.js";
import lodash from "lodash";
import { getPluginRender } from "./render.js";
import {
getPluginRender
} from "./render.js";
import gsCfg from '../model/gsCfg.js'
import {
@ -26,6 +30,7 @@ let path_img = ["background_image", "/icon/bg"];
let tempDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/NoteTemp`
let tempData = {};
init()
function init() {
Data.createDir("", tempDataUrl, false);
tempData = Data.readJSON(tempDataUrl, "tempData")
@ -233,7 +238,7 @@ export async function Note(e, {
urlType = urlType[lodash.random(0, urlType.length - 1)]
}
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;
urlType = tempData[e.user_id].temp;
}
@ -254,6 +259,9 @@ export async function Note(e, {
list_img.push(val)
}
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]}`, {
save_id: uid,
uid: uid,
@ -278,7 +286,9 @@ export async function Note(e, {
}
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) {
let mysApi = new MysApi(uid, cookie)
@ -355,42 +365,68 @@ export async function pokeNote(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 All = ["默认", "随机", "0"];
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 nickname = Bot.nickname;
if (e.isGroup) {
let info = await Bot.getGroupMemberInfo(e.group_id, Bot.uin)
nickname = info.card ?? info.nickname
}
if (msg.includes("列表")) {
let mstList = [];
urlType.unshift(`当前支持选择的模板有:`)
for (let item of urlType) {
urlType.unshift(`请选择序号~~\n当前支持选择的模板有:`)
for (let [index, item] of urlType.entries()) {
let msg_pass = [];
msg_pass.push(item)
if(item!=urlType[0]){
msg_pass.push( segment.image(`file:///${mbPath}${item}/icon/bg/${fs.readdirSync(`${mbPath}${item}/icon/bg/`)[0]}`))
}
let botqq;
if(isV3){
let cfg = await import(`file://${_path}/lib/config/config.js`)
botqq=cfg.default.qq
let imgurl;
if (index != 0) {
if (item.includes(".")) {
imgurl = await segment.image(`file:///${mbPath}background_image/${item}`);
item = item.split(".")[0];
} 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({
message: msg_pass,
nickname: "云崽",
user_id: botqq
nickname: nickname,
user_id: Bot.uin
})
}
e.reply(await Bot.makeForwardMsg(mstList));
return true;
}
if(urlType.includes(msg+".png")){
msg=msg+".png";
}
if (!urlType.includes(msg) && !All.includes(msg)) {
e.reply("没有找到你想要的模板昵!可输入 【#体力模板列表】 查询当前支持的模板哦~~")
return true;
} else if (All.includes(msg)) {
type = -1;
} else type = 1;
} else {
type = 1
if (msg.includes(".")) {
type = 0
}
}
tempData[e.user_id] = {
temp: msg,
type: type,
@ -408,5 +444,11 @@ const note_file = function() {
if (val.includes(".")) continue;
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;
}

View File

@ -289,7 +289,7 @@ export async function allMysSign() {
e.reply = (msg) => {
//关闭签到消息推送
if (!isPushSign) {
if (!isPushSign||ismysbool) {
return;
}
if (msg.includes("签到成功") && (cookie.isSignPush === true || cookie.isSignPush === undefined)) {
@ -331,7 +331,7 @@ export async function allSign() {
if (!msg.includes("OK")) {
return;
}
if (!isAllSign) {
if (!isAllSign||isbool) {
return;
}
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);
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) {
this.e = e;
if (Object.keys(this.getStoken(e.user_id)).length != 0) {
@ -300,6 +309,27 @@ export default class MihoYoApi {
// '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) {
let cookiePattern = /^(\S+)=(\S+)$/;
let cookieArray = cookie.replace(/\s*/g, "").split(";");