mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
✨ 适配 Trending (#539)
* ✨ 适配 v1 tetrio 的 Trending * 🗃️ 添加 compare_delta 配置项 * 🗃️ 添加 TETRIOLeagueUserMap 索引表 * ✨ 添加对比时间配置项 * ✨ 添加 compare_delta 解析函数 * ✨ 添加 Trending 类的 compare 方法 * 🗃️ 移除不正确的复合索引 * ✨ 定时任务拉取tl数据时同步更新索引 * ✨ 适配 trending * 🐛 修复 find_entry 在无 uid 时的索引返回逻辑 * 📝 修正 compare_delta 迁移父迁移注释 * 🗃️ 为非 PostgreSQL 回填迁移补充外键约束 * 🔒 迁移中使用参数绑定设置 PG 内存参数 * ✨ 修正 Trends 的 vs 为 adpm * 🐛 修正获取玩家 ID 的范围
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from arclet.alconna import Arg
|
||||
from nonebot_plugin_alconna import Option, Subcommand
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
@@ -9,6 +11,7 @@ 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
|
||||
@@ -23,6 +26,12 @@ command.add(
|
||||
alias=['-DT', 'DefaultTemplate'],
|
||||
help_text='设置默认查询模板',
|
||||
),
|
||||
Option(
|
||||
'--default-compare',
|
||||
Arg('compare', parse_duration, notice='对比时间距离'),
|
||||
alias=['-DC', 'DefaultCompare'],
|
||||
help_text='设置默认对比时间距离',
|
||||
),
|
||||
help_text='TETR.IO 查询个性化配置',
|
||||
),
|
||||
)
|
||||
@@ -35,18 +44,28 @@ alc.shortcut(
|
||||
|
||||
|
||||
@alc.assign('TETRIO.config')
|
||||
async def _(user: User, session: async_scoped_session, event_session: Uninfo, template: Template):
|
||||
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}'],
|
||||
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)
|
||||
config = TETRIOUserConfig(id=user.id, query_template=template or 'v1', compare_delta=compare)
|
||||
session.add(config)
|
||||
else:
|
||||
config.query_template = template
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user