nonebot-plugin-batitle 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 MerCuJerry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.1
2
+ Name: nonebot-plugin-batitle
3
+ Version: 0.1.0
4
+ Summary: BlueArchive Title Generator
5
+ Home-page: https://github.com/MerCuJerry/nonebot-plugin-batitle
6
+ Author-Email: MerCuJerry <mercujerry@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2023 MerCuJerry
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ Project-URL: Homepage, https://github.com/MerCuJerry/nonebot-plugin-batitle
17
+ Requires-Python: >=3.11
18
+ Requires-Dist: nonebot2>=2.1.0
19
+ Requires-Dist: nonebot-adapter-onebot>=2.3.1
20
+ Requires-Dist: pillow>=10.0.1
21
+ Description-Content-Type: text/markdown
22
+
23
+ <div align="center">
24
+ <a href="https://v2.nonebot.dev/store"><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo"></a>
25
+ <br>
26
+ <p><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/NoneBotPlugin.svg" width="240" alt="NoneBotPluginText"></p>
27
+ </div>
28
+
29
+ <div align="center">
30
+
31
+ # nonebot-plugin-batitle
32
+
33
+ _✨ NoneBot 插件 碧蓝档案式标题生成器✨_
34
+
35
+
36
+ <a href="./LICENSE">
37
+ <img src="https://img.shields.io/github/license/MerCuJerry/nonebot-plugin-batitle.svg" alt="license">
38
+ </a>
39
+ <a href="https://pypi.python.org/pypi/nonebot-plugin-batitle">
40
+ <img src="https://img.shields.io/pypi/v/nonebot-plugin-batitle.svg" alt="pypi">
41
+ </a>
42
+ <img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python">
43
+
44
+ </div>
45
+
46
+ ## 📖 介绍
47
+
48
+ 这里是插件的详细介绍部分
49
+
50
+ ## 💿 安装
51
+
52
+ <details open>
53
+ <summary>使用 nb-cli 安装</summary>
54
+ 在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装
55
+
56
+ nb plugin install nonebot-plugin-batitle
57
+
58
+ </details>
59
+
60
+ <details>
61
+ <summary>使用包管理器安装</summary>
62
+ 在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令
63
+
64
+ <details>
65
+ <summary>pip</summary>
66
+
67
+ pip install nonebot-plugin-batitle
68
+ </details>
69
+ <details>
70
+ <summary>pdm</summary>
71
+
72
+ pdm add nonebot-plugin-batitle
73
+ </details>
74
+ <details>
75
+ <summary>poetry</summary>
76
+
77
+ poetry add nonebot-plugin-batitle
78
+ </details>
79
+ <details>
80
+ <summary>conda</summary>
81
+
82
+ conda install nonebot-plugin-batitle
83
+ </details>
84
+
85
+ 打开 nonebot2 项目根目录下的 `pyproject.toml` 文件, 在 `[tool.nonebot]` 部分追加写入
86
+
87
+ plugins = ["nonebot_plugin_batitle"]
88
+
89
+ </details>
90
+
91
+ ## 🎉 使用
92
+ ### 指令表
93
+ | 指令 | 权限 | 需要@ | 范围 | 说明 |
94
+ |:-----:|:----:|:----:|:----:|:----:|
95
+ | batitle (前)|(后)| 群员 | 否 | 群聊 | 使用时去掉括号 |
96
+ | ba标题 (前)|(后) | 群员 | 否 | 群聊 | 同上 |
@@ -0,0 +1,74 @@
1
+ <div align="center">
2
+ <a href="https://v2.nonebot.dev/store"><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo"></a>
3
+ <br>
4
+ <p><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/NoneBotPlugin.svg" width="240" alt="NoneBotPluginText"></p>
5
+ </div>
6
+
7
+ <div align="center">
8
+
9
+ # nonebot-plugin-batitle
10
+
11
+ _✨ NoneBot 插件 碧蓝档案式标题生成器✨_
12
+
13
+
14
+ <a href="./LICENSE">
15
+ <img src="https://img.shields.io/github/license/MerCuJerry/nonebot-plugin-batitle.svg" alt="license">
16
+ </a>
17
+ <a href="https://pypi.python.org/pypi/nonebot-plugin-batitle">
18
+ <img src="https://img.shields.io/pypi/v/nonebot-plugin-batitle.svg" alt="pypi">
19
+ </a>
20
+ <img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python">
21
+
22
+ </div>
23
+
24
+ ## 📖 介绍
25
+
26
+ 这里是插件的详细介绍部分
27
+
28
+ ## 💿 安装
29
+
30
+ <details open>
31
+ <summary>使用 nb-cli 安装</summary>
32
+ 在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装
33
+
34
+ nb plugin install nonebot-plugin-batitle
35
+
36
+ </details>
37
+
38
+ <details>
39
+ <summary>使用包管理器安装</summary>
40
+ 在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令
41
+
42
+ <details>
43
+ <summary>pip</summary>
44
+
45
+ pip install nonebot-plugin-batitle
46
+ </details>
47
+ <details>
48
+ <summary>pdm</summary>
49
+
50
+ pdm add nonebot-plugin-batitle
51
+ </details>
52
+ <details>
53
+ <summary>poetry</summary>
54
+
55
+ poetry add nonebot-plugin-batitle
56
+ </details>
57
+ <details>
58
+ <summary>conda</summary>
59
+
60
+ conda install nonebot-plugin-batitle
61
+ </details>
62
+
63
+ 打开 nonebot2 项目根目录下的 `pyproject.toml` 文件, 在 `[tool.nonebot]` 部分追加写入
64
+
65
+ plugins = ["nonebot_plugin_batitle"]
66
+
67
+ </details>
68
+
69
+ ## 🎉 使用
70
+ ### 指令表
71
+ | 指令 | 权限 | 需要@ | 范围 | 说明 |
72
+ |:-----:|:----:|:----:|:----:|:----:|
73
+ | batitle (前)|(后)| 群员 | 否 | 群聊 | 使用时去掉括号 |
74
+ | ba标题 (前)|(后) | 群员 | 否 | 群聊 | 同上 |
@@ -0,0 +1,44 @@
1
+ from nonebot import on_startswith
2
+ from nonebot.plugin import PluginMetadata
3
+ from nonebot.adapters.onebot.v11 import MessageSegment
4
+ from nonebot.params import EventPlainText, Startswith
5
+ from nonebot.matcher import Matcher
6
+ from .draw import draw_pic
7
+ from io import BytesIO
8
+
9
+ __version__ = "0.1.0"
10
+ __plugin_meta__ = PluginMetadata(
11
+ name="BlueArchive Title Generator",
12
+ description="碧蓝档案式标题生成器",
13
+ usage="碧蓝档案式标题生成器",
14
+ type="application",
15
+ homepage="https://github.com/MerCuJerry/nonebot-plugin-batitle",
16
+ supported_adapters={"~onebot.v11"},
17
+ )
18
+
19
+ batitle = ("batitle ", "ba标题 ")
20
+ batitle_matcher = on_startswith(msg=batitle, block=True, priority=5)
21
+
22
+
23
+ @batitle_matcher.handle()
24
+ async def _handler(
25
+ matcher: Matcher, str_match: str = Startswith(), key: str = EventPlainText()
26
+ ):
27
+ try:
28
+ keyword: str = key.replace(str_match, "")
29
+ if "|" in keyword:
30
+ keyword = keyword.replace("|", "|")
31
+ upper = keyword.split("|")[0].strip()
32
+ downer = keyword.split("|")[1].strip()
33
+ img_raw = draw_pic(front=upper, back=downer)
34
+ img = BytesIO()
35
+ img_raw.save(img, format="png")
36
+ img_bytes: bytes = img.getvalue()
37
+ img_raw.close()
38
+ img.close()
39
+ await matcher.finish(MessageSegment.image(img_bytes))
40
+
41
+ except OSError:
42
+ await matcher.finish("生成失败……请检查字体文件设置是否正确")
43
+ except IndexError:
44
+ await matcher.finish("生成失败……请检查命令格式是否正确")
@@ -0,0 +1,86 @@
1
+ from PIL import Image, ImageDraw, ImageFont
2
+ from pathlib import Path
3
+ from math import tan, radians
4
+
5
+ SRC_PATH = Path(__file__).parent / "src"
6
+ FONT_PATH = SRC_PATH / "Merged.otf"
7
+ HALO_PATH = SRC_PATH / "halo.png"
8
+ CROSS_PATH = SRC_PATH / "cross.png"
9
+
10
+
11
+ def draw_pic(front: str = "アリス", back: str = "Archive", dx: int = 80, dy: int = 0):
12
+ # consts and calc
13
+ fnt_size = 84
14
+ pic_width = fnt_size * (front.__len__() + back.__len__() + 2)
15
+ pic_height = fnt_size * 2 + 50
16
+ # color
17
+ blue = (18, 138, 250, 255)
18
+ gray = (43, 43, 43, 255)
19
+ white = (255, 255, 255, 255)
20
+ # load src
21
+ fnt_Hans = ImageFont.truetype(FONT_PATH.as_posix(), fnt_size)
22
+ halo = Image.open(HALO_PATH).convert("RGBA")
23
+ cross = Image.open(CROSS_PATH).convert("RGBA")
24
+ # text tilt
25
+ angle = 20
26
+ dist = pic_height * tan(radians(angle))
27
+ data = (1, tan(radians(angle)), -dist, 0, 1, 0)
28
+ #
29
+ mid: tuple(int, int) = (304, 144)
30
+ offset: int = 18
31
+ offset_2: int = 18
32
+ polygon_xy = [
33
+ (138, 428),
34
+ (mid[0] - offset, mid[1] - offset),
35
+ (mid[0] + offset, mid[1] + offset),
36
+ ]
37
+ polygon_xy_second = [
38
+ (484, 222),
39
+ (mid[0] - offset_2, mid[1] + offset_2),
40
+ (mid[0] + offset_2, mid[1] - offset_2),
41
+ ]
42
+ # resize halo
43
+ halo = halo.resize((250, 250), Image.BILINEAR)
44
+ # predraw polygon on cross
45
+ prepaint_pic = Image.new("RGBA", (500, 500), (255, 255, 255, 0))
46
+ prepaint = ImageDraw.Draw(prepaint_pic)
47
+ prepaint.polygon(polygon_xy, fill=white)
48
+ prepaint.polygon(polygon_xy_second, fill=white)
49
+ prepaint.bitmap((0, 0), cross, fill=blue)
50
+ prepaint_pic = prepaint_pic.resize((250, 250), Image.BILINEAR)
51
+ # predraw front text
52
+ front_pic = Image.new(
53
+ "RGBA", (fnt_size * (front.__len__() + 2), fnt_size * 2), (255, 255, 255, 0)
54
+ )
55
+ prepaint = ImageDraw.Draw(front_pic)
56
+ prepaint.text((0, 0), front, font=fnt_Hans, fill=blue)
57
+ front_pic = front_pic.transform(
58
+ (pic_width, pic_height), Image.AFFINE, data, Image.BILINEAR
59
+ )
60
+ front_pic = front_pic.crop(front_pic.getbbox())
61
+ # predraw back text
62
+ back_pic = Image.new(
63
+ "RGBA", (fnt_size * (back.__len__() + 2), fnt_size * 2), (255, 255, 255, 0)
64
+ )
65
+ prepaint = ImageDraw.Draw(back_pic)
66
+ prepaint.text(
67
+ (0, 0),
68
+ back,
69
+ font=fnt_Hans,
70
+ fill=gray,
71
+ stroke_width=5,
72
+ stroke_fill=white,
73
+ )
74
+ back_pic = back_pic.transform(
75
+ (pic_width, pic_height), Image.AFFINE, data, Image.BILINEAR
76
+ )
77
+ back_pic = back_pic.crop(back_pic.getbbox())
78
+ # draw pic
79
+ pic = Image.new("RGBA", (pic_width, pic_height), (255, 255, 255, 0))
80
+ paint_board = ImageDraw.Draw(pic)
81
+ pic.paste(front_pic, (10, fnt_size), front_pic)
82
+ paint_board.bitmap((front_pic.size[0]-dx, dy), halo, fill=gray)
83
+ pic.paste(back_pic, (front_pic.size[0], fnt_size-6), back_pic)# magic number dkw just -6
84
+ pic.paste(prepaint_pic, (front_pic.size[0]-dx, dy), prepaint_pic)
85
+ pic = pic.crop(pic.getbbox())
86
+ return pic.convert("RGB")
@@ -0,0 +1,31 @@
1
+ [project]
2
+ name = "nonebot-plugin-batitle"
3
+ version = "0.1.0"
4
+ description = "BlueArchive Title Generator"
5
+ authors = [
6
+ { name = "MerCuJerry", email = "mercujerry@gmail.com" },
7
+ ]
8
+ dependencies = [
9
+ "nonebot2 >= 2.1.0",
10
+ "nonebot-adapter-onebot>=2.3.1",
11
+ "pillow >= 10.0.1",
12
+ ]
13
+ requires-python = ">=3.11"
14
+ readme = "README.md"
15
+
16
+ [project.license]
17
+ file = "LICENSE"
18
+
19
+ [project.urls]
20
+ homepage = "https://github.com/MerCuJerry/nonebot-plugin-batitle"
21
+
22
+ [build-system]
23
+ requires = [
24
+ "pdm-backend",
25
+ ]
26
+ build-backend = "pdm.backend"
27
+
28
+ [tool.pdm.build]
29
+ includes = [
30
+ "nonebot_plugin_batitle",
31
+ ]
File without changes