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:31:17 +00:00
|
|
|
from .update import update_difficulty_csv, update_assets
|
2023-05-06 08:48:13 +00:00
|
|
|
from .genb19 import drawb19
|
2023-04-29 08:19:10 +00:00
|
|
|
|
2023-05-18 04:29:55 +00:00
|
|
|
phi = module('phigros', developers=['OasisAkari'], desc='{phigros.help.desc}',
|
2023-04-29 08:19:10 +00:00
|
|
|
alias={'p': 'phigros', 'pgr': 'phigros', 'phi': 'phigros'})
|
|
|
|
|
|
|
|
|
2023-05-18 04:29:55 +00:00
|
|
|
@phi.command('bind <sessiontoken> {{phigros.help.bind}}')
|
2023-04-29 08:19:10 +00:00
|
|
|
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']:
|
2023-05-19 04:46:29 +00:00
|
|
|
send_msg.append(await msg.sendMessage(msg.locale.t("phigros.message.bind.warning")))
|
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:
|
2023-05-19 04:46:29 +00:00
|
|
|
send_msg.append(await msg.sendMessage(msg.locale.t("phigros.message.bind.success")))
|
2023-04-29 08:19:10 +00:00
|
|
|
if need_revoke:
|
|
|
|
await msg.sleep(15)
|
|
|
|
for i in send_msg:
|
|
|
|
await i.delete()
|
|
|
|
|
|
|
|
|
2023-05-19 04:46:29 +00:00
|
|
|
@phi.command('unbind {{phigros.help.unbind}}')
|
2023-04-29 08:19:10 +00:00
|
|
|
async def _(msg: Bot.MessageSession):
|
|
|
|
unbind = PgrBindInfoManager(msg).remove_bind_info()
|
|
|
|
if unbind:
|
2023-05-19 04:46:29 +00:00
|
|
|
await msg.finish(msg.locale.t("phigros.message.unbind.success"))
|
2023-04-29 08:19:10 +00:00
|
|
|
|
|
|
|
|
2023-05-19 04:46:29 +00:00
|
|
|
@phi.command('b19 {{phigros.help.b19}}')
|
2023-04-29 08:19:10 +00:00
|
|
|
async def _(msg: Bot.MessageSession):
|
|
|
|
bind = PgrBindInfoManager(msg).get_bind_sessiontoken()
|
|
|
|
if bind is None:
|
2023-05-18 04:29:55 +00:00
|
|
|
await msg.finish(msg.locale.t("phigros.message.user_unbound"))
|
2023-04-29 08:19:10 +00:00
|
|
|
else:
|
2023-05-20 15:27:57 +00:00
|
|
|
s = TSocket.TSocket()
|
|
|
|
s.setTimeout(10000)
|
|
|
|
transport = TTransport.TBufferedTransport(s)
|
2023-04-29 08:19:10 +00:00
|
|
|
protocol = TBinaryProtocol.TBinaryProtocol(transport)
|
|
|
|
client = Phigros.Client(protocol)
|
|
|
|
transport.open()
|
|
|
|
saveurl = client.getSaveUrl(bind)
|
|
|
|
result = client.best19(saveurl.saveUrl)
|
|
|
|
transport.close()
|
2023-05-18 04:29:55 +00:00
|
|
|
await msg.sendMessage(Image(drawb19('', result)))
|
2023-04-30 16:14:59 +00:00
|
|
|
|
|
|
|
|
2023-05-18 10:10:09 +00:00
|
|
|
@phi.command('update', required_superuser=True)
|
2023-04-30 16:31:17 +00:00
|
|
|
async def _(msg: Bot.MessageSession):
|
2023-05-18 10:15:57 +00:00
|
|
|
update_assets_ = await update_assets()
|
|
|
|
update_difficulty_csv_ = await update_difficulty_csv()
|
2023-05-20 15:06:52 +00:00
|
|
|
|
2023-05-18 15:21:26 +00:00
|
|
|
if update_assets_ and update_difficulty_csv_:
|
2023-05-18 10:35:02 +00:00
|
|
|
await msg.finish(msg.locale.t("phigros.message.update.success"))
|
2023-05-18 15:21:26 +00:00
|
|
|
else:
|
|
|
|
if not update_assets_ and not update_difficulty_csv_:
|
|
|
|
await msg.finish(msg.locale.t("phigros.message.update.failed"))
|
|
|
|
elif not update_assets_:
|
|
|
|
await msg.finish("assets " + msg.locale.t("phigros.message.update.failed"))
|
|
|
|
elif not update_difficulty_csv_:
|
|
|
|
await msg.finish("difficulty_csv " + msg.locale.t("phigros.message.update.failed"))
|