Skip to content

Commit

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

## 📝 更新日志

### 0.3.1

- 兼容 HTTPX 0.28

### 0.3.0

- 适配 Pydantic V1 & V2
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_nonememe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from . import __main__ as __main__ # noqa: E402
from .config import ConfigModel # noqa: E402

__version__ = "0.3.0"
__version__ = "0.3.1"
__plugin_meta__ = PluginMetadata(
name="NoneMeme",
description="NoneBot 群大佬的日常",
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_nonememe/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from typing import List, NoReturn
from typing import NoReturn

from nonebot import logger, on_command
from nonebot.adapters import Event, Message
Expand Down Expand Up @@ -67,7 +67,7 @@ async def _(matcher: Matcher, state: T_State, event: Event):
if arg in ("0", "q", "quit", "exit", "退出"):
await matcher.finish("已退出选择")

searched: List[MemeItem] = state["items"]
searched: list[MemeItem] = state["items"]
if not (arg.isdigit() and (0 <= (index := (int(arg) - 1)) < len(searched))):
await matcher.reject("请输入正确的结果序号,退出选择请发送 `0`")

Expand Down
16 changes: 8 additions & 8 deletions nonebot_plugin_nonememe/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import urllib.parse
from pathlib import Path
from typing import List, cast
from typing import cast

import anyio
import json5
Expand Down Expand Up @@ -31,13 +31,13 @@ class MemeItem(BaseModel):
path: str


meme_list: List[MemeItem] = []
meme_list: list[MemeItem] = []


def search_meme_items(
keyword: str,
use_regex: bool = False, # noqa: FBT001
) -> List[MemeItem]:
) -> list[MemeItem]:
if use_regex:
pattern = re.compile(keyword, re.IGNORECASE)
return [item for item in meme_list if pattern.search(item.name)]
Expand All @@ -52,7 +52,7 @@ def search_meme_items(


async def fetch_meme(path: str) -> bytes:
async with AsyncClient(proxies=config.nonememe_proxy) as cli:
async with AsyncClient(proxy=config.nonememe_proxy) as cli:
resp = await cli.get(f"{config.nonememe_repo_prefix}/{path}")
return resp.content

Expand All @@ -72,13 +72,13 @@ def build_meme_item(meme_path: str) -> MemeItem:
return MemeItem(name=path_obj.stem, suffix=path_obj.suffix, path=meme_path)


async def fetch_meme_list() -> List[MemeItem]:
async with AsyncClient(proxies=config.nonememe_proxy) as cli:
async def fetch_meme_list() -> list[MemeItem]:
async with AsyncClient(proxy=config.nonememe_proxy) as cli:
resp = await cli.get(f"{config.nonememe_repo_prefix}/static/scripts/config.js")
text = resp.text
text = text[text.find("{") : text.rfind("}") + 1]

items: List[str] = cast(dict, json5.loads(text))["items"]
items: list[str] = cast(dict, json5.loads(text))["items"]
return [build_meme_item(item) for item in items]


Expand All @@ -104,7 +104,7 @@ async def update_meme_list():

logger.warning("Failed to fetch meme list, use cache instead")
got_meme_list = type_validate_json(
List[MemeItem],
list[MemeItem],
await cache_json_path.read_text(encoding="u8"),
)

Expand Down

0 comments on commit 5e1fac1

Please sign in to comment.