From 91f1d98176b1885eda522523070345ab12e3fd57 Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Thu, 13 Oct 2022 10:47:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=AD=BE=E5=88=B0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=E3=80=81=E7=B1=B3?= =?UTF-8?q?=E6=B8=B8=E5=B8=81=E5=85=A8=E9=83=A8=E7=AD=BE=E5=88=B0=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=81=E7=B1=B3=E7=A4=BE=E8=87=AA=E5=8A=A8=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sign.js | 5 +++-- model/mys/mihoyoApi.js | 2 +- model/mys/utils.js | 11 +++++++++- model/user.js | 49 +++++++++++++++++++++++++++--------------- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/apps/sign.js b/apps/sign.js index a31477a..8f9ecee 100644 --- a/apps/sign.js +++ b/apps/sign.js @@ -38,8 +38,9 @@ export const rule = { } export async function cloudSign(e){ let user = new User(e); - let res= await user.cloudSeach() - await replyMsg(e, "云原神签到成功\n当前"+res.message); + START = moment().unix(); + let res= await user.cloudSign() + await replyMsg(e, res.message); return true; } export async function signTask(e){ diff --git a/model/mys/mihoyoApi.js b/model/mys/mihoyoApi.js index 683df94..e123239 100644 --- a/model/mys/mihoyoApi.js +++ b/model/mys/mihoyoApi.js @@ -202,7 +202,7 @@ export default class miHoYoApi { }, cloudGamer: { url: `${mys.cloud_api}/hk4e_cg_cn/gamer/api/ackNotification`, - query: `id=${data.reward_id}`, + body: {id:data.reward_id}, types: 'cloud' }, cloudGet: { diff --git a/model/mys/utils.js b/model/mys/utils.js index 3c72830..8755688 100644 --- a/model/mys/utils.js +++ b/model/mys/utils.js @@ -20,6 +20,15 @@ export function randomString(length,os=false) { } return randomStr; } + +export async function redisGet(userId,type='bbs'){ + await redis.get(`xiaoyao:${type}:${userId}`); +} +export async function redisSet(userId,type='bbs',data){ + var time = moment(Date.now()).add('days', 1).format('YYYY-MM-DD 00:00:00') + var new_date = (new Date(time).getTime() - new Date().getTime()) / 1000 //获取隔天凌晨的时间差 + await redis.set(`xiaoyao:${type}:${userId}`,JSON.stringify(data),{EX:parseInt(new_date)}); +} /** * 发送私聊消息,仅给好友发送 * @param user_id qq号 @@ -91,7 +100,7 @@ export default { sleepAsync,getServer, randomSleepAsync, replyMake, - randomString, + randomString,redisGet,redisSet, relpyPrivate, getCookieMap } diff --git a/model/user.js b/model/user.js index 5800459..f9f86d0 100644 --- a/model/user.js +++ b/model/user.js @@ -44,7 +44,8 @@ export default class user { let yundata = yunres.data if (yunres.retcode === 0) { sumData["云原神"] = { - "今日可获取": yundata?.coin?.coin_num, + "今日可获取": yundata?.coin?.free_coin_num, + "米云币":yundata?.coin?.coin_num, "免费时长": yundata?.free_time?.free_time, "总时长": yundata.total_time } @@ -88,9 +89,9 @@ export default class user { if (!(this.configSign.signlist.includes(forum.name))) { continue; } - message += `**${forum.name}**\n` let res try { + message += `**${forum.name}**\n` res = await this.getData("userGameInfo", forum) await utils.sleepAsync(300) //等几毫秒免得请求太频繁了 if (res?.data?.list?.length === 0 || !res?.data?.list) { @@ -152,7 +153,22 @@ export default class user { async docHelp(type) { return this.configSign[type.includes("云") ? "yunDoc" : "cookiesDoc"] } - + async cloudSign(){ + let res = await this.getData("cloudReward") + if(res?.data?.list?.length==0||!res?.data?.list){ + res.message=`您今天的奖励已经领取了~` + }else{ + let sendMsg=`` + for(let item of res?.data?.list){ + let reward_id = item.id; + let reward_msg = item.msg; + res = await this.getData("cloudGamer",{reward_id}) + sendMsg+=`\n领取奖励,ID:${reward_id},Msg:${reward_msg}` + } + res.message=sendMsg; + } + return res + } async cloudSeach() { let res = await this.getData("cloudGet") //这样会算签到?具体待测试 if (res?.retcode == -100) { @@ -185,10 +201,6 @@ export default class user { challenge = '', res; try { - if (bbsTask) { - this.e.reply(`米游币自动签到任务进行中、暂不支持手动签到`); - return false; - } for (let forum of forumData) { let trueDetail = 0; let Vote = 0; @@ -398,7 +410,7 @@ export default class user { utils.relpyPrivate(qq, msg + "\n云原神自动签到成功"); } }; - await this.cloudSeach(e); + await this.cloudSign(e); await utils.sleepAsync(10000); } let msg = `云原神签到任务完成` @@ -487,7 +499,7 @@ export default class user { bbsTask = false; } async bbsGeetest() { - let res = await this.getData('bbsGetCaptcha') //????????????????????????????? + let res = await this.getData('bbsGetCaptcha') let challenge = res.data["challenge"] res = await this.getData("bbsValidate", res.data) if (res?.data?.validate) { @@ -530,7 +542,6 @@ export default class user { skuid } = await this.getCookie(e); let cookiesDoc = await this.getcookiesDoc(); - // let miHoYoApi = new MihoYoApi(this.e); if (!cookie) { e.reply("请先#绑定cookie\n发送【体力帮助】查看配置教程") return false; @@ -543,7 +554,7 @@ export default class user { // e.reply("米游社登录cookie不完整,请前往米游社通行证处重新获取cookie~\ncookies必须包含login_ticket【教程】 " + cookiesDoc) return false; } - let flot = this.stoken(cookie, e) + let flot =await this.stoken(cookie, e) await utils.sleepAsync(1000); //延迟加载防止文件未生成 if (!flot) { e.reply("登录失效请重新登录获取cookie发送机器人~") @@ -585,20 +596,24 @@ export default class user { if (Object.keys(datalist).length > 0) { return true; } - const map = utils.getCookieMap(cookie); - let loginTicket = map.get("login_ticket"); - const loginUid = map.get("login_uid") ? map.get("login_uid") : map.get("ltuid"); + const map =await utils.getCookieMap(cookie); + let loginTicket = map?.get("login_ticket"); + const loginUid = map?.get("login_uid") ? map?.get("login_uid") : map?.get("ltuid"); if (isV3) { loginTicket = gsCfg.getBingCookie(e.user_id).login_ticket } - - let res = this.getData("bbsStoken", { + let mhyapi = new miHoYoApi(this.e); + let res = await mhyapi.getData("bbsStoken", { loginUid, loginTicket }) + // this.getData("bbsStoken", { + // loginUid, + // loginTicket + // }) if (res?.data) { datalist[e.uid] = { - stuid: map.get("account_id"), + stuid: map?.get("account_id"), stoken: data.data.list[0].token, ltoken: data.data.list[1].token, uid: e.uid,