Skip to content

Commit

Permalink
Merge pull request #82 from MinatoAquaCrews/dev-v0.4.x
Browse files Browse the repository at this point in the history
🔖 v0.4.11
  • Loading branch information
KafCoppelia authored Jun 9, 2023
2 parents 8746cdb + eddf3b9 commit ff8c244
Show file tree
Hide file tree
Showing 9 changed files with 392 additions and 435 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
stages: [commit]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.6
rev: v3.0.0-alpha.9-for-vscode
hooks:
- id: prettier
types_or: [markdown, yaml, json]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ _🙏 今日运势 🙏_
</a>

<a href="https://github.com/nonebot/nonebot2">
<img src="https://img.shields.io/badge/nonebot2-2.0.0rc1+-green">
<img src="https://img.shields.io/badge/nonebot2-2.0.0rc4+-green">
</a>

<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_fortune/releases/tag/v0.4.10.post2">
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_fortune/releases/tag/v0.4.11">
<img src="https://img.shields.io/github/v/release/MinatoAquaCrews/nonebot_plugin_fortune?color=orange">
</a>

Expand All @@ -35,9 +35,9 @@ _🙏 今日运势 🙏_

## 版本

[v0.4.10.post2](https://github.com/MinatoAquaCrews/nonebot_plugin_fortune/releases/tag/v0.4.10.post2)
[v0.4.11](https://github.com/MinatoAquaCrews/nonebot_plugin_fortune/releases/tag/v0.4.11)

⚠️ 适配nonebot2-2.0.0rc1+
⚠️ 适配nonebot2-2.0.0rc4+

👉 [如何添加自己的抽签主题资源?欢迎贡献!🙏](https://github.com/MinatoAquaCrews/nonebot_plugin_fortune/blob/master/How-to-add-new-theme.md)

Expand Down
70 changes: 41 additions & 29 deletions nonebot_plugin_fortune/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from nonebot_plugin_apscheduler import scheduler
from typing import Annotated

from nonebot import on_command, on_fullmatch, on_regex, require
from nonebot.adapters.onebot.v11 import (GROUP, GROUP_ADMIN, GROUP_OWNER,
GroupMessageEvent, Message,
MessageSegment)
from nonebot.log import logger
from nonebot.matcher import Matcher
from nonebot.params import CommandArg, Depends, RegexMatched
from nonebot.params import CommandArg, Depends, RegexStr
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata

Expand All @@ -14,34 +16,42 @@

require("nonebot_plugin_apscheduler")

__fortune_version__ = "v0.4.10.post2"
__fortune_usages__ = f'''
__fortune_version__ = "v0.4.11"
__fortune_usages__ = f"""
[今日运势/抽签/运势] 一般抽签
[xx抽签] 指定主题抽签
[指定xx签] 指定特殊角色签底,需要自己尝试哦~
[设置xx签] 设置群抽签主题
[重置主题] 重置群抽签主题
[主题列表] 查看可选的抽签主题
[查看主题] 查看群抽签主题'''.strip()
[查看主题] 查看群抽签主题""".strip()

__plugin_meta__ = PluginMetadata(
name="今日运势",
description="抽签!占卜你的今日运势🙏",
usage=__fortune_usages__,
extra={
"author": "KafCoppelia <[email protected]>",
"version": __fortune_version__
}
"version": __fortune_version__,
},
)

general_divine = on_command(
"今日运势", aliases={"抽签", "运势"}, permission=GROUP, priority=8)
specific_divine = on_regex(r"^[^/]\S+抽签$", permission=GROUP, priority=8)
limit_setting = on_regex(r"^指定(.*?)签$", permission=GROUP, priority=8)
change_theme = on_regex(r"^设置(.*?)签$", permission=SUPERUSER |
GROUP_ADMIN | GROUP_OWNER, priority=8, block=True)
reset_themes = on_regex("^重置(抽签)?主题$", permission=SUPERUSER |
GROUP_ADMIN | GROUP_OWNER, priority=8, block=True)
change_theme = on_regex(
r"^设置(.*?)签$",
permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER,
priority=8,
block=True,
)
reset_themes = on_regex(
"^重置(抽签)?主题$",
permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER,
priority=8,
block=True,
)
themes_list = on_fullmatch("主题列表", permission=GROUP, priority=8, block=True)
show_themes = on_regex("^查看(抽签)?主题$", permission=GROUP, priority=8, block=True)

Expand All @@ -60,7 +70,7 @@ async def _(event: GroupMessageEvent):


@general_divine.handle()
async def _(event: GroupMessageEvent, args: Message = CommandArg()):
async def _(event: GroupMessageEvent, args: Annotated[Message, CommandArg()]):
arg: str = args.extract_plain_text()

if "帮助" in arg[-2:]:
Expand All @@ -74,8 +84,9 @@ async def _(event: GroupMessageEvent, args: Message = CommandArg()):
await general_divine.finish("今日运势生成出错……")

if not is_first:
msg = MessageSegment.text("你今天抽过签了,再给你看一次哦🤗\n") + \
MessageSegment.image(image_file)
msg = MessageSegment.text("你今天抽过签了,再给你看一次哦🤗\n") + MessageSegment.image(
image_file
)
else:
logger.info(f"User {uid} | Group {gid} 占卜了今日运势")
msg = MessageSegment.text("✨今日运势✨\n") + \
Expand All @@ -84,16 +95,14 @@ async def _(event: GroupMessageEvent, args: Message = CommandArg()):
await general_divine.finish(msg, at_sender=True)


async def get_user_theme(matcher: Matcher, args: str = RegexMatched()) -> str:
arg: str = args[:-2]
if len(arg) < 1:
@specific_divine.handle()
async def _(
matcher: Matcher, event: GroupMessageEvent, user_themes: Annotated[str, RegexStr()]
):
user_theme: str = user_themes[:-2]
if len(user_theme) < 1:
await matcher.finish("输入参数错误")

return arg


@specific_divine.handle()
async def _(event: GroupMessageEvent, user_theme: str = Depends(get_user_theme)):
for theme in FortuneThemesDict:
if user_theme in FortuneThemesDict[theme]:
if not FortuneManager.theme_enable_check(theme):
Expand All @@ -109,18 +118,20 @@ async def _(event: GroupMessageEvent, user_theme: str = Depends(get_user_theme))

if not is_first:
msg = MessageSegment.text(
"你今天抽过签了,再给你看一次哦🤗\n") + MessageSegment.image(image_file)
"你今天抽过签了,再给你看一次哦🤗\n"
) + MessageSegment.image(image_file)
else:
logger.info(f"User {uid} | Group {gid} 占卜了今日运势")
msg = MessageSegment.text(
"✨今日运势✨\n") + MessageSegment.image(image_file)
msg = MessageSegment.text("✨今日运势✨\n") + MessageSegment.image(
image_file
)

await specific_divine.finish(msg, at_sender=True)

await specific_divine.finish("还没有这种抽签主题哦~")


async def get_user_arg(matcher: Matcher, args: str = RegexMatched()) -> str:
async def get_user_arg(matcher: Matcher, args: Annotated[str, RegexStr()]) -> str:
arg: str = args[2:-1]
if len(arg) < 1:
await matcher.finish("输入参数错误")
Expand All @@ -129,7 +140,7 @@ async def get_user_arg(matcher: Matcher, args: str = RegexMatched()) -> str:


@change_theme.handle()
async def _(event: GroupMessageEvent, user_theme: str = Depends(get_user_arg)):
async def _(event: GroupMessageEvent, user_theme: Annotated[str, Depends(get_user_arg)]):
gid: str = str(event.group_id)

for theme in FortuneThemesDict:
Expand All @@ -143,7 +154,7 @@ async def _(event: GroupMessageEvent, user_theme: str = Depends(get_user_arg)):


@limit_setting.handle()
async def _(event: GroupMessageEvent, limit: str = Depends(get_user_arg)):
async def _(event: GroupMessageEvent, limit: Annotated[str, Depends(get_user_arg)]):
logger.warning("指定签底抽签功能将在 v0.5.x 弃用")

gid: str = str(event.group_id)
Expand All @@ -164,8 +175,9 @@ async def _(event: GroupMessageEvent, limit: str = Depends(get_user_arg)):
await limit_setting.finish("今日运势生成出错……")

if not is_first:
msg = MessageSegment.text("你今天抽过签了,再给你看一次哦🤗\n") + \
MessageSegment.image(image_file)
msg = MessageSegment.text("你今天抽过签了,再给你看一次哦🤗\n") + MessageSegment.image(
image_file
)
else:
logger.info(f"User {uid} | Group {gid} 占卜了今日运势")
msg = MessageSegment.text("✨今日运势✨\n") + \
Expand Down
Loading

0 comments on commit ff8c244

Please sign in to comment.