-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): 增加对千橡游戏下天书奇谈游戏最新消息的支持 (#16416)
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'imop', | ||
url: 'imop.com', | ||
|
||
zh: { | ||
name: '千橡游戏', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Route } from '@/types'; | ||
import { load } from 'cheerio'; | ||
import got from '@/utils/got'; | ||
import iconv from 'iconv-lite'; | ||
import cache from '@/utils/cache'; | ||
|
||
const baseUrl = 'http://t.imop.com'; | ||
|
||
export const route: Route = { | ||
path: '/tianshu', | ||
categories: ['game'], | ||
example: '/imop/tianshu', | ||
radar: [ | ||
{ | ||
source: ['t.imop.com'], | ||
target: '/tianshu', | ||
}, | ||
], | ||
name: '全部消息', | ||
maintainers: ['zhkgo'], | ||
handler, | ||
}; | ||
|
||
async function handler() { | ||
const { data: response } = await got(`${baseUrl}/list/0-1.htm`, { responseType: 'buffer' }); | ||
const $ = load(iconv.decode(response, 'gbk')); | ||
const list = $('.right .right_top .right_bot .list2 .ul1 ul') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
const href: string = item.find('a').attr('href'); | ||
return { | ||
title: item.find('a').text(), | ||
link: href.startsWith('http') ? href : `${baseUrl}${href}`, | ||
}; | ||
}); | ||
const items = await Promise.all( | ||
list.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const { data: response } = await got(item.link, { responseType: 'buffer' }); | ||
const $ = load(iconv.decode(response, 'gbk')); | ||
item.description = $('.right .right_top .right_bot .articlebox').html(); | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: '天书最新消息', | ||
link: `${baseUrl}/list/0-1.htm`, | ||
item: items, | ||
}; | ||
} |