mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-15 12:47:48 +00:00
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
import { ZZZPlugin } from '../lib/plugin.js';
|
|
import settings from '../lib/settings.js';
|
|
import _ from 'lodash';
|
|
import { rulePrefix } from '../lib/common.js';
|
|
import request from '../utils/request.js';
|
|
|
|
export class Calendar extends ZZZPlugin {
|
|
constructor() {
|
|
super({
|
|
name: '[ZZZ-Plugin]Calendar',
|
|
dsc: 'zzzCalendar',
|
|
event: 'message',
|
|
priority: _.get(settings.getConfig('priority'), 'calendar', 70),
|
|
rule: [
|
|
{
|
|
reg: `${rulePrefix}(cal|日历)$`,
|
|
fnc: 'calendar',
|
|
},
|
|
],
|
|
});
|
|
}
|
|
async calendar() {
|
|
const activityList = await request
|
|
.get(
|
|
'https://announcement-api.mihoyo.com/common/nap_cn/announcement/api/getAnnList?game=nap&game_biz=nap_cn&lang=zh-cn&bundle_id=nap_cn&channel_id=1&level=70&platform=pc®ion=prod_gf_cn&uid=12345678'
|
|
)
|
|
.then(res => res.json());
|
|
if (!activityList?.data) {
|
|
return this.reply('获取活动列表失败');
|
|
}
|
|
const t = activityList?.data?.t || new Date().getTime().toString();
|
|
const activityContent = await request
|
|
.get(
|
|
`https://announcement-static.mihoyo.com/common/nap_cn/announcement/api/getAnnContent?game=nap&game_biz=nap_cn&lang=zh-cn&bundle_id=nap_cn&platform=pc®ion=prod_gf_cn&t=${t}&level=70&channel_id=1`
|
|
)
|
|
.then(res => res.json());
|
|
const contentList = activityContent?.data?.list || [];
|
|
const calendarContent = contentList.find(
|
|
item => item.title.includes('日历') && item.subtitle.includes('活动日历')
|
|
);
|
|
|
|
const htmlContent = calendarContent?.content || '';
|
|
if (!htmlContent) {
|
|
return this.reply('未找到活动日历');
|
|
}
|
|
const imgReg = /<img.*?src="(.*?)".*?>/g;
|
|
const imgSrc = imgReg.exec(htmlContent)?.[1];
|
|
if (imgSrc) {
|
|
await this.reply(segment.image(imgSrc));
|
|
} else {
|
|
await this.reply('未找到活动日历图片');
|
|
}
|
|
}
|
|
}
|