2021-04-08 15:22:55 +00:00
|
|
|
import re
|
|
|
|
|
2021-09-10 18:05:27 +00:00
|
|
|
import ujson as json
|
|
|
|
|
2022-07-31 08:27:58 +00:00
|
|
|
from core.builtins.message import MessageSession
|
2021-10-24 10:55:45 +00:00
|
|
|
from core.component import on_command
|
2022-06-28 06:11:03 +00:00
|
|
|
from core.elements import Plain, Image, Url
|
2021-04-08 15:22:55 +00:00
|
|
|
from core.utils import get_url
|
2021-11-19 17:50:34 +00:00
|
|
|
from .teahouse import get_rss as get_teahouse_rss
|
|
|
|
|
2021-08-07 07:56:48 +00:00
|
|
|
|
2022-09-05 14:08:52 +00:00
|
|
|
async def get_weekly(with_img=False):
|
2021-08-07 03:37:17 +00:00
|
|
|
result = json.loads(await get_url(
|
2022-08-01 15:33:35 +00:00
|
|
|
'https://minecraft.fandom.com/zh/api.php?action=parse&page=Minecraft_Wiki/weekly&prop=text|revid&format=json',
|
|
|
|
200))
|
2021-08-07 03:37:17 +00:00
|
|
|
html = result['parse']['text']['*']
|
|
|
|
text = re.sub(r'<p>', '\n', html) # 分段
|
|
|
|
text = re.sub(r'<(.*?)>', '', text, flags=re.DOTALL) # 移除所有 HTML 标签
|
|
|
|
text = re.sub(r'\n\n\n', '\n\n', text) # 移除不必要的空行
|
|
|
|
text = re.sub(r'\n*$', '', text)
|
|
|
|
img = re.findall(r'(?<=src=")(.*?)(?=/revision/latest/scale-to-(width|height)-down/\d{3}\?cb=\d{14}?")', html)
|
|
|
|
page = re.findall(r'(?<=<b><a href=").*?(?=")', html)
|
2021-09-06 05:13:03 +00:00
|
|
|
msg_list = [Plain('发生错误:本周页面已过期,请联系中文 Minecraft Wiki 更新。' if page[
|
2023-01-28 05:53:11 +00:00
|
|
|
0] == '/zh/wiki/%E7%8E%BB%E7%92%83' else '本周的每周页面:\n\n' + text)]
|
2021-09-06 05:13:03 +00:00
|
|
|
if img:
|
2022-01-17 13:28:49 +00:00
|
|
|
msg_list.append(Plain(f'图片:' + str(Url(f'{img[0][0]}?format=original')) +
|
|
|
|
f'\n\n页面链接:' + str(Url(f'https://minecraft.fandom.com{page[0]}')) +
|
2022-01-20 12:13:03 +00:00
|
|
|
f'\n每周页面:' + str(
|
|
|
|
Url(f'https://minecraft.fandom.com/zh/wiki/?oldid={str(result["parse"]["revid"])}'))))
|
2022-09-05 14:08:52 +00:00
|
|
|
if with_img:
|
|
|
|
msg_list.append(Image(path=img[0][0]))
|
2021-08-07 03:37:17 +00:00
|
|
|
|
2021-09-06 05:13:03 +00:00
|
|
|
return msg_list
|
2021-08-07 03:37:17 +00:00
|
|
|
|
2021-08-07 07:56:48 +00:00
|
|
|
|
2022-08-09 17:02:50 +00:00
|
|
|
wky = on_command('weekly', developers=['Dianliang233'])
|
2021-10-24 10:55:45 +00:00
|
|
|
|
|
|
|
|
2022-08-09 17:02:50 +00:00
|
|
|
@wky.handle('{获取中文 Minecraft Wiki 的每周页面}')
|
2021-10-24 10:55:45 +00:00
|
|
|
async def _(msg: MessageSession):
|
2022-09-05 14:08:52 +00:00
|
|
|
weekly = await get_weekly(True if msg.target.clientName == 'QQ' else False)
|
2022-05-21 16:04:29 +00:00
|
|
|
await msg.finish(weekly)
|
2021-11-19 17:50:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
@wky.handle('teahouse {获取茶馆周报}')
|
|
|
|
async def _(msg: MessageSession):
|
|
|
|
weekly = await get_teahouse_rss()
|
2022-05-21 16:04:29 +00:00
|
|
|
await msg.finish(weekly)
|