mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9f6817c6a | |||
| 4c7cd00a76 | |||
| b8cf10b45d | |||
| 4ec5c3bde1 | |||
| 270b953bc9 | |||
| 13bd0da592 |
@@ -1,3 +1,4 @@
|
|||||||
|
from asyncio import Lock
|
||||||
from collections.abc import AsyncGenerator
|
from collections.abc import AsyncGenerator
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
@@ -72,9 +73,11 @@ async def create_or_update_bind(
|
|||||||
|
|
||||||
T = TypeVar('T', 'TETRIOHistoricalData', 'TOPHistoricalData', 'TOSHistoricalData')
|
T = TypeVar('T', 'TETRIOHistoricalData', 'TOPHistoricalData', 'TOSHistoricalData')
|
||||||
|
|
||||||
|
lock = Lock()
|
||||||
|
|
||||||
|
|
||||||
async def anti_duplicate_add(cls: type[T], model: T) -> None:
|
async def anti_duplicate_add(cls: type[T], model: T) -> None:
|
||||||
async with get_session() as session:
|
async with lock, get_session() as session:
|
||||||
result = (
|
result = (
|
||||||
await session.scalars(
|
await session.scalars(
|
||||||
select(cls)
|
select(cls)
|
||||||
@@ -88,8 +91,8 @@ async def anti_duplicate_add(cls: type[T], model: T) -> None:
|
|||||||
if i.data == model.data:
|
if i.data == model.data:
|
||||||
logger.debug('Anti duplicate successfully')
|
logger.debug('Anti duplicate successfully')
|
||||||
return
|
return
|
||||||
session.add(model)
|
session.add(model)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class Player:
|
|||||||
if self.user_id is not None:
|
if self.user_id is not None:
|
||||||
return self.user_id
|
return self.user_id
|
||||||
if self.user_name is not None:
|
if self.user_name is not None:
|
||||||
return self.user_name
|
return self.user_name.lower()
|
||||||
msg = 'Invalid user'
|
msg = 'Invalid user'
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
|||||||
@@ -172,9 +172,10 @@ async def query_historical_data(user: User, user_info: UserInfoSuccess) -> list[
|
|||||||
|
|
||||||
# 按照时间排序
|
# 按照时间排序
|
||||||
histories = sorted(histories, key=lambda x: x.record_at)
|
histories = sorted(histories, key=lambda x: x.record_at)
|
||||||
|
print(histories)
|
||||||
for index, value in enumerate(histories):
|
for index, value in enumerate(histories):
|
||||||
# 在历史记录里找有没有今天0点后的数据
|
# 在历史记录里找有没有今天0点后的数据, 并且至少要有两个数据点
|
||||||
if value.record_at > today:
|
if value.record_at > today and len(histories) >= 2: # noqa: PLR2004
|
||||||
histories = histories[:index] + [
|
histories = histories[:index] + [
|
||||||
get_specified_point(histories[index - 1], histories[index], today.replace(microsecond=1000))
|
get_specified_point(histories[index - 1], histories[index], today.replace(microsecond=1000))
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = 'nonebot-plugin-tetris-stats'
|
name = 'nonebot-plugin-tetris-stats'
|
||||||
version = '1.2.3'
|
version = '1.2.6'
|
||||||
description = '一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件'
|
description = '一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件'
|
||||||
authors = ['scdhh <wallfjjd@gmail.com>']
|
authors = ['scdhh <wallfjjd@gmail.com>']
|
||||||
readme = 'README.md'
|
readme = 'README.md'
|
||||||
|
|||||||
Reference in New Issue
Block a user