diff --git a/docs/game.md b/docs/game.md index 9646f1ee09..22a97e8062 100644 --- a/docs/game.md +++ b/docs/game.md @@ -199,6 +199,10 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 +### 最新消息 + + + ## 旅法师营地 ### 旅法师营地 diff --git a/lib/router.js b/lib/router.js index e43c46f85f..f8266a413a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1437,8 +1437,9 @@ router.get('/dilbert/strip', require('./routes/dilbert/strip')); router.get('/yxdzqb/:type', require('./routes/yxdzqb')); // 怪物猎人 -router.get('/monsterhunter/update', require('./routes/monsterhunter/update')); +router.get('/monsterhunter/update', require('./routes/mhw/update')); router.get('/mhw/update', require('./routes/mhw/update')); +router.get('/mhw/news', require('./routes/mhw/news')); // 005.tv router.get('/005tv/zx/latest', require('./routes/005tv/zx')); diff --git a/lib/routes/mhw/news.js b/lib/routes/mhw/news.js new file mode 100644 index 0000000000..fac8cc8f6b --- /dev/null +++ b/lib/routes/mhw/news.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = 'https://www.monsterhunter.com/world-iceborne/cn/news/'; + const response = await got({ + method: 'get', + url: `https://www.monsterhunter.com/world-iceborne/assets/data/cn/news.json?_=${+new Date()}`, + }); + + let result = response.data.topics.map((item) => ({ + title: item.text, + link: `https://www.monsterhunter.com${item.link}`, + })); + + result = await Promise.all( + result.map(async (item) => + Promise.resolve( + await ctx.cache.tryGet(item.link, async () => { + const response = await got.get(item.link.replace('/cn/', '/') + 'inc/contents_cn.html'); + const $ = cheerio.load(response.data); + + return { + title: + $('.h2') + .text() + .trim() || item.title, + description: $('#contents').html(), + link: item.link, + author: 'MONSTER HUNTER WORLD: ICEBORNE', + }; + }) + ) + ) + ); + + ctx.state.data = { + title: '怪物猎人世界最新消息', + link: url, + item: result, + }; +}; diff --git a/lib/routes/mhw/update.js b/lib/routes/mhw/update.js index 642de1a4c2..13282607b5 100644 --- a/lib/routes/mhw/update.js +++ b/lib/routes/mhw/update.js @@ -31,7 +31,10 @@ module.exports = async (ctx) => { .map((index, item) => { item = $(item); return { - title: item.find('.text').text(), + title: item + .find('.text') + .text() + .trim(), pubDate: new Date(item.find('.date').text()).toUTCString(), link: url2 + item.attr('href'), };