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/wiki/utils/rc_qq.py

97 lines
3.6 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 urllib.parse
from config import Config
from core.dirty_check import check
from core.logger import Logger
from modules.wiki.utils.UTC8 import UTC8
from modules.wiki.utils.action_cn import action
from modules.wiki.utils.wikilib import WikiLib
async def rc_qq(wiki_url):
wiki = WikiLib(wiki_url)
qq_account = Config("qq_account")
query = await wiki.get_json(action='query', list='recentchanges',
rcprop='title|user|timestamp|loginfo|comment|redirect|flags|sizes|ids',
rclimit=99,
rctype='edit|new|log'
)
pageurl = wiki.wiki_info.articlepath
nodelist = [{
"type": "node",
"data": {
"name": f"最近更改地址",
"uin": qq_account,
"content": [
{"type": "text", "data": {"text": pageurl.replace("$1", 'Special:RecentChanges')}}]
}
}]
rclist = []
userlist = []
titlelist = []
for x in query["query"]["recentchanges"]:
userlist.append(x['user'])
titlelist.append(x['title'])
checked_userlist = await check(*userlist)
user_checked_map = {}
for u in checked_userlist:
user_checked_map[u['original']] = u['content']
checked_titlelist = await check(*titlelist)
title_checked_map = {}
for t in checked_titlelist:
title_checked_map[t['original']] = t['content']
for x in query["query"]["recentchanges"]:
t = []
t.append(f"用户:{user_checked_map[x['user']]}")
t.append(UTC8(x['timestamp'], 'full'))
if x['type'] == 'edit':
count = x['newlen'] - x['oldlen']
if count > 0:
count = f'+{str(count)}'
else:
count = str(count)
t.append(f"{title_checked_map[x['title']]}{count}")
comment = x['comment']
if comment == '':
comment = '(无摘要内容)'
t.append(comment)
t.append(pageurl.replace('$1',
f"{urllib.parse.quote(title_checked_map[x['title']])}?oldid={x['old_revid']}&diff={x['revid']}"))
if x['type'] == 'new':
r = ''
if 'redirect' in x:
r = '(新重定向)'
t.append(f"{title_checked_map[x['title']]}{r}")
comment = x['comment']
if comment == '':
comment = '(无摘要内容)'
t.append(comment)
if x['type'] == 'log':
log = x['logaction'] + '' + title_checked_map[x['title']]
if x['logtype'] in action:
a = action[x['logtype']].get(x['logaction'])
if a is not None:
log = a % title_checked_map[x['title']]
t.append(log)
params = x['logparams']
if 'durations' in params:
t.append('时长:' + params['durations'])
if 'target_title' in params:
t.append('对象页面:' + params['target_title'])
if x['revid'] != 0:
t.append(pageurl.replace(
"$1", f"{urllib.parse.quote(title_checked_map[x['title']])}"))
rclist.append('\n'.join(t))
for x in rclist:
nodelist.append(
{
"type": "node",
"data": {
"name": f"最近更改",
"uin": qq_account,
"content": [{"type": "text", "data": {"text": x}}],
}
})
Logger.debug(nodelist)
return nodelist