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

36 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import aiohttp
from core.dirty_check import check
from modules.utils.UTC8 import UTC8
from modules.wiki.database import WikiDB
get_start_wiki = WikiDB.get_start_wiki
async def rc(table, id):
get_wiki_url = get_start_wiki(table, id)
if get_wiki_url:
url = get_wiki_url + '?action=query&list=recentchanges&rcprop=title|user|timestamp&rctype=edit|new&format=json'
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}"
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)
y = await check(m)
print(y)
if y.find('<吃掉了>') != -1 or y.find('<全部吃掉了>') != -1:
msg = y + '\n...仅显示前5条内容\n检测到外来信息介入请前往最近更改查看所有消息。Special:最近更改'
else:
msg = y + '\n...仅显示前5条内容'
return msg
else:
return '未设定起始Wiki。'