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

103 lines
3.9 KiB
Python
Raw Normal View History

2021-11-12 14:25:53 +00:00
import urllib.parse
from config import Config
from core.dirty_check import check
2022-08-04 07:52:42 +00:00
from core.logger import Logger
2021-11-12 14:25:53 +00:00
from modules.wiki.utils.UTC8 import UTC8
from modules.wiki.utils.action_cn import action
from modules.wiki.utils.wikilib import WikiLib
2021-11-12 14:25:53 +00:00
2023-05-21 04:57:33 +00:00
async def rc_qq(wiki_url):
2021-11-12 14:25:53 +00:00
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'
)
2021-12-25 14:46:08 +00:00
pageurl = wiki.wiki_info.articlepath
2021-11-12 14:25:53 +00:00
nodelist = [{
"type": "node",
"data": {
2023-05-21 04:57:33 +00:00
"name": f"最近更改地址",
2021-11-12 14:25:53 +00:00
"uin": qq_account,
"content": [
{"type": "text", "data": {"text": pageurl.replace("$1", 'Special:RecentChanges') +
2023-05-21 04:57:33 +00:00
('\n tips复制粘贴下面的任一消息到聊天窗口发送可获取此次改动详细信息的截图。'
2023-04-30 03:30:59 +00:00
if wiki.wiki_info.in_allowlist else '')}}]
2021-11-12 14:25:53 +00:00
}
}]
rclist = []
userlist = []
titlelist = []
for x in query["query"]["recentchanges"]:
2023-01-16 07:54:07 +00:00
if 'title' in x:
userlist.append(x['user'])
titlelist.append(x['title'])
2021-11-12 14:25:53 +00:00
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)
2023-04-30 03:30:59 +00:00
t.append(
pageurl.replace(
'$1',
f"{urllib.parse.quote(title_checked_map[x['title']])}?oldid={x['old_revid']}&diff={x['revid']}"))
2021-11-12 14:25:53 +00:00
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:
2022-04-08 07:17:39 +00:00
t.append(pageurl.replace(
"$1", f"{urllib.parse.quote(title_checked_map[x['title']])}"))
2021-11-12 14:25:53 +00:00
rclist.append('\n'.join(t))
for x in rclist:
nodelist.append(
{
"type": "node",
"data": {
2023-05-21 04:57:33 +00:00
"name": f"最近更改",
2021-11-12 14:25:53 +00:00
"uin": qq_account,
"content": [{"type": "text", "data": {"text": x}}],
}
})
2022-08-04 07:52:42 +00:00
Logger.debug(nodelist)
2023-05-21 04:57:33 +00:00
return nodelist