diff --git a/plugins/genshin/apps/takeBirthdayPhoto.js b/plugins/genshin/apps/takeBirthdayPhoto.js index b16ed75..adfa622 100644 --- a/plugins/genshin/apps/takeBirthdayPhoto.js +++ b/plugins/genshin/apps/takeBirthdayPhoto.js @@ -3,7 +3,7 @@ import gsCfg from '../model/gsCfg.js' import fetch from 'node-fetch' export class takeBirthdayPhoto extends plugin { - constructor() { + constructor () { super({ name: '留影叙佳期', dsc: '留影叙佳期', @@ -21,7 +21,7 @@ export class takeBirthdayPhoto extends plugin { ]) } - async birthdaystar(e) { + async birthdaystar (e) { const { user_id } = e const userInfo = await this.getCookie(user_id) @@ -32,6 +32,9 @@ export class takeBirthdayPhoto extends plugin { return true } + this.region = await this.getServer(userInfo.uid) + this.game_biz = this.region.includes('cn') ? 'hk4e_cn' : 'hk4e_global' + const e_hk4e_token = await this.getEHK4EToken(userInfo.ck, userInfo.uid) if (!e_hk4e_token) { e.reply(['获取e-hk4e_token失败,请刷新ck后再试~', this.button], true) @@ -48,6 +51,7 @@ export class takeBirthdayPhoto extends plugin { e.reply(['今天没有生日角色哦~', this.button], true) return true } + try { for (const role of birthday_star_list) { await e.reply(`正在获取${role.name}的图片,请稍等~`, true) @@ -68,29 +72,26 @@ export class takeBirthdayPhoto extends plugin { return true } - async getCookie(user_id) { + async getCookie (user_id) { const userInfo = ((await gsCfg.getBingCk()).ckQQ)[user_id] return userInfo } - async getEHK4EToken(ck, uid) { - const isCN = uid.toString().match(/^[125]/) ? true : false - const url = isCN ? 'https://api-takumi.mihoyo.com/common/badge/v1/login/account' : 'https://api-os-takumi.mihoyo.com/common/badge/v1/login/account' - const game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' - const region = await this.getServer(uid) + async getEHK4EToken (ck, uid) { + const url = this.region.includes('cn') ? 'https://api-takumi.mihoyo.com/common/badge/v1/login/account' : 'https://api-os-takumi.mihoyo.com/common/badge/v1/login/account' const headers = { - 'Cookie': ck, + Cookie: ck, 'Content-Type': 'application/json;charset=UTF-8', - 'Referer': 'https://webstatic.mihoyo.com/', - 'Origin': 'https://webstatic.mihoyo.com' + Referer: 'https://webstatic.mihoyo.com/', + Origin: 'https://webstatic.mihoyo.com' } const body = JSON.stringify({ uid: Number(uid), - game_biz: game_biz, + game_biz: this.game_biz, lang: 'zh-cn', - region: region + region: this.region }) - let res = await fetch(url, { method: "POST", body, headers }) + let res = await fetch(url, { method: 'POST', body, headers }) const e_hk4e_token = res.headers.get('set-cookie').match(/e_hk4e_token=(.*?);/)[1] res = await res.json() if (res.retcode != 0) { @@ -99,7 +100,7 @@ export class takeBirthdayPhoto extends plugin { return e_hk4e_token } - async getServer(uid) { + async getServer (uid) { switch (String(uid)[0]) { case '1': case '2': @@ -118,32 +119,22 @@ export class takeBirthdayPhoto extends plugin { return 'cn_gf01' } - async getBirthdayStar(uid, e_hk4e_token, ck) { - const cookie = `e_hk4e_token=${e_hk4e_token};${ck}` - const badge_region = await this.getServer(uid) - const isCN = uid.toString().match(/^[125]/) ? true : false - const game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' - const headers = { 'Cookie': cookie } - const url = `https://hk4e-api.mihoyo.com/event/birthdaystar/account/index?lang=zh-cn&badge_uid=${uid}&badge_region=${badge_region}&game_biz=${game_biz}&activity_id=20220301153521` + async getBirthdayStar (uid, e_hk4e_token, ck) { + const headers = { Cookie: `e_hk4e_token=${e_hk4e_token};${ck}` } + const url = `https://hk4e-api.mihoyo.com/event/birthdaystar/account/index?lang=zh-cn&badge_uid=${uid}&badge_region=${this.region}&game_biz=${this.game_biz}&activity_id=20220301153521` let res = await fetch(url, { headers }) res = await res.json() return res.data.role } - async getBirthdayStarImg(uid, e_hk4e_token, ck, role_id) { - const cookie = `e_hk4e_token=${e_hk4e_token};${ck}` - const badge_region = await this.getServer(uid) - const isCN = uid.toString().match(/^[125]/) ? true : false - const game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' - const headers = { 'Cookie': cookie } - const url = `https://hk4e-api.mihoyo.com/event/birthdaystar/account/post_my_draw?lang=zh-cn&badge_uid=${uid}&badge_region=${badge_region}&game_biz=${game_biz}&activity_id=20220301153521` + async getBirthdayStarImg (uid, e_hk4e_token, ck, role_id) { + const headers = { Cookie: `e_hk4e_token=${e_hk4e_token};${ck}` } + const url = `https://hk4e-api.mihoyo.com/event/birthdaystar/account/post_my_draw?lang=zh-cn&badge_uid=${uid}&badge_region=${this.region}&game_biz=${this.game_biz}&activity_id=20220301153521` const body = JSON.stringify({ role_id: Number(role_id) }) - let res = await fetch(url, { method: "POST", body, headers }) + let res = await fetch(url, { method: 'POST', body, headers }) res = await res.json() - if (res.retcode != 0) { - return res.message - } else { - return 'success' - } + + if (res.retcode != 0) return res.message + else return 'success' } -} \ No newline at end of file +} diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index 0f3cd30..bdaa78c 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -55,7 +55,7 @@ export default class MysInfo { return false } - if (!['1', '2', '5', '6', '7', '8', '9'].includes(String(mysInfo.uid)[0])) { + if (!['1', '2', '3', '5', '6', '7', '8', '9'].includes(String(mysInfo.uid)[0])) { // e.reply('只支持查询国服uid') return false } @@ -103,7 +103,7 @@ export default class MysInfo { } let matchUid = (msg = '') => { - let ret = /[125-9][0-9]{8}/g.exec(msg) + let ret = /[1235-9][0-9]{8}/g.exec(msg) if (!ret) return false return ret[0] } diff --git a/plugins/genshin/resources/StarRail/html/mysNews/mysNews.html b/plugins/genshin/resources/StarRail/html/mysNews/mysNews.html index 7ec26a7..22e3827 100644 --- a/plugins/genshin/resources/StarRail/html/mysNews/mysNews.html +++ b/plugins/genshin/resources/StarRail/html/mysNews/mysNews.html @@ -4,6 +4,7 @@ + @@ -122,7 +123,7 @@ - + + @@ -122,7 +123,7 @@ - + '],h=0;d>h;h++){g.push("");for(var i=0;d>i;i++)g.push('');g.push("")}g.push("
"),c.innerHTML=g.join("");var j=c.childNodes[0],k=(b.width-j.offsetWidth)/2,l=(b.height-j.offsetHeight)/2;k>0&&l>0&&(j.style.margin=l+"px "+k+"px")},a.prototype.clear=function(){this._el.innerHTML=""},a}();QRCode=function(a,b){if(this._htOption={width:256,height:256,typeNumber:4,colorDark:"#000000",colorLight:"#ffffff",correctLevel:d.H},"string"==typeof b&&(b={text:b}),b)for(var c in b)this._htOption[c]=b[c];"string"==typeof a&&(a=document.getElementById(a)),this._android=n(),this._el=a,this._oQRCode=null,this._oDrawing=new q(this._el,this._htOption),this._htOption.text&&this.makeCode(this._htOption.text)},QRCode.prototype.makeCode=function(a){this._oQRCode=new b(r(a,this._htOption.correctLevel),this._htOption.correctLevel),this._oQRCode.addData(a),this._oQRCode.make(),this._el.title=a,this._oDrawing.draw(this._oQRCode),this.makeImage()},QRCode.prototype.makeImage=function(){"function"==typeof this._oDrawing.makeImage&&(!this._android||this._android>=3)&&this._oDrawing.makeImage()},QRCode.prototype.clear=function(){this._oDrawing.clear()},QRCode.CorrectLevel=d}(); \ No newline at end of file diff --git a/plugins/genshin/resources/StarRail/html/mysNews/qrcode.min.js b/plugins/genshin/resources/script/qrcode.min.js similarity index 100% rename from plugins/genshin/resources/StarRail/html/mysNews/qrcode.min.js rename to plugins/genshin/resources/script/qrcode.min.js