Skip to content

Commit

Permalink
Merge branch 'dev' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
KafCoppelia authored Dec 5, 2023
2 parents 4b510d8 + 7c3d234 commit 793e8ba
Show file tree
Hide file tree
Showing 15 changed files with 1,575 additions and 668 deletions.
6 changes: 4 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ categories:
- title: "🧰 Maintenance"
label: "chore"

change-template: "- $TITLE @$AUTHOR (#$NUMBER)"
name-template: "v$RESOLVED_VERSION"
tag-template: "v$RESOLVED_VERSION"
change-template: "- $TITLE [@$AUTHOR](https://github.com/$AUTHOR) ([#$NUMBER]($URL))"
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
Expand All @@ -32,4 +34,4 @@ template: |
$CHANGES
Changelog: [`$PREVIOUS_TAG...`](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/compare/$PREVIOUS_TAG...)
Changelog: [`$PREVIOUS_TAG...v$RESOLVED_VERSION`](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION)
5 changes: 2 additions & 3 deletions .github/workflows/poetry-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ env.TAG_NAME }}

- name: Publish python poetry package
uses: JRubics/poetry-publish@v1.16
uses: JRubics/poetry-publish@v1.17
with:
python_version: "3.10"
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
build_format: "wheel"
ignore_dev_requirements: "yes"
10 changes: 6 additions & 4 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ name: Release Drafter

on:
push:
tags:
- v*
pull_request_target:
branches:
- master

pull_request:
types: [opened, reopened, synchronize]
types:
- closed

permissions:
contents: read
Expand All @@ -19,7 +21,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: master

Expand Down
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ repos:
- id: isort
stages: [commit]

- repo: https://github.com/hhatto/autopep8
rev: v2.0.4
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: autopep8
- id: black
stages: [commit]

- repo: https://github.com/pre-commit/mirrors-prettier
Expand All @@ -34,3 +34,9 @@ repos:
- id: check-added-large-files
- id: mixed-line-ending
- id: check-json

- repo: https://github.com/python-poetry/poetry
rev: 1.6.1
hooks:
- id: poetry-check
- id: poetry-lock
12 changes: 5 additions & 7 deletions How-to-add-new-tarot-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@

1. 该功能对**图片后缀无要求**

