Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/utils/rc.py

35 lines
1.4 KiB
Python
Raw Normal View History

import ujson as json
2021-02-01 15:13:11 +00:00
import aiohttp
from core.dirty_check import check
2021-07-30 07:05:58 +00:00
from modules.utils.UTC8 import UTC8
from modules.wiki.wikilib import wikilib
2021-02-01 15:13:11 +00:00
2021-08-23 12:44:31 +00:00
async def rc(wiki_url):
2021-07-30 07:05:58 +00:00
pageurl = await wikilib().get_article_path(wiki_url) + 'Special:RecentChanges'
if wiki_url:
url = wiki_url + '?action=query&list=recentchanges&rcprop=title|user|timestamp&rctype=edit|new&format=json'
2021-02-01 15:13:11 +00:00
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=aiohttp.ClientTimeout(total=20)) as req:
if req.status != 200:
return f"请求时发生错误:{req.status}\n错误汇报地址https://github.com/Teahouse-Studios/bot/issues/new?assignees=OasisAkari&labels=bug&template=5678.md&title="
2021-02-01 15:13:11 +00:00
else:
text1 = await req.text()
file = json.loads(text1)
d = []
for x in file['query']['recentchanges'][:5]:
d.append(x['title'] + ' - ' + x['user'] + ' ' + UTC8(x['timestamp'], 'onlytime'))
m = '\n'.join(d)
print(m)
2021-02-19 11:23:58 +00:00
y = await check(m)
2021-02-01 15:13:11 +00:00
print(y)
if y.find('<吃掉了>') != -1 or y.find('<全部吃掉了>') != -1:
msg = f'{pageurl}\n{y}\n...仅显示前5条内容\n检测到外来信息介入,请前往最近更改查看所有消息。'
2021-02-01 15:13:11 +00:00
else:
msg = f'{pageurl}\n{y}\n...仅显示前5条内容'
2021-02-01 15:13:11 +00:00
return msg
else:
return '未设定起始Wiki。'