mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
* ✨ 适配 v1 tetrio 的 Trending * 🗃️ 添加 compare_delta 配置项 * 🗃️ 添加 TETRIOLeagueUserMap 索引表 * ✨ 添加对比时间配置项 * ✨ 添加 compare_delta 解析函数 * ✨ 添加 Trending 类的 compare 方法 * 🗃️ 移除不正确的复合索引 * ✨ 定时任务拉取tl数据时同步更新索引 * ✨ 适配 trending * 🐛 修复 find_entry 在无 uid 时的索引返回逻辑 * 📝 修正 compare_delta 迁移父迁移注释 * 🗃️ 为非 PostgreSQL 回填迁移补充外键约束 * 🔒 迁移中使用参数绑定设置 PG 内存参数 * ✨ 修正 Trends 的 vs 为 adpm * 🐛 修正获取玩家 ID 的范围
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
from datetime import timedelta
|
|
|
|
from arclet.alconna import Arg
|
|
from nonebot_plugin_alconna import Option, Subcommand
|
|
from nonebot_plugin_alconna.uniseg import UniMessage
|
|
from nonebot_plugin_orm import async_scoped_session
|
|
from nonebot_plugin_uninfo import Uninfo
|
|
from nonebot_plugin_uninfo.orm import get_session_persist_id
|
|
from nonebot_plugin_user import User
|
|
from sqlalchemy import select
|
|
|
|
from ...db import trigger
|
|
from ...i18n import Lang
|
|
from ...utils.duration import parse_duration
|
|
from . import alc, command
|
|
from .constant import GAME_TYPE
|
|
from .models import TETRIOUserConfig
|
|
from .typedefs import Template
|
|
|
|
command.add(
|
|
Subcommand(
|
|
'config',
|
|
Option(
|
|
'--default-template',
|
|
Arg('template', Template, notice='模板版本'),
|
|
alias=['-DT', 'DefaultTemplate'],
|
|
help_text='设置默认查询模板',
|
|
),
|
|
Option(
|
|
'--default-compare',
|
|
Arg('compare', parse_duration, notice='对比时间距离'),
|
|
alias=['-DC', 'DefaultCompare'],
|
|
help_text='设置默认对比时间距离',
|
|
),
|
|
help_text='TETR.IO 查询个性化配置',
|
|
),
|
|
)
|
|
|
|
alc.shortcut(
|
|
'(?i:io)(?i:配置|配|config)',
|
|
command='tstats TETR.IO config',
|
|
humanized='io配置',
|
|
)
|
|
|
|
|
|
@alc.assign('TETRIO.config')
|
|
async def _(
|
|
user: User,
|
|
session: async_scoped_session,
|
|
event_session: Uninfo,
|
|
template: Template | None = None,
|
|
compare: timedelta | None = None,
|
|
):
|
|
async with trigger(
|
|
session_persist_id=await get_session_persist_id(event_session),
|
|
game_platform=GAME_TYPE,
|
|
command_type='config',
|
|
command_args=([f'--default-template {template}'] if template is not None else [])
|
|
+ ([f'--default-compare {compare}'] if compare is not None else []),
|
|
):
|
|
config = (await session.scalars(select(TETRIOUserConfig).where(TETRIOUserConfig.id == user.id))).one_or_none()
|
|
if config is None:
|
|
config = TETRIOUserConfig(id=user.id, query_template=template or 'v1', compare_delta=compare)
|
|
session.add(config)
|
|
else:
|
|
if template is not None:
|
|
config.query_template = template
|
|
if compare is not None:
|
|
config.compare_delta = compare
|
|
await session.commit()
|
|
await UniMessage(Lang.bind.config_success()).finish()
|