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/ab.py

34 lines
1.4 KiB
Python
Raw Normal View History

2021-02-01 15:13:11 +00:00
import json
import aiohttp
from core.dirty_check import check
from modules.utils.UTC8 import UTC8
2021-03-21 06:57:02 +00:00
from modules.wiki.database import WikiDB
2021-04-08 12:51:28 +00:00
get_start_wiki = WikiDB.get_start_wiki
2021-02-01 15:13:11 +00:00
async def ab(table, id):
get_wiki_url = get_start_wiki(table, id)
if get_wiki_url:
url = get_wiki_url + '?action=query&list=abuselog&aflprop=user|title|action|result|filter|timestamp&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']['abuselog'][:5]:
d.append('' + x['title'] + ' - ' + x['user'] + '' + UTC8(x['timestamp'], 'onlytimenoutc') + '\n过滤器名:' + x[
2021-02-10 14:48:49 +00:00
'filter'] + '\n处理结果:' + x['result'])
2021-02-19 11:25:10 +00:00
y = await check('\n'.join(d))
2021-02-01 15:13:11 +00:00
if y.find('<吃掉了>') != -1 or y.find('<全部吃掉了>') != -1:
return y + '\n...仅显示前5条内容\n检测到外来信息介入请前往滥用日志查看所有消息。Special:滥用日志\n[一分钟后撤回本消息]'
else:
return y + '\n...仅显示前5条内容\n[一分钟后撤回本消息]'
else:
return '未设定起始Wiki。'