喵喵日历增加从活动详情信息中解析活动日期的逻辑,使一些活动日期更加准确

This commit is contained in:
yoimiya-kokomi 2022-05-20 16:01:46 +08:00
parent 29f5c42a64
commit 0fc70eb4f1
2 changed files with 46 additions and 18 deletions

View File

@ -1,6 +1,8 @@
# 1.5.4
# 1.5.5
* `#喵喵日历` 增加 `#喵喵日历列表`命令,以列表形式展示活动信息
* `#喵喵日历` 升级
* 增加 `#喵喵日历列表`命令,以列表形式展示活动信息
* 增加从活动详情信息中解析活动日期的逻辑,使一些活动日期更加准确
* `#深渊出场率`、`#角色持有率` 等功能样式及字体微调
* 增加鹿野院平藏的角色信息,可通过`#平藏天赋`、`#平藏命座`查看信息
* `#角色面板` 伤害计算增加双手剑计算逻辑,增加物伤计算逻辑

View File

@ -19,11 +19,36 @@ let Cal = {
let listApi = "https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAnnList?game=hk4e&game_biz=hk4e_cn&lang=zh-cn&bundle_id=hk4e_cn&platform=pc&region=cn_gf01&level=55&uid=100000000";
let request = await fetch(listApi);
let calendarData = await request.json();
return calendarData;
let listData = await request.json();
let timeMap;
let timeMapCache = await redis.get("cache:calendar:detail");
if (timeMapCache) {
timeMap = JSON.parse(timeMapCache) || {};
} else {
let detailApi = "https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAnnContent?game=hk4e&game_biz=hk4e_cn&lang=zh-cn&bundle_id=hk4e_cn&platform=pc&region=cn_gf01&level=55&uid=100000000";
let request2 = await fetch(detailApi);
let detailData = await request2.json();
timeMap = {}
if (detailData && detailData.data && detailData.data.list) {
lodash.forEach(detailData.data.list, (ds) => {
let { ann_id, content } = ds;
content = content.replace(/(<|&lt;)[\w "%:;=\-\\/\\(\\)\,\\.]+(>|&gt;)/g, "");
let timeRet = /活动时间(?:〓|\s)*([0-9\\/\\: ~]*)/.exec(content);
if (timeRet && timeRet[1]) {
let times = timeRet[1].split("~");
if (times.length === 2) {
timeMap[ann_id] = {
start: times[0].trim().replace(/\//g,"-"),
end: times[1].trim().replace(/\//g,"-")
}
}
}
})
}
await redis.set("cache:calendar:detail", JSON.stringify(timeMap), { EX: 60 * 30 });
}
return { listData, timeMap };
},
getDateList() {
@ -81,10 +106,10 @@ let Cal = {
next = now.add(1, "M").format(f),
nextM = now.format("MMMM");
check.push([moment(`${last}-16 04:00`), moment(`${curr}-01 03:59`), lastM + "下半"]);
check.push([moment(`${curr}-01 04:00`), moment(`${curr}-16 03:59`), currM + "上半"]);
check.push([moment(`${curr}-16 04:00`), moment(`${next}-01 03:59`), currM + "下半"]);
check.push([moment(`${next}-01 04:00`), moment(`${next}-16 03:59`), nextM + "上半"]);
check.push([moment(`${last}-16 04:00:00`), moment(`${curr}-01 03:59:59`), lastM + "下半"]);
check.push([moment(`${curr}-01 04:00:00`), moment(`${curr}-16 03:59:59`), currM + "上半"]);
check.push([moment(`${curr}-16 04:00:00`), moment(`${next}-01 03:59:59`), currM + "下半"]);
check.push([moment(`${next}-01 04:00:00`), moment(`${next}-16 03:59:59`), nextM + "上半"]);
let ret = [];
lodash.forEach(check, (ds) => {
@ -96,12 +121,14 @@ let Cal = {
return ret;
},
getList(ds, target, { startTime, endTime, totalRange, now }, isAct = false,) {
getList(ds, target, { startTime, endTime, totalRange, now, timeMap = {} }, isAct = false,) {
let type = isAct ? "activity" : "normal",
id = ds.ann_id,
title = ds.title,
banner = isAct ? ds.banner : '',
extra = { sort: isAct ? 5 : 10 };
extra = { sort: isAct ? 5 : 10 },
detail = timeMap[id] || {};
if (ignoreIds.includes(id) || ignoreReg.test(title)) {
return;
@ -128,8 +155,8 @@ let Cal = {
}
}
let sDate = moment(ds.start_time),
eDate = moment(ds.end_time);
let sDate = moment(detail.start || ds.start_time),
eDate = moment(detail.end || ds.end_time);
let sTime = moment.max(sDate, startTime),
eTime = moment.min(eDate, endTime);
@ -177,15 +204,14 @@ let Cal = {
let now = moment();
let calendarData = await Cal.reqCalData();
let { listData, timeMap } = await Cal.reqCalData();
let dl = Cal.getDateList();
let list = [], abyss = [];
lodash.forEach(calendarData.data.list[1].list, (ds) => Cal.getList(ds, list, { ...dl, now }, true))
lodash.forEach(calendarData.data.list[0].list, (ds) => Cal.getList(ds, list, { ...dl, now }, false));
lodash.forEach(listData.data.list[1].list, (ds) => Cal.getList(ds, list, { ...dl, now, timeMap }, true))
lodash.forEach(listData.data.list[0].list, (ds) => Cal.getList(ds, list, { ...dl, now, timeMap }, false));
let abyssCal = Cal.getAbyssCal(dl.startTime, dl.endTime);
lodash.forEach(abyssCal, (t) => {