🐛 日历

This commit is contained in:
bietiaop 2024-11-15 20:43:12 +08:00
parent 92bb7993b4
commit 0f8a85fa62
2 changed files with 39 additions and 9 deletions

View file

@ -20,21 +20,26 @@ export class Note extends ZZZPlugin {
});
}
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&region=prod_gf_cn&uid=12345678'
);
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&region=prod_gf_cn&uid=12345678'
)
.then(res => res.json());
if (!activityList?.data) {
await this.reply('获取活动列表失败');
return false;
}
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&region=prod_gf_cn&t=${t}&level=70&channel_id=1`
);
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&region=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) {
await this.reply('未找到活动日历');

View file

@ -28,7 +28,24 @@ const request = (url, options = {}, retry = 0, timeout = 15000) => {
const controller = new AbortController();
const { signal } = controller;
const timeoutId = setTimeout(() => controller.abort(), timeout);
options.headers = {
'Content-Type': 'application/json',
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
Accept:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Sec-Ch-Ua':
'"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
'Sec-Ch-Ua-Mobile': '?0',
'Sec-Ch-Ua-Platform': '"Windows"',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'none',
'Sec-Fetch-User': '?1',
...(options?.headers || {}),
};
const _fetch = async (url, options, retryCount = 0) => {
if (retryCount > retry) {
throw new Error('Retry limit reached', err);
@ -58,9 +75,17 @@ const request = (url, options = {}, retry = 0, timeout = 15000) => {
* @returns {Promise<Response>}
*/
request.get = async (url, data, options = {}) => {
const params = new URLSearchParams(data);
const u = new URL(url);
for (const key in data) {
u.searchParams.append(key, data[key]);
}
const { retry, timeout, ...restOptions } = options;
return request(`${url}?${params}`, restOptions, retry, timeout);
return request(
u.toString(),
{ ...restOptions, method: 'GET' },
retry,
timeout
);
};
/**