2023-08-10 15:33:33 +08:00
|
|
|
|
import plugin from '../../../lib/plugins/plugin.js'
|
2024-01-24 19:14:04 +08:00
|
|
|
|
import MysInfo from '../model/mys/mysInfo.js'
|
2023-08-14 13:09:35 +08:00
|
|
|
|
import fetch from 'node-fetch'
|
2023-08-10 15:33:33 +08:00
|
|
|
|
|
|
|
|
|
export class takeBirthdayPhoto extends plugin {
|
2024-01-24 19:14:04 +08:00
|
|
|
|
constructor() {
|
2023-08-10 15:33:33 +08:00
|
|
|
|
super({
|
|
|
|
|
name: '留影叙佳期',
|
|
|
|
|
dsc: '留影叙佳期',
|
|
|
|
|
event: 'message',
|
|
|
|
|
priority: 5000,
|
|
|
|
|
rule: [
|
|
|
|
|
{
|
2023-10-09 22:04:09 +08:00
|
|
|
|
reg: '^#?(留影(叙佳期)?|((领)?((角色)?生日)(卡)?))$',
|
2023-08-14 04:15:44 +08:00
|
|
|
|
fnc: 'birthdaystar'
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
})
|
2023-12-22 22:56:11 +08:00
|
|
|
|
this.button = segment.button([
|
|
|
|
|
{ text: "留影叙佳期", input: "#留影叙佳期" },
|
|
|
|
|
])
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
2023-08-14 04:15:44 +08:00
|
|
|
|
|
2024-01-24 19:14:04 +08:00
|
|
|
|
async birthdaystar(e) {
|
|
|
|
|
let uid = await MysInfo.getUid(this.e)
|
|
|
|
|
if (!uid) return false
|
|
|
|
|
let ck = await MysInfo.checkUidBing(uid, this.e)
|
|
|
|
|
if (!ck) {
|
2023-12-22 22:56:11 +08:00
|
|
|
|
e.reply(['请先绑定ck再使用本功能哦~', segment.button([
|
|
|
|
|
{ text: "Cookie帮助", callback: "#Cookie帮助" },
|
|
|
|
|
])], true)
|
2023-08-14 04:15:44 +08:00
|
|
|
|
return true
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 19:14:04 +08:00
|
|
|
|
this.region = await this.getServer(uid)
|
2024-01-15 16:17:48 +08:00
|
|
|
|
this.game_biz = this.region.includes('cn') ? 'hk4e_cn' : 'hk4e_global'
|
|
|
|
|
|
2024-01-24 19:14:04 +08:00
|
|
|
|
const e_hk4e_token = await this.getEHK4EToken(ck.ck, uid)
|
2023-08-10 15:33:33 +08:00
|
|
|
|
if (!e_hk4e_token) {
|
2023-12-22 22:56:11 +08:00
|
|
|
|
e.reply(['获取e-hk4e_token失败,请刷新ck后再试~', this.button], true)
|
2023-08-14 04:15:44 +08:00
|
|
|
|
return true
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 19:14:04 +08:00
|
|
|
|
const birthday_star_list = await this.getBirthdayStar(uid, e_hk4e_token, ck.ck)
|
2023-08-10 15:33:33 +08:00
|
|
|
|
if (!birthday_star_list) {
|
2023-12-22 22:56:11 +08:00
|
|
|
|
e.reply(['获取生日角色失败,请稍后再试~', this.button], true)
|
2023-08-14 04:15:44 +08:00
|
|
|
|
return true
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (birthday_star_list.length === 0) {
|
2023-12-22 22:56:11 +08:00
|
|
|
|
e.reply(['今天没有生日角色哦~', this.button], true)
|
2023-08-14 04:15:44 +08:00
|
|
|
|
return true
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
2024-01-15 16:17:48 +08:00
|
|
|
|
|
2023-08-31 16:37:30 +08:00
|
|
|
|
try {
|
|
|
|
|
for (const role of birthday_star_list) {
|
|
|
|
|
await e.reply(`正在获取${role.name}的图片,请稍等~`, true)
|
|
|
|
|
await e.reply(segment.image(role.take_picture))
|
2024-01-24 19:14:04 +08:00
|
|
|
|
const message = await this.getBirthdayStarImg(uid, e_hk4e_token, ck.ck, role.role_id)
|
2023-08-31 16:37:30 +08:00
|
|
|
|
if (message != 'success') {
|
2023-12-22 22:56:11 +08:00
|
|
|
|
await e.reply([message, this.button])
|
2023-08-31 16:37:30 +08:00
|
|
|
|
return true
|
|
|
|
|
} else {
|
|
|
|
|
await e.reply(`获取${role.name}的图片成功~`, true)
|
|
|
|
|
}
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
2023-08-31 16:37:30 +08:00
|
|
|
|
} catch (error) {
|
2023-12-22 22:56:11 +08:00
|
|
|
|
await e.reply([`获取角色留影叙佳期图片失败,可能是ck失效...`, this.button], true)
|
2023-08-31 16:37:30 +08:00
|
|
|
|
logger.error(error)
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 19:14:04 +08:00
|
|
|
|
async getEHK4EToken(ck, uid) {
|
2024-01-15 16:17:48 +08:00
|
|
|
|
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'
|
2023-08-14 13:09:35 +08:00
|
|
|
|
const headers = {
|
2024-01-15 16:17:48 +08:00
|
|
|
|
Cookie: ck,
|
2023-08-10 15:33:33 +08:00
|
|
|
|
'Content-Type': 'application/json;charset=UTF-8',
|
2024-01-15 16:17:48 +08:00
|
|
|
|
Referer: 'https://webstatic.mihoyo.com/',
|
|
|
|
|
Origin: 'https://webstatic.mihoyo.com'
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
|
|
|
|
const body = JSON.stringify({
|
|
|
|
|
uid: Number(uid),
|
2024-01-15 16:17:48 +08:00
|
|
|
|
game_biz: this.game_biz,
|
2023-08-10 15:33:33 +08:00
|
|
|
|
lang: 'zh-cn',
|
2024-01-15 16:17:48 +08:00
|
|
|
|
region: this.region
|
2023-08-10 15:33:33 +08:00
|
|
|
|
})
|
2024-01-15 16:17:48 +08:00
|
|
|
|
let res = await fetch(url, { method: 'POST', body, headers })
|
2023-08-14 13:09:35 +08:00
|
|
|
|
const e_hk4e_token = res.headers.get('set-cookie').match(/e_hk4e_token=(.*?);/)[1]
|
|
|
|
|
res = await res.json()
|
|
|
|
|
if (res.retcode != 0) {
|
2023-08-10 15:33:33 +08:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return e_hk4e_token
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 19:14:04 +08:00
|
|
|
|
async getServer(uid) {
|
2024-02-06 07:19:34 +08:00
|
|
|
|
switch (String(uid).slice(0, -8)) {
|
2023-08-10 15:33:33 +08:00
|
|
|
|
case '1':
|
|
|
|
|
case '2':
|
|
|
|
|
return 'cn_gf01'
|
|
|
|
|
case '5':
|
|
|
|
|
return 'cn_qd01'
|
|
|
|
|
case '6':
|
|
|
|
|
return 'os_usa'
|
|
|
|
|
case '7':
|
|
|
|
|
return 'os_euro'
|
|
|
|
|
case '8':
|
2024-02-04 09:02:39 +08:00
|
|
|
|
case '18':
|
2023-08-10 15:33:33 +08:00
|
|
|
|
return 'os_asia'
|
|
|
|
|
case '9':
|
|
|
|
|
return 'os_cht'
|
|
|
|
|
}
|
|
|
|
|
return 'cn_gf01'
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 19:14:04 +08:00
|
|
|
|
async getBirthdayStar(uid, e_hk4e_token, ck) {
|
2024-01-15 16:17:48 +08:00
|
|
|
|
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`
|
2023-08-14 13:09:35 +08:00
|
|
|
|
let res = await fetch(url, { headers })
|
|
|
|
|
res = await res.json()
|
|
|
|
|
return res.data.role
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 19:14:04 +08:00
|
|
|
|
async getBirthdayStarImg(uid, e_hk4e_token, ck, role_id) {
|
2024-01-15 16:17:48 +08:00
|
|
|
|
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`
|
2023-08-14 13:09:35 +08:00
|
|
|
|
const body = JSON.stringify({ role_id: Number(role_id) })
|
2024-01-15 16:17:48 +08:00
|
|
|
|
let res = await fetch(url, { method: 'POST', body, headers })
|
2023-08-14 13:09:35 +08:00
|
|
|
|
res = await res.json()
|
2024-01-15 16:17:48 +08:00
|
|
|
|
|
|
|
|
|
if (res.retcode != 0) return res.message
|
|
|
|
|
else return 'success'
|
2023-08-10 15:33:33 +08:00
|
|
|
|
}
|
2024-01-15 16:17:48 +08:00
|
|
|
|
}
|