Skip to content

Commit

Permalink
⚡️ v0.4.10a1: change sign-in check
Browse files Browse the repository at this point in the history
  • Loading branch information
KafCoppelia committed Jan 9, 2023
1 parent 72ec411 commit 1fc411a
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 271 deletions.
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ v0.4.10a1
SAKURA_FLAG=true # 樱色之云绯色之恋
SUMMER_POCKETS_FLAG=false # 夏日口袋
AMAZING_GRACE_FLAG=false # 奇异恩典·圣夜的小镇
ARK_ORDER_FLAG=true # 方舟指令换装皮肤
```

**请确保不全为`false`,否则会抛出错误**
Expand Down Expand Up @@ -110,7 +109,7 @@ v0.4.10a1

*group_rule会自动生成,specific_rule可手动配置*

⚠️ 将在`v0.5.x`弃用
⚠️ 将在`v0.5.0`弃用

指定凯露签,由于存在两张凯露的签底,配置凯露签的**路径列表**即可;其余类似,**请确保图片路径、格式输入正确**

Expand All @@ -134,13 +133,13 @@ v0.4.10a1

7. 插件启动时将自动检查抽签主题启用情况,当全部为`false`会抛出错误。

8. TODO in `v0.5.x`
8. TODO in `v0.5.0`

- [ ] 优化设置主题、指定主题、及检索的方式;
- [ ] 文案排版算法;
- [ ] 新增功能:每日星座运势;
- [x] 新增功能:资源缺失检查、自动下载;
- [x] 新增资源:新的抽签主题资源!方舟指令
- [ ] 新增资源:新的抽签主题资源!

## 命令

Expand All @@ -150,7 +149,7 @@ v0.4.10a1

3. 指定签底并抽签:指定[xxx]签,在`./resource/fortune_setting.json`内手动配置;

⚠️ 将在`v0.5.x`弃用
⚠️ 将在`v0.5.0`弃用

4. [群管或群主或超管] 配置抽签主题:

Expand All @@ -160,11 +159,9 @@ v0.4.10a1

5. 抽签设置:查看当前群抽签主题的配置;

6. [超管] 刷新抽签:全局即刻刷新抽签,防止过0点未刷新
6. 今日运势帮助:显示插件帮助文案

7. 今日运势帮助:显示插件帮助文案;

8. 查看(抽签)主题:显示当前已启用主题;
7. 查看(抽签)主题:显示当前已启用主题;

## 效果

Expand All @@ -184,8 +181,6 @@ v0.4.10a1

3. 东方归言录(Touhou Lostword):[KafCoppelia](https://github.com/KafCoppelia);

4. 方舟指令(Ark Order):[KafCoppelia](https://github.com/KafCoppelia);

5. [FloatTech-zbpdata/Fortune](https://github.com/FloatTech/zbpdata):其余主题签;
4. [FloatTech-zbpdata/Fortune](https://github.com/FloatTech/zbpdata):其余主题签;

6. 运势文案:[KafCoppelia](https://github.com/KafCoppelia)。`copywriting.json` 整合了関係運、全体運、勉強運、金運、仕事運、恋愛運、総合運、大吉、中吉、小吉、吉、半吉、末吉、末小吉、凶、小凶、半凶、末凶、大凶及700+条运势文案!来源于Hololive早安系列2019年第6.109.22期,有修改。
5. 运势文案:[KafCoppelia](https://github.com/KafCoppelia)。`copywriting.json` 整合了関係運、全体運、勉強運、金運、仕事運、恋愛運、総合運、大吉、中吉、小吉、吉、半吉、末吉、末小吉、凶、小凶、半凶、末凶、大凶及700+条运势文案!来源于Hololive早安系列2019年第6.109.22期,有修改。
102 changes: 54 additions & 48 deletions nonebot_plugin_fortune/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,92 +32,100 @@
}
)

divine = on_command("今日运势", aliases={"抽签", "运势"}, permission=GROUP, priority=8)
divine_specific = on_regex(r"^[^/]\S+抽签$", permission=GROUP, priority=8)
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)
theme_setting = on_regex(r"^设置(.*?)签$", permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER, priority=8, block=True)
reset = on_regex("^重置(抽签)?主题$", permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER, priority=8, block=True)
theme_list = on_fullmatch("主题列表", permission=GROUP, priority=8, block=True)
show = on_regex("^查看(抽签)?主题$", permission=GROUP, priority=8, block=True)
refresh = on_fullmatch("刷新抽签", permission=SUPERUSER, priority=7, block=True)


@show.handle()
async def _(event: GroupMessageEvent):
gid: str = str(event.group_id)
theme: str = fortune_manager.get_group_theme(gid)
await show.finish(f"当前群抽签主题:{FortuneThemesDict[theme][0]}")


@theme_list.handle()
async def _(event: GroupMessageEvent):
msg: str = fortune_manager.get_main_theme_list()
await theme_list.finish(msg)

@divine.handle()

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

if "帮助" in arg[-2:]:
await divine.finish(__fortune_usages__)
await general_divine.finish(__fortune_usages__)

gid: str = str(event.group_id)
uid: str = str(event.user_id)
nickname: str = event.sender.card if event.sender.card else event.sender.nickname

is_first, image_file = fortune_manager.divine(gid, uid, nickname, None, None)

is_first, image_file = fortune_manager.divine(gid, uid, None, None)
if not image_file:
await divine.finish("今日运势生成出错……")
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 {event.user_id} | Group {event.group_id} 占卜了今日运势")
msg = MessageSegment.text("✨今日运势✨\n") + MessageSegment.image(image_file)

await divine.finish(msg, at_sender=True)
msg = MessageSegment.text("✨今日运势✨\n") + \
MessageSegment.image(image_file)

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:
await matcher.finish("输入参数错误")

return arg

@divine_specific.handle()

@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 fortune_manager.theme_enable_check(theme):
await divine_specific.finish("该抽签主题未启用~")
await specific_divine.finish("该抽签主题未启用~")
else:
gid: str = str(event.group_id)
uid: str = str(event.user_id)
nickname: str = event.sender.card if event.sender.card else event.sender.nickname

is_first, image_file = fortune_manager.divine(gid, uid, nickname, theme, None)

is_first, image_file = fortune_manager.divine(
gid, uid, theme, None)
if not image_file:
await divine_specific.finish("今日运势生成出错……")
await specific_divine.finish("今日运势生成出错……")

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

await divine_specific.finish(msg, at_sender=True)

await divine_specific.finish("还没有这种抽签主题哦~")
await specific_divine.finish(msg, at_sender=True)

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


async def get_user_arg(matcher: Matcher, args: str = RegexMatched()) -> str:
arg: str = args[2:-1]
if len(arg) < 1:
await matcher.finish("输入参数错误")

return arg



@theme_setting.handle()
async def _(event: GroupMessageEvent, user_theme: str = Depends(get_user_arg)):
gid: str = str(event.group_id)

for theme in FortuneThemesDict:
if user_theme in FortuneThemesDict[theme]:
if not fortune_manager.divination_setting(theme, gid):
Expand All @@ -127,50 +135,48 @@ async def _(event: GroupMessageEvent, user_theme: str = Depends(get_user_arg)):

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


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

gid: str = str(event.group_id)
uid: str = str(event.user_id)
nickname: str = event.sender.card if event.sender.card else event.sender.nickname


if limit == "随机":
is_first, image_file = fortune_manager.divine(gid, uid, nickname, None, None)
is_first, image_file = fortune_manager.divine(gid, uid, None, None)
if not image_file:
await limit_setting.finish("今日运势生成出错……")
await limit_setting.finish("今日运势生成出错……")
else:
spec_path = fortune_manager.specific_check(limit)
if not spec_path:
await limit_setting.finish("还不可以指定这种签哦,请确认该签底对应主题开启或图片路径存在~")
else:
is_first, image_file = fortune_manager.divine(gid, uid, nickname, None, spec_path)
is_first, image_file = fortune_manager.divine(
gid, uid, None, spec_path)
if not image_file:
await limit_setting.finish("今日运势生成出错……")
await limit_setting.finish("今日运势生成出错……")

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

await limit_setting.finish(msg, at_sender=True)


@reset.handle()
async def _(event: GroupMessageEvent):
gid: str = str(event.group_id)
if not fortune_manager.divination_setting("random", gid):
await reset.finish("重置群抽签主题失败!")

await reset.finish("已重置当前群抽签主题为随机~")

@refresh.handle()
async def _():
fortune_manager.reset_fortune()
await refresh.finish("今日运势已刷新!")

# 重置每日占卜

# 清空昨日生成的图片
@scheduler.scheduled_job("cron", hour=0, minute=0, misfire_grace_time=60)
async def _():
fortune_manager.reset_fortune()
logger.info("今日运势已刷新!")
fortune_manager.clean_out_pics()
logger.info("昨日运势图片已清空!")
Loading

0 comments on commit 1fc411a

Please sign in to comment.