2. 如果你有完整的塔罗牌资源,请根据[资源说明](./README.md#资源说明)`./resource/BilibiliTarot` 的目录结构将塔罗牌分类并**建立对应目录**,并**重命名**塔罗牌图片文件
2. 如果你有完整的塔罗牌资源,请根据[资源说明](./README.md#资源说明)`./resource/BilibiliTarot` 的目录结构将塔罗牌分类并**建立对应目录**,并**重命名**塔罗牌图片文件与其保持一致

```python
["MajorArcana", "Cups", "Pentacles", "Sowrds", "Wands"]
```

3. 如果塔罗牌资源不完整也没关系,但请确保**每个子类资源完整**。例如,我有新的塔罗牌主题 `NameOfNewTheme`,但仅有大阿卡纳22张,及圣杯15张,则建立如下 `NameOfNewTheme` 子目录:
3. 如果塔罗牌资源不完整也没关系,但请确保**每个子类资源完整**。例如,我有新的塔罗牌主题 `NewTarotTheme`,但仅有大阿卡纳22张,及圣杯15张,则建立如下 `NewTarotTheme` 子目录:

```
MyTarotResource
├ BilibiliTarot
│ └ ……
├ TouhouTarot
│ └ ……
└ NameOfNewTheme
└ NewTarotTheme
├ Cups
│ ├ 圣杯-01.png
│ ├ 圣杯-02.png
Expand All @@ -31,9 +29,9 @@
└ 21-世界.png
```

将其放入 `TAROT_PATH` 目录下即可。例如,以上示例**所有的塔罗牌资源**均在 `MyTarotResource` 目录下,则设置:
将其放入 `TAROT_PATH` 目录下即可。例如,上述示例中**所有的塔罗牌资源**均在 `MyTarotResource` 目录下,则设置:

```
```toml
TAROT_PATH="your-path-to-MyTarotResource"
```

Expand Down
78 changes: 59 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ _🔮 塔罗牌 🔮_

<p align="center">

<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/MinatoAquaCrews/nonebot_plugin_tarot?color=blue">
<a href="https://github.com/nonebot/nonebot2">
<img src="https://img.shields.io/badge/nonebot2-2.0.0+-green">
</a>

<a href="https://github.com/nonebot/nonebot2">
<img src="https://img.shields.io/badge/nonebot2-2.0.0b3+-green">
<a href="https://onebot.dev/">
<img src="https://img.shields.io/badge/OneBot-v11-black?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg==" alt="onebot">
</a>

<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.4.0.post4">
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.5.0a3">
<img src="https://img.shields.io/github/v/release/MinatoAquaCrews/nonebot_plugin_tarot?color=orange">
</a>

Expand All @@ -40,31 +40,71 @@ _“许多傻瓜对千奇百怪的迷信说法深信不疑:象牙、护身符

## 版本

🧰 [v0.4.0.post4](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.4.0.post4)
🧰 [v0.5.0a3](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.5.0a3)

⚠ 适配nonebot2-2.0.0b3+

👉 [如何添加新的塔罗牌主题资源?](./How-to-add-new-tarot-theme.md)欢迎贡献!🙏
⚠ 适配nonebot2-2.0.0+

## 安装

1. 通过 `pip``nb` 安装。pypi无法发行过大安装包,由此安装的插件不包含 `./resource`**所有塔罗牌主题资源**。请在[v0.4.0 release](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.4.0)页面下载各主题资源,部署至本地后修改 `TAROT_PATH` 配置即可;
1. 安装方式
- 通过 `pip``nb-cli` 安装。pypi无法发行过大安装包,由此安装的插件不包含 `./resource` 下提供的塔罗牌主题资源。仓库提供了两种塔罗牌主题,可在 [v0.4.0 release](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.4.0) Assets下载,部署至本地后修改 `TAROT_PATH` 配置即可;

- 通过 `zip``git clone` 安装:包含 `resource` 下所有塔罗牌主题资源;

2. `CHAIN_REPLY` 设置全局群聊转发模式(避免刷屏),可通过命令开启或关闭,默认开启;

2. `env` 下设置 `TAROT_PATH` 以更改资源路径`CHAIN_REPLY` 设置全局群聊转发模式(避免刷屏),亦可通过命令修改;`TAROT_AUTO_UPDATE` 开启则插件将在启动时自动检查更新(默认关闭)。例如:
3. `env` 下设置 `TAROT_PATH` 以更改资源路径,该目录下存放各塔罗牌主题图片(子目录表示不同主题)。默认为 `nonebot_plugin_localstore` 为本插件提供的路径。例如:

```python
TAROT_PATH="path-to-your-resource"
```toml
TAROT_PATH="path-to-MyTarotResource"
CHAIN_REPLY=false
TAROT_AUTO_UPDATE=false
```

⚠ 请为塔罗牌资源分配单独的目录存放!即某一目录下仅有塔罗牌的所有资源。[#26](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/issues/26)
```
MyTarotResource
├ BilibiliTarot
│ └ ……
└ TouhouTarot
└ ……
```

4. 用户应启用**至少一种主题**。仓库提供了两种主题,但仅将 `BilibiliTarot` 作为插件**内置主题**(另一主题主题可选)。配置项 `TAROT_BUILTIN_THEME_ENABLED` 以启用(默认开启)内置主题。该配置项可配合 `TAROT_EXTRA_THEMES` 使用。

```toml
# 错误!无可用主题!
TAROT_BUILTIN_THEME_ENABLED=false
TAROT_EXTRA_THEMES=[]

3. 启动时,插件会自动下载repo中最新的 `tarot.json` 文件,`tarot.json` 不一定随插件版本更新;
# 正确!仅使用插件内置主题BilibiliTarot
TAROT_BUILTIN_THEME_ENABLED=true
TAROT_EXTRA_THEMES=[]

4. 图片资源可选择**不部署在本地**,插件会自动尝试从repo中下载缓存。
# 正确!仅使用用户提供的主题MyTarotTheme
TAROT_BUILTIN_THEME_ENABLED=false
TAROT_EXTRA_THEMES=["MyTarotTheme"]

# 正确!使用插件内置主题BilibiliTarot与额外的主题TouhouTarot
TAROT_BUILTIN_THEME_ENABLED=true
TAROT_EXTRA_THEMES=["TouhouTarot"]
```

5. 图片资源可选择**不部署在本地**,此时,如果所需主题为仓库提供的两种主题之一,则会尝试下载并缓存。此外,用户也可以添加自己的塔罗牌主题。配置项 `TAROT_EXTRA_THEMES` 用以添加本地部署的自定义主题。例如,用户额外添加了两个主题,则对应目录结构为:

```toml
TAROT_PATH="path-to-MyTarotResource"
TAROT_EXTRA_THEMES=["MyTarotTheme1", "MyTarotTheme2"]
```
```
MyTarotResource
├ MyTarotTheme1
│ └ ……
└ MyTarotTheme2
└ ……
```

⚠ 使用 `raw.fgit.ml` 进行下载,不确保次次成功
⚠ 使用 `ghproxy.com` 下载仓库提供的主题,不确保次次成功

👉 [如何添加新的塔罗牌主题资源?](./How-to-add-new-tarot-theme.md) 欢迎贡献!🙏

## 命令

Expand All @@ -83,7 +123,7 @@ _“许多傻瓜对千奇百怪的迷信说法深信不疑:象牙、护身符

⚠ 资源中额外四张王牌(Ace)不在体系中,因此不会在占卜时用到,因为小阿卡纳中各系均有Ace牌,但可以自行收藏。

2. `tarot.json`中对牌阵,抽牌张数、是否有切牌、各牌正逆位解读进行说明。`cards` 字段下对所有塔罗牌做了正逆位含义与资源路径的说明;
2. `tarot.json` 中对牌阵,抽牌张数、是否有切牌、各牌正逆位解读进行说明。`cards` 字段下对所有塔罗牌做了正逆位含义与资源路径的说明;

3. 根据牌阵的不同有不同的塔罗牌解读,同时也与问卜者的问题、占卜者的解读等因素相关,因此不存在所谓的解读方式正确与否。`cards` 字段下的正逆位含义参考以下以及其他网络资源:

Expand Down
71 changes: 50 additions & 21 deletions nonebot_plugin_tarot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,94 @@
from nonebot import on_command, on_regex
from nonebot import require

from nonebot.adapters.onebot.v11 import Bot
from nonebot.adapters.onebot.v11.event import GroupMessageEvent, MessageEvent
from nonebot.adapters.onebot.v11.event import (
GroupMessageEvent,
MessageEvent,
PrivateMessageEvent,
)
from nonebot.matcher import Matcher
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata

require("nonebot_plugin_localstore") # isort:skip

from .config import PluginConfig
from .data_source import tarot_manager

__tarot_version__ = "v0.4.0.post4"
__tarot_usages__ = f'''
塔罗牌 {__tarot_version__}
__plugin_version__ = "v0.5.0a3"
__plugin_usages__ = f"""
塔罗牌 {__plugin_version__}
[占卜] 随机选取牌阵进行占卜
[塔罗牌] 得到单张塔罗牌回应
[开启/启用/关闭/禁用]群聊转发 开启或关闭全局群聊转发'''.strip()
[开启/启用/关闭/禁用]群聊转发 开启或关闭全局群聊转发""".strip()

__plugin_meta__ = PluginMetadata(
name="塔罗牌",
description="塔罗牌!魔法占卜🔮",
usage=__tarot_usages__,
usage=__plugin_usages__,
type="application",
homepage="https://github.com/MinatoAquaCrews/nonebot_plugin_tarot",
config=PluginConfig,
extra={
"author": "KafCoppelia <[email protected]>",
"version": __tarot_version__
}
"version": __plugin_version__,
},
supported_adapters={"~onebot.v11"},
)

divine = on_command(cmd="占卜", priority=7)
tarot = on_command(cmd="塔罗牌", priority=7)
chain_reply_switch = on_regex(
pattern=r"^(开启|启用|关闭|禁用)群聊转发(模式)?$", permission=SUPERUSER, priority=7, block=True)
pattern=r"^(开启|启用|关闭|禁用)群聊转发(模式)?$", permission=SUPERUSER, priority=7, block=True
)


@divine.handle()
async def general_divine_in_group(
bot: Bot, matcher: Matcher, event: GroupMessageEvent
) -> None:
arg = event.get_plaintext()

if "帮助" in arg[-2:]:
await matcher.finish(__plugin_usages__)

await tarot_manager.divine_in_group(bot, matcher, event.group_id)


@divine.handle()
async def general_divine(bot: Bot, matcher: Matcher, event: MessageEvent):
arg: str = event.get_plaintext()
async def general_divine_in_private(
matcher: Matcher, event: PrivateMessageEvent
) -> None:
arg = event.get_plaintext()

if "帮助" in arg[-2:]:
await matcher.finish(__tarot_usages__)
await matcher.finish(__plugin_usages__)

await tarot_manager.divine(bot, matcher, event)
await tarot_manager.divine_in_private(matcher)


@tarot.handle()
async def _(matcher: Matcher, event: MessageEvent):
arg: str = event.get_plaintext()
arg = event.get_plaintext()

if "帮助" in arg[-2:]:
await matcher.finish(__tarot_usages__)
await matcher.finish(__plugin_usages__)

msg = await tarot_manager.onetime_divine()
msg = await tarot_manager.get_one_tarot()
await matcher.finish(msg)


@chain_reply_switch.handle()
async def _(event: GroupMessageEvent):
arg: str = event.get_plaintext()
arg = event.get_plaintext()
base = "占卜群聊转发模式已{0}~"

if arg[:2] == "开启" or arg[:2] == "启用":
tarot_manager.switch_chain_reply(True)
msg = "占卜群聊转发模式已开启~"
tarot_manager.is_chain_reply = True
msg = base.format("开启")
else:
tarot_manager.switch_chain_reply(False)
msg = "占卜群聊转发模式已关闭~"
tarot_manager.is_chain_reply = False
msg = base.format("关闭")

await chain_reply_switch.finish(msg)
Loading

0 comments on commit 793e8ba

Please sign in to comment.