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/arcaea/__init__.py
2021-12-25 17:32:41 +08:00

70 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import traceback
from config import Config
from core.component import on_command
from core.elements import MessageSession, Plain, Image
from core.utils import get_url
from .getb30 import getb30
from .info import get_info
from .initialize import arcb30init
arc = on_command('arcaea', developers=['OasisAkari'], desc='查询Arcaea相关内容。',
alias={'b30': 'arcaea b30', 'a': 'arcaea', 'arc': 'arcaea'})
@arc.handle('b30 <friendcode> {查询一个Arcaea用户的b30列表}')
async def _(msg: MessageSession):
assets = os.path.abspath('assets/arcaea')
if not os.path.exists(assets):
await msg.sendMessage('未找到资源文件请放置一枚arcaea的apk到机器人的assets目录并重命名为arc.apk后使用~arcaea initialize初始化资源。')
return
friendcode = msg.parsed_msg['<friendcode>']
if friendcode:
try:
resp = await getb30(friendcode)
except Exception:
traceback.print_exc()
await msg.sendMessage('获取失败。')
return
else:
resp = {'text': '请输入好友码!'}
msgchain = [Plain(resp['text'])]
if 'file' in resp and msg.Feature.image:
msgchain.append(Image(path=resp['file']))
await msg.sendMessage(msgchain)
@arc.handle('info <friendcode> {查询一个Arcaea用户的最近游玩记录}')
async def _(msg: MessageSession):
assets = os.path.abspath('assets/arcaea')
if not os.path.exists(assets):
await msg.sendMessage('未找到资源文件请放置一枚arcaea的apk到机器人的assets目录并重命名为arc.apk后使用~arcaea initialize初始化资源。')
return
friendcode = msg.parsed_msg['<friendcode>']
try:
resp = await get_info(friendcode)
except Exception:
traceback.print_exc()
await msg.sendMessage('获取失败。')
return
await msg.sendMessage(resp)
@arc.handle('initialize', required_superuser=True)
async def _(msg: MessageSession):
assets_apk = os.path.abspath('./assets/arc.apk')
if not os.path.exists(assets_apk):
await msg.sendMessage('未找到arc.apk')
return
result = await arcb30init()
if result:
await msg.sendMessage('成功初始化!')
@arc.handle('download {获取最新版本的游戏apk}')
async def _(msg: MessageSession):
webrender = Config('web_render')
resp = await get_url(webrender + 'source?url=https://webapi.lowiro.com/webapi/serve/static/bin/arcaea/apk/', 200, fmt='json')
if resp:
await msg.sendMessage([Plain(f'目前的最新版本为{resp["value"]["version"]}\n下载地址:{resp["value"]["url"]}')])