nonebot-plugin-xibao 1.0.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,36 @@
1
+ Metadata-Version: 2.3
2
+ Name: nonebot-plugin-xibao
3
+ Version: 1.0.0
4
+ Summary: 喜报生成
5
+ Author: sp2dev
6
+ Author-email: theinsp2@outlook.com
7
+ Requires-Python: >=3.9, <4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: nonebot-plugin-saa (>=0.1.0)
15
+ Requires-Dist: nonebot2 (>=2.4.2,<3.0.0)
16
+ Requires-Dist: pillow (>10.0.0)
17
+ Description-Content-Type: text/markdown
18
+
19
+ # 喜(悲)报机器人
20
+
21
+ ## 安装
22
+
23
+ ```
24
+ nb plugin install nonebot-plugin-xibao
25
+ ```
26
+ ```
27
+ pip install nonebot-plugin-xibao
28
+ ```
29
+
30
+ ## 使用
31
+
32
+ 使用时记得加上前缀哦!
33
+ | 命令 | 功能 |
34
+ | --- | --- |
35
+ | `喜报` | 生成一张喜报 |
36
+ | `悲报` | 生成一张悲报 |
@@ -0,0 +1,18 @@
1
+ # 喜(悲)报机器人
2
+
3
+ ## 安装
4
+
5
+ ```
6
+ nb plugin install nonebot-plugin-xibao
7
+ ```
8
+ ```
9
+ pip install nonebot-plugin-xibao
10
+ ```
11
+
12
+ ## 使用
13
+
14
+ 使用时记得加上前缀哦!
15
+ | 命令 | 功能 |
16
+ | --- | --- |
17
+ | `喜报` | 生成一张喜报 |
18
+ | `悲报` | 生成一张悲报 |
@@ -0,0 +1,73 @@
1
+ from nonebot import on_command
2
+ from nonebot import require
3
+ from nonebot.plugin import PluginMetadata
4
+
5
+ require("nonebot_plugin_saa")
6
+
7
+ from nonebot.adapters import Message
8
+ from nonebot.params import CommandArg
9
+ import nonebot_plugin_saa as saa
10
+
11
+ from PIL import Image, ImageDraw, ImageFont
12
+
13
+ from pathlib import Path
14
+ import io
15
+
16
+ __plugin_meta__ = PluginMetadata(
17
+ name="喜(悲)报生成器",
18
+ description="生成喜报(或是悲报,管他呢)",
19
+ usage="/喜报 [文字] 生成喜报\n/悲报 [文字] 生成悲报",
20
+ type="application",
21
+ homepage="https://github.com/sp2dev/nonebot-plugin-xibao")
22
+
23
+ font_path = Path(__file__).parent / "SourceHanSans.otf"
24
+
25
+
26
+ async def _generate_image(bg_file: str, text = "", font_size = 250, text_color = "black", stroke="") -> bytes:
27
+
28
+ img_path = Path(__file__).parent / bg_file
29
+ img = Image.open(img_path)
30
+ draw = ImageDraw.Draw(img)
31
+ font = ImageFont.truetype(font_path, font_size)
32
+
33
+ bbox = draw.textbbox((0, 0), text, font=font)
34
+ text_width = bbox[2] - bbox[0]
35
+ text_height = bbox[3] - bbox[1]
36
+ image_width, image_height = img.size
37
+
38
+ x = (image_width - text_width) / 2 + font_size / 4
39
+ y = (image_height - text_height) / 2 - font_size / 4
40
+
41
+ draw.text((x, y), text, fill=text_color, font=font, stroke_fill=stroke, stroke_width=10)
42
+ output = io.BytesIO()
43
+ img.save(output, format='PNG')
44
+ return output.getvalue()
45
+
46
+
47
+ async def gen_xibao(font_size: int = 250, text: str = "") -> bytes:
48
+ return await _generate_image("xibao_bg.png", text, font_size, "red", stroke="yellow")
49
+
50
+ async def gen_beibao(font_size: int = 250, text: str = "") -> bytes:
51
+ return await _generate_image("beibao_bg.png", text, font_size, "black", stroke="white")
52
+
53
+
54
+ genxibao = on_command("喜报", aliases={"喜报:", "喜报:"} )
55
+ @genxibao.handle()
56
+ async def xibaohandle(args:Message = CommandArg()):
57
+ textinput = args.extract_plain_text()
58
+ if len(textinput) > 25:
59
+ await genbeibao.finish("字数太多啦!长度应在 25 个字符以内")
60
+ size = 250 - len(textinput) * 10
61
+ picdata = await gen_xibao(text = textinput, font_size=size)
62
+ await saa.Image(picdata).send()
63
+
64
+
65
+ genbeibao = on_command("悲报", aliases={"悲报:", "悲报:"} )
66
+ @genbeibao.handle()
67
+ async def beibaohandle(args:Message = CommandArg()):
68
+ textinput = args.extract_plain_text()
69
+ if len(textinput) > 25:
70
+ await genbeibao.finish("字数太多啦!长度应在 25 个字符以内")
71
+ size = 250 - len(textinput) * 10
72
+ picdata = await gen_beibao(text = textinput, font_size=size)
73
+ await saa.Image(picdata).send()
@@ -0,0 +1,23 @@
1
+ [project]
2
+ name = "nonebot-plugin-xibao"
3
+ version = "1.0.0"
4
+ description = "喜报生成"
5
+ readme = "README.md"
6
+ requires-python = ">=3.9, <4.0"
7
+ authors = [{ name = "sp2dev", email = "theinsp2@outlook.com" }]
8
+ dependencies = [
9
+ "nonebot2>=2.4.2,<3.0.0",
10
+ "nonebot-plugin-saa>=0.1.0",
11
+ "pillow>10.0.0"
12
+ ]
13
+
14
+ [tool.setuptools]
15
+ include = ["nonebot_plugin_xibao/SourceHanSans.otf"]
16
+
17
+ [tool.poetry.dependencies]
18
+ python = "^3.9"
19
+ nonebot2 = "^2.3.1"
20
+
21
+ [build-system]
22
+ requires = ["poetry-core>=1.0.0"]
23
+ build-backend = "poetry.core.masonry.api"