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

61 lines
2 KiB
Python
Raw Normal View History

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
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
from modules.wiki.wikilib import wikilib
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(' ')
mode = None
metaurl = None
username = None
id = kwargs[Target].id
if '-r' in commandsplit:
mode = '-r'
2021-02-09 13:24:08 +00:00
commandsplit.remove('-r')
command = ' '.join(commandsplit)
if '-p' in commandsplit:
mode = '-p'
2021-02-09 13:24:08 +00:00
commandsplit.remove('-p')
command = ' '.join(commandsplit)
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
else:
await sendMessage(kwargs, '未设置起始Interwiki。')
result = await GetUser(metaurl, username, mode)
2021-02-01 15:13:11 +00:00
if result:
matchimg = re.match('.*\[\[uimgc:(.*)]]', result)
if matchimg:
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}
help = {'user': {
'help': '~user [~(wiki_name)] <username> - 获取一个Gamepedia用户的信息。' +
'\n[-r] - 获取详细信息' +
'\n[-p] - 生成一张图片'}}