-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from MinatoAquaCrews/dev-v0.4.x
🔖 v0.4.11
- Loading branch information
Showing
9 changed files
with
392 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
@@ -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) | ||
|
||
|
@@ -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:]: | ||
|
@@ -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") + \ | ||
|
@@ -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): | ||
|
@@ -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("输入参数错误") | ||
|
@@ -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: | ||
|
@@ -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) | ||
|
@@ -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") + \ | ||
|
Oops, something went wrong.