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

65 lines
2.6 KiB
Python
Raw Normal View History

2023-04-29 08:19:10 +00:00
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from .phigrosLibrary import Phigros
import traceback
from config import Config
from core.builtins import Bot
from core.builtins import Plain, Image
from core.component import module
from core.utils.http import get_url
from .dbutils import PgrBindInfoManager
2023-04-30 16:14:59 +00:00
from .update import update_difficulty_csv
2023-04-29 08:19:10 +00:00
phi = module('phigros', developers=['OasisAkari'], desc='查询 Phigros 相关内容。SessionToken获取参考'
'https://mivik.gitee.io/pgr-bot-help/index.html#%E5%AE%89%E5%8D%93',
alias={'p': 'phigros', 'pgr': 'phigros', 'phi': 'phigros'})
@phi.command('bind <sessiontoken> {使用云存档SessionToken绑定一个账户。请在私聊绑定账户}')
async def _(msg: Bot.MessageSession):
need_revoke = False
send_msg = []
if msg.target.targetFrom in ['QQ|Group', 'QQ|Guild', 'Discord|Channel', 'Telegram|group', 'Telegram|supergroup']:
send_msg.append(await msg.sendMessage('警告:您正在群组中绑定账户,这有可能会使您的账户云存档数据被他人篡改。请尽量使用私聊绑定账户以避免这种情况。\n'
2023-04-30 16:14:59 +00:00
'您可以通过重新登录重置SessionToken此次命令产生的消息将在15秒后撤回。'))
2023-04-29 08:19:10 +00:00
need_revoke = True
token: str = msg.parsed_msg['<sessiontoken>']
bind = PgrBindInfoManager(msg).set_bind_info(sessiontoken=token)
if bind:
send_msg.append(await msg.sendMessage("成功绑定账户。"))
if need_revoke:
await msg.sleep(15)
for i in send_msg:
await i.delete()
@phi.command('unbind {取消绑定账户。}')
async def _(msg: Bot.MessageSession):
unbind = PgrBindInfoManager(msg).remove_bind_info()
if unbind:
await msg.finish("成功取消绑定账户。")
@phi.command('b19 {查询B19信息。}')
async def _(msg: Bot.MessageSession):
bind = PgrBindInfoManager(msg).get_bind_sessiontoken()
if bind is None:
await msg.finish("您还未绑定账户。")
else:
transport = TTransport.TBufferedTransport(TSocket.TSocket())
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Phigros.Client(protocol)
transport.open()
saveurl = client.getSaveUrl(bind)
result = client.best19(saveurl.saveUrl)
await msg.sendMessage("查询结果:\n" + str(result))
transport.close()
2023-04-30 16:14:59 +00:00
@phi.command('update rating')
async def _(msg: Bot.MessageSession):
await update_difficulty_csv()