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 6c6e219 commit ac20d9c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 28 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ _✨ 看看 NoneBot 群大佬们的日常 ✨_

<br />

<a href="https://pydantic.dev">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/pyd-v1-or-v2.json" alt="Pydantic Version 1 Or 2" >
</a>
<a href="./LICENSE">
<img src="https://img.shields.io/github/license/lgc-NB2Dev/nonebot-plugin-nonememe.svg" alt="license">
</a>
Expand Down Expand Up @@ -145,6 +148,11 @@ Telegram:[@lgc2333](https://t.me/lgc2333)

## 📝 更新日志

### 0.3.0

- 适配 Pydantic V1 & V2
- 换用 alconna

### 0.2.0

- 自动更新图片列表
Expand Down
6 changes: 3 additions & 3 deletions nonebot_plugin_nonememe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from nonebot.plugin import PluginMetadata, inherit_supported_adapters

require("nonebot_plugin_apscheduler")
require("nonebot_plugin_saa")
require("nonebot_plugin_alconna")

from . import __main__ as __main__ # noqa: E402
from .config import ConfigModel # noqa: E402

__version__ = "0.2.0"
__version__ = "0.3.0"
__plugin_meta__ = PluginMetadata(
name="NoneMeme",
description="NoneBot 群大佬的日常",
Expand All @@ -18,6 +18,6 @@
type="application",
homepage="https://github.com/lgc-NB2Dev/nonebot-plugin-nonememe",
config=ConfigModel,
supported_adapters=inherit_supported_adapters("nonebot_plugin_saa"),
supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna"),
extra={"License": "MIT", "Author": "student_2333"},
)
20 changes: 12 additions & 8 deletions nonebot_plugin_nonememe/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from typing import List, NoReturn

from nonebot import logger, on_command
from nonebot.adapters import Message
from nonebot.internal.adapter import Event
from nonebot.adapters import Event, Message
from nonebot.exception import FinishedException
from nonebot.matcher import Matcher
from nonebot.params import CommandArg
from nonebot.typing import T_State
from nonebot_plugin_saa import Image, MessageFactory, Text
from nonebot_plugin_alconna.uniseg import UniMessage

from .config import config
from .data_source import MemeItem, get_meme, meme_list, search_meme_items
Expand All @@ -16,12 +16,16 @@
async def finish_with_meme(meme_item: MemeItem) -> NoReturn:
try:
image_bytes = await get_meme(meme_item)
except Exception:
except Exception as e:
logger.exception("Failed to get meme")
await MessageFactory("获取图片失败,请检查后台日志").finish()
await MessageFactory(
[Text(f"# {meme_item.name}"), Image(image_bytes)],
).finish(reply=True)
await UniMessage("获取图片失败,请检查后台日志").send()
raise FinishedException from e
await (
UniMessage.text(f"# {meme_item.name}")
.image(raw=image_bytes)
.send(reply_to=True)
)
raise FinishedException


cmd_meme = on_command("nonememe", aliases={"nb草图", "nb梗图"})
Expand Down
24 changes: 12 additions & 12 deletions nonebot_plugin_nonememe/config.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from typing import Optional, Union
from typing_extensions import NotRequired, TypedDict
from typing_extensions import TypedDict

from nonebot import get_driver
from nonebot import get_plugin_config
from pydantic import BaseModel


class CronDict(TypedDict):
year: NotRequired[Union[str, int]]
month: NotRequired[Union[str, int]]
day: NotRequired[Union[str, int]]
week: NotRequired[Union[str, int]]
day_of_week: NotRequired[Union[str, int]]
hour: NotRequired[Union[str, int]]
minute: NotRequired[Union[str, int]]
second: NotRequired[Union[str, int]]
class CronDict(TypedDict, total=False):
year: Union[str, int]
month: Union[str, int]
day: Union[str, int]
week: Union[str, int]
day_of_week: Union[str, int]
hour: Union[str, int]
minute: Union[str, int]
second: Union[str, int]


class ConfigModel(BaseModel):
Expand All @@ -26,4 +26,4 @@ class ConfigModel(BaseModel):
nonememe_search_limit: int = 5


config: ConfigModel = ConfigModel.parse_obj(get_driver().config.dict())
config = get_plugin_config(ConfigModel)
5 changes: 3 additions & 2 deletions nonebot_plugin_nonememe/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import json5
from httpx import AsyncClient
from nonebot import get_driver, logger
from nonebot.compat import type_validate_json
from nonebot_plugin_apscheduler import scheduler
from pydantic import BaseModel, parse_raw_as
from pydantic import BaseModel

from .config import config

Expand Down Expand Up @@ -102,7 +103,7 @@ async def update_meme_list():
raise

logger.warning("Failed to fetch meme list, use cache instead")
got_meme_list = parse_raw_as(
got_meme_list = type_validate_json(
List[MemeItem],
await cache_json_path.read_text(encoding="u8"),
)
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[project]
name = "nonebot-plugin-nonememe"
version = "0.2.0.post4"
dynamic = ["version"]
description = "The daily life of the NoneBot group members"
authors = [{ name = "student_2333", email = "[email protected]" }]
dependencies = [
"nonebot2>=2.2.0",
"nonebot-plugin-send-anything-anywhere>=0.3.2",
"nonebot-plugin-alconna>=0.40.0rc1",
"nonebot-plugin-apscheduler>=0.3.0",
"pydantic>=1.10.0,<2",
"httpx>=0.24.1",
"json5>=0.9.14",
"anyio>=3.6.2",
Expand All @@ -23,6 +22,10 @@ homepage = "https://github.com/lgc-NB2Dev/nonebot-plugin-nonememe"
[tool.pdm.build]
includes = []

[tool.pdm.version]
source = "file"
path = "nonebot_plugin_nonememe/__init__.py"

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

0 comments on commit ac20d9c

Please sign in to comment.