修复兑换码获取报错导致无法处理完整数据的问题

更新 #电脑帮助 文案
This commit is contained in:
Anno_Lawl 2024-01-04 17:50:50 +08:00
parent b659655dca
commit 2e877a11b4
2 changed files with 18 additions and 9 deletions

View File

@ -4,7 +4,7 @@ import fetch from 'node-fetch'
import MysInfo from '../model/mys/mysInfo.js' import MysInfo from '../model/mys/mysInfo.js'
export class exchange extends plugin { export class exchange extends plugin {
constructor() { constructor () {
super({ super({
name: '兑换码', name: '兑换码',
dsc: '前瞻直播兑换码', dsc: '前瞻直播兑换码',
@ -23,7 +23,7 @@ export class exchange extends plugin {
}) })
} }
async getCode() { async getCode () {
let reg = this.e.msg.match(/^(#|\*)?(原神|星铁|崩铁|崩三|崩坏三|崩坏3)?(直播|前瞻)?兑换码$/) let reg = this.e.msg.match(/^(#|\*)?(原神|星铁|崩铁|崩三|崩坏三|崩坏3)?(直播|前瞻)?兑换码$/)
this.uid = '75276550' this.uid = '75276550'
if (reg[1] == '*' || ["星铁", "崩铁"].includes(reg[2])) { if (reg[1] == '*' || ["星铁", "崩铁"].includes(reg[2])) {
@ -42,7 +42,9 @@ export class exchange extends plugin {
/** index info */ /** index info */
let index = await this.getData('index') let index = await this.getData('index')
if (!index || !index.data) { return true } if (!index || !index.data) {
return true
}
if (index.data === null) { if (index.data === null) {
return await this.reply(`错误:\n${index.message}`) return await this.reply(`错误:\n${index.message}`)
} }
@ -74,7 +76,7 @@ export class exchange extends plugin {
await this.reply(msg) await this.reply(msg)
} }
async getData(type) { async getData (type) {
let url = { let url = {
index: `https://api-takumi.mihoyo.com/event/miyolive/index`, index: `https://api-takumi.mihoyo.com/event/miyolive/index`,
code: `https://api-takumi-static.mihoyo.com/event/miyolive/refreshCode?version=${this.code_ver}&time=${this.now}`, code: `https://api-takumi-static.mihoyo.com/event/miyolive/refreshCode?version=${this.code_ver}&time=${this.now}`,
@ -103,14 +105,20 @@ export class exchange extends plugin {
} }
// 获取 "act_id" // 获取 "act_id"
async getActId() { async getActId () {
let ret = await this.getData('actId') let ret = await this.getData('actId');
if (ret.error || ret.retcode !== 0) { if (ret.error || ret.retcode !== 0) {
return ""; return "";
} }
for (const p of ret.data.list) { for (const p of ret.data.list) {
const post = p.post.post; let post;
try {
post = p.post.post;
} catch (e) {
logger.error("活动数据获取异常");
logger.error(e);
}
if (!post) { if (!post) {
continue; continue;
} }
@ -124,8 +132,9 @@ export class exchange extends plugin {
} }
} }
} }
// 兑换码使用 // 兑换码使用
async useCode() { async useCode () {
let cdkCode = this.e.message[0].text.split(/#(兑换码使用|cdk-u) /, 3)[2]; let cdkCode = this.e.message[0].text.split(/#(兑换码使用|cdk-u) /, 3)[2];
let res = await MysInfo.get(this.e, 'useCdk', { cdk: cdkCode }) let res = await MysInfo.get(this.e, 'useCdk', { cdk: cdkCode })
if (res) { if (res) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 KiB

After

Width:  |  Height:  |  Size: 457 KiB