Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Mar 10, 2024
1 parent 229820b commit 19962cd
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 45 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ Telegram:[@lgc2333](https://t.me/lgc2333)

## 📝 更新日志

### 0.11.2

- 小重构小修复

### 0.11.1

- 修复 `ba档线` 指令的问题 \([#56](https://github.com/lgc-NB2Dev/nonebot-plugin-bawiki/pull/56))\
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_bawiki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .config import Cfg as Cfg # noqa: E402
from .help import extra, register_help_cmd, usage # noqa: E402

__version__ = "0.11.1"
__version__ = "0.11.2"
__plugin_meta__ = PluginMetadata(
name="BAWiki",
description="碧蓝档案Wiki插件",
Expand Down
17 changes: 9 additions & 8 deletions nonebot_plugin_bawiki/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional
from typing_extensions import Annotated

from nonebot import get_plugin_config
from pydantic import BaseModel, Field, HttpUrl
Expand All @@ -16,14 +17,14 @@ class Cfg(BaseModel):
ba_illegal_limit: int = 3
ba_arona_set_alias_only_su: bool = False

ba_gamekee_url: HttpUrl = Field("https://ba.gamekee.com/")
ba_schale_url: HttpUrl = Field("https://schale.gg/")
ba_bawiki_db_url: HttpUrl = Field("https://bawiki.lgc2333.top/")
ba_arona_api_url: HttpUrl = Field("https://arona.diyigemt.com/")
ba_arona_cdn_url: HttpUrl = Field("https://arona.cdn.diyigemt.com/")
ba_shittim_url: HttpUrl = Field("https://arona.icu/")
ba_shittim_api_url: HttpUrl = Field("https://api.arona.icu/")
ba_shittim_data_url: HttpUrl = Field("https://data.ba.benx1n.com/")
ba_gamekee_url: Annotated[str, HttpUrl] = Field("https://ba.gamekee.com/")
ba_schale_url: Annotated[str, HttpUrl] = Field("https://schale.gg/")
ba_bawiki_db_url: Annotated[str, HttpUrl] = Field("https://bawiki.lgc2333.top/")
ba_arona_api_url: Annotated[str, HttpUrl] = Field("https://arona.diyigemt.com/")
ba_arona_cdn_url: Annotated[str, HttpUrl] = Field("https://arona.cdn.diyigemt.com/")
ba_shittim_url: Annotated[str, HttpUrl] = Field("https://arona.icu/")
ba_shittim_api_url: Annotated[str, HttpUrl] = Field("https://api.arona.icu/")
ba_shittim_data_url: Annotated[str, HttpUrl] = Field("https://data.ba.benx1n.com/")

ba_shittim_key: Optional[str] = None
ba_shittim_request_delay: float = 0
Expand Down
69 changes: 35 additions & 34 deletions nonebot_plugin_bawiki/data/shittim_chest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from enum import Enum
from io import BytesIO
from typing import (
Annotated,
Any,
AsyncIterable,
Callable,
Dict,
Generic,
Iterable,
List,
Optional,
Protocol,
Expand All @@ -19,6 +19,7 @@
TypeVar,
Union,
)
from typing_extensions import Unpack
from urllib.parse import urljoin

import anyio
Expand All @@ -33,16 +34,15 @@
from nonebot.compat import PYDANTIC_V2, type_validate_python
from nonebot_plugin_htmlrender import get_new_page
from playwright.async_api import Route, ViewportSize
from pydantic import BaseModel, Field
from typing_extensions import Unpack
from pydantic import BaseModel, ConfigDict, Field
from yarl import URL

from nonebot_plugin_bawiki.compat import field_validator
from ..compat import field_validator

if PYDANTIC_V2:
from pydantic import AfterValidator
pass
else:
from pydantic import validator
pass

from ..config import config
from ..resource import (
Expand Down Expand Up @@ -112,7 +112,8 @@ async def __call__(
page: int,
size: int,
delay: float,
) -> Tuple[Optional[List[T]], bool]: ...
) -> Tuple[Optional[List[T]], bool]:
...


class IterPFKwargs(TypedDict, total=False):
Expand Down Expand Up @@ -167,7 +168,7 @@ class RankDataType(Enum):
# region models


def validator_time(v: str):
def validator_time(cls, v: str): # noqa: ANN001, ARG001
try:
return (
datetime.strptime(v, "%Y-%m-%d %H:%M")
Expand All @@ -178,13 +179,24 @@ def validator_time(v: str):
raise ValueError(f"Time `{v}` format error") from e


def validator_time_as_local(v: datetime) -> datetime:
def validator_time_as_local(cls, v: datetime) -> datetime: # noqa: ANN001, ARG001
return v.astimezone()


def each_item_validator(func: Callable[[Any, T], T]):
def wrapper(cls, v: Iterable[T]) -> List[T]: # noqa: ARG001, ANN001
return [func(cls, x) for x in v]

return wrapper


class CamelAliasModel(BaseModel):
class Config:
alias_generator = camel_case
if PYDANTIC_V2:
model_config = ConfigDict(alias_generator=camel_case)
else:

class Config:
alias_generator = camel_case


class PaginationModel(CamelAliasModel):
Expand Down Expand Up @@ -262,31 +274,20 @@ class Rank(PaginationModel):

class RaidChart(CamelAliasModel):
data: Optional[Dict[int, List[Optional[int]]]] = None
time: List[datetime]

if PYDANTIC_V2:
time: List[Annotated[datetime, AfterValidator(validator_time_as_local)]]
else:
time: List[datetime]
_validator_time = validator(
"time",
each_item=True,
allow_reuse=True,
)(validator_time_as_local)
_validator_time = field_validator("time")(
each_item_validator(validator_time_as_local),
)


class ParticipationChart(CamelAliasModel):
value: List[int]
key: List[datetime]

if PYDANTIC_V2:
key: List[Annotated[datetime, AfterValidator(validator_time_as_local)]]
else:
key: List[datetime]

_validator_time = validator(
"key",
each_item=True,
allow_reuse=True,
)(validator_time_as_local)
_validator_time = field_validator("key")(
each_item_validator(validator_time_as_local),
)


# endregion
Expand Down Expand Up @@ -478,12 +479,12 @@ def render_raid_chart(data: RaidChart) -> bytes:

ax = figure.add_subplot()
for key in CHART_SHOW_RANKS:
if (key not in data.data) or (not (y := data.data[key])):
if (not data.data) or (key not in data.data) or (not (y := data.data[key])):
continue
x = data.time[: len(y)]
ax.plot(
x,
y,
x, # type: ignore
y, # type: ignore
label=(
f"{' ' * (10 - (len(str(key)) * 2))}{key} | "
f"{x[-1].strftime(DATE_FORMAT)} | "
Expand All @@ -501,7 +502,7 @@ def render_participation_chart(data: ParticipationChart) -> bytes:

ax = figure.add_subplot()
ax.plot(
data.key,
data.key, # type: ignore
data.value,
label=(
"Participants | "
Expand Down
4 changes: 4 additions & 0 deletions nonebot_plugin_bawiki/resource/res/shittim/css/shittim.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ body {
text-align: center;
}

.grade-title.ins {
background-color: rgb(216, 212, 253);
}

.grade-title.extreme {
background-color: rgb(252, 222, 253);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ Args:
<div class="content grade-line">
{%- for rank in summaries -%}
<div class="grade">
<div class="grade-title {{ rank.hard_fullname | lower }}">{{ rank.hard_fullname }}</div>
{%- if rank.hard_fullname == "INS" -%}{%- set name = "Insane" -%}
{%- else -%}{%- set name = rank.hard_fullname -%}{%- endif -%}
<div class="grade-title {{ rank.hard_fullname | lower }}">{{ name }}</div>
<div class="number">{{ rank.rank }}</div>
</div>
{%- endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_bawiki/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async def base_async_req(*urls: str, **kwargs: Unpack[AsyncReqKwargs]) -> Any:
if not isinstance(base_urls, list):
base_urls = [base_urls]
urls = tuple(
itertools.starmap(urljoin, itertools.product(base_urls, urls)),
itertools.starmap(urljoin, itertools.product(base_urls, urls)), # type: ignore
)

async def do_request(current_url: str):
Expand Down

0 comments on commit 19962cd

Please sign in to comment.