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/user/__init__.py

45 lines
1.5 KiB
Python
Raw Normal View History

2021-08-01 14:26:55 +00:00
import re
2021-10-24 10:55:45 +00:00
from core.component import on_command
2022-06-28 06:11:03 +00:00
from core.elements import Plain, Image
from core.builtins.message import MessageSession
2021-08-07 07:56:48 +00:00
from modules.wiki.dbutils import WikiTargetInfo
2021-08-01 14:26:55 +00:00
from .userlib import GetUser
2021-10-24 10:55:45 +00:00
usr = on_command('user', alias=['u'],
developers=['OasisAkari'])
2021-08-01 14:26:55 +00:00
2021-10-24 10:55:45 +00:00
@usr.handle('<username> [-r|-p] {获取一个MediaWiki用户的信息。-r - 获取详细信息。-p - 生成一张图片。)}')
2021-08-01 14:26:55 +00:00
async def user(msg: MessageSession):
mode = None
metaurl = None
username = None
if msg.parsed_msg['-r'] is True:
mode = '-r'
if msg.parsed_msg['-p'] is True:
mode = '-p'
get_url = WikiTargetInfo(msg).get_start_wiki()
if get_url:
metaurl = get_url
username = msg.parsed_msg['<username>']
else:
2022-05-21 16:04:29 +00:00
await msg.finish('未设置起始wiki且没有提供Interwiki。')
2021-08-01 14:26:55 +00:00
match_interwiki = re.match(r'(.*?):(.*)', username)
if match_interwiki:
get_iw = WikiTargetInfo(msg).get_interwikis()
if get_iw and match_interwiki.group(1) in get_iw:
2021-08-24 13:08:33 +00:00
metaurl = get_iw[match_interwiki.group(1)]
2021-08-01 14:26:55 +00:00
username = match_interwiki.group(2)
result = await GetUser(metaurl, username, mode)
2021-12-24 05:01:30 +00:00
print(result)
2021-08-01 14:26:55 +00:00
if result:
2021-12-24 05:07:49 +00:00
matchimg = re.match('(.*)\[\[uimgc:(.*)]]', result)
2021-08-01 14:26:55 +00:00
if matchimg:
2021-12-24 05:07:49 +00:00
msgchain = [Plain(matchimg.group(1)), Image(matchimg.group(2))]
2021-08-01 14:26:55 +00:00
else:
msgchain = [Plain(result)]
2021-12-24 05:07:49 +00:00
print(msgchain)
2022-05-21 16:04:29 +00:00
await msg.finish(msgchain)