2020-06-13 12:43:43 +00:00
|
|
|
import re
|
2020-08-12 16:01:34 +00:00
|
|
|
|
2021-02-01 15:13:11 +00:00
|
|
|
from graia.application import Group, Friend, MessageChain
|
|
|
|
from graia.application.message.elements.internal import Image, UploadMethods, Plain
|
|
|
|
|
2021-04-25 14:10:03 +00:00
|
|
|
from core.elements import Target
|
2021-02-01 15:13:11 +00:00
|
|
|
from core.template import sendMessage
|
2021-03-21 05:00:17 +00:00
|
|
|
from modules.wiki.database import WikiDB
|
2021-04-25 14:10:03 +00:00
|
|
|
from modules.wiki.wikilib import wikilib
|
2021-02-09 13:05:19 +00:00
|
|
|
from .userlib import GetUser
|
2020-09-19 10:35:13 +00:00
|
|
|
|
2020-08-12 16:01:34 +00:00
|
|
|
|
2021-02-09 13:06:40 +00:00
|
|
|
# 呜呜呜 想偷个懒都不行
|
2021-02-01 15:13:11 +00:00
|
|
|
async def main(kwargs: dict):
|
|
|
|
command = re.sub('^user ', '', kwargs['trigger_msg'])
|
|
|
|
commandsplit = command.split(' ')
|
2021-02-09 13:05:19 +00:00
|
|
|
mode = None
|
|
|
|
metaurl = None
|
|
|
|
username = None
|
2021-04-25 14:10:03 +00:00
|
|
|
id = kwargs[Target].id
|
2021-02-09 13:05:19 +00:00
|
|
|
|
|
|
|
if '-r' in commandsplit:
|
|
|
|
mode = '-r'
|
2021-02-09 13:24:08 +00:00
|
|
|
commandsplit.remove('-r')
|
2021-02-09 13:05:19 +00:00
|
|
|
command = ' '.join(commandsplit)
|
|
|
|
if '-p' in commandsplit:
|
|
|
|
mode = '-p'
|
2021-02-09 13:24:08 +00:00
|
|
|
commandsplit.remove('-p')
|
2021-02-09 13:05:19 +00:00
|
|
|
command = ' '.join(commandsplit)
|
2021-04-25 14:10:03 +00:00
|
|
|
match_interwiki = re.match(r'(.*?):(.*)', command)
|
|
|
|
if match_interwiki:
|
|
|
|
table = 'custom_interwiki_' + kwargs[Target].target_from
|
|
|
|
get_iw = WikiDB.get_custom_interwiki(table, id, match_interwiki.group(1))
|
|
|
|
if get_iw:
|
|
|
|
metaurl = get_iw
|
|
|
|
table = 'start_wiki_link_' + kwargs[Target].target_from
|
|
|
|
get_url = WikiDB.get_start_wiki(table, id)
|
|
|
|
if get_url:
|
|
|
|
metaurl = get_url
|
|
|
|
username = command
|
2021-02-09 13:05:19 +00:00
|
|
|
else:
|
2021-04-25 14:10:03 +00:00
|
|
|
await sendMessage(kwargs, '未设置起始Interwiki。')
|
2021-02-09 13:05:19 +00:00
|
|
|
result = await GetUser(metaurl, username, mode)
|
2021-02-01 15:13:11 +00:00
|
|
|
if result:
|
|
|
|
matchimg = re.match('.*\[\[uimgc:(.*)]]', result)
|
|
|
|
if matchimg:
|
2021-04-25 14:10:03 +00:00
|
|
|
imgchain = MessageChain.create([Image.fromLocalFile(matchimg.group(1))])
|
2021-02-01 15:13:11 +00:00
|
|
|
result = re.sub('\[\[uimgc:.*]]', '', result)
|
|
|
|
msgchain = MessageChain.create([Plain(result)])
|
|
|
|
msgchain = msgchain.plusWith(imgchain)
|
|
|
|
else:
|
|
|
|
msgchain = MessageChain.create([Plain(result)])
|
|
|
|
await sendMessage(kwargs, msgchain)
|
2020-09-19 06:21:06 +00:00
|
|
|
|
2020-09-19 10:35:13 +00:00
|
|
|
|
2021-02-01 15:13:11 +00:00
|
|
|
command = {'user': main}
|
2021-02-09 13:05:19 +00:00
|
|
|
help = {'user': {
|
|
|
|
'help': '~user [~(wiki_name)] <username> - 获取一个Gamepedia用户的信息。' +
|
|
|
|
'\n[-r] - 获取详细信息' +
|
|
|
|
'\n[-p] - 生成一张图片'}}
|