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
2021-03-21 13:00:17 +08:00

80 lines
2.8 KiB
Python

import re
from graia.application import Group, Friend, MessageChain
from graia.application.message.elements.internal import Image, UploadMethods, Plain
from core.template import sendMessage
from modules.wiki.database import WikiDB
from .userlib import GetUser
database = WikiDB()
# 呜呜呜 想偷个懒都不行
async def main(kwargs: dict):
command = re.sub('^user ', '', kwargs['trigger_msg'])
commandsplit = command.split(' ')
mode = None
metaurl = None
username = None
if Group in kwargs:
id = kwargs[Group].id
if Friend in kwargs:
id = kwargs[Friend].id
if '-r' in commandsplit:
mode = '-r'
commandsplit.remove('-r')
command = ' '.join(commandsplit)
if '-p' in commandsplit:
mode = '-p'
commandsplit.remove('-p')
command = ' '.join(commandsplit)
match_gpsite = re.match(r'~(.*?) (.*)', command)
if match_gpsite:
metaurl = f'https://{match_gpsite.group(1)}.gamepedia.com/api.php'
username = match_gpsite.group(2)
else:
match_interwiki = re.match(r'(.*?):(.*)', command)
if match_interwiki:
if Group in kwargs:
table = 'custom_interwiki_group'
if Friend in kwargs:
table = 'custon_interwiki_self'
get_iw = database.get_custom_interwiki(table, id, match_interwiki.group(1))
if get_iw:
metaurl = get_iw
username = match_interwiki.group(2)
else:
if Group in kwargs:
table = 'start_wiki_link_group'
if Friend in kwargs:
table = 'start_wiki_link_self'
get_url = database.get_start_wiki(table, id)
if get_url:
metaurl = get_url
username = command
else:
await sendMessage(kwargs, '未设置起始Interwiki。')
result = await GetUser(metaurl, username, mode)
if result:
matchimg = re.match('.*\[\[uimgc:(.*)]]', result)
if matchimg:
if Group in kwargs:
mth = UploadMethods.Group
if Friend in kwargs:
mth = UploadMethods.Friend
imgchain = MessageChain.create([Image.fromLocalFile(matchimg.group(1), method=mth)])
result = re.sub('\[\[uimgc:.*]]', '', result)
msgchain = MessageChain.create([Plain(result)])
msgchain = msgchain.plusWith(imgchain)
else:
msgchain = MessageChain.create([Plain(result)])
await sendMessage(kwargs, msgchain)
command = {'user': main}
help = {'user': {
'help': '~user [~(wiki_name)] <username> - 获取一个Gamepedia用户的信息。' +
'\n[-r] - 获取详细信息' +
'\n[-p] - 生成一张图片'}}