大变:移动了很多很多文件并优化构建流程
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-09-30 02:23:40 +08:00
parent 3b8b060c5b
commit 6e0082c1c9
28 changed files with 28 additions and 30 deletions

View File

@ -30,11 +30,7 @@ steps:
image: docker:dind image: docker:dind
privileged: true privileged: true
commands: commands:
- docker login -u kagami-ci -p ${KAGAMI_CI_PASSWORD} gitea.service.jazzwhom.top - docker run --rm gitea.service.jazzwhom.top/mttu-developers/konabot:nightly-${DRONE_COMMIT_SHA} python scripts/test_plugin_load.py
- docker run --rm gitea.service.jazzwhom.top/mttu-developers/konabot:nightly-${DRONE_COMMIT_SHA} python test_plugin_load.py
environment:
KAGAMI_CI_PASSWORD:
from_secret: KAGAMI-CI-PASSWORD
volumes: volumes:
- name: docker-socket - name: docker-socket

View File

@ -4,5 +4,8 @@ WORKDIR /app
COPY requirements.txt ./ COPY requirements.txt ./
RUN pip install -r requirements.txt --no-deps RUN pip install -r requirements.txt --no-deps
COPY . . COPY bot.py ./
COPY assets ./
COPY scripts ./
COPY konabot ./
CMD [ "python", "bot.py" ] CMD [ "python", "bot.py" ]

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

Before

Width:  |  Height:  |  Size: 219 KiB

After

Width:  |  Height:  |  Size: 219 KiB

View File

Before

Width:  |  Height:  |  Size: 272 KiB

After

Width:  |  Height:  |  Size: 272 KiB

4
konabot/common/path.py Normal file
View File

@ -0,0 +1,4 @@
from pathlib import Path
ASSETS_PATH = Path(__file__).resolve().parent.parent.parent / "assets"
FONTS_PATH = ASSETS_PATH / "fonts"

View File

@ -1,8 +1,8 @@
from imagetext_py import EmojiOptions, FontDB from imagetext_py import EmojiOptions, FontDB
from .path import ASSETS from konabot.common.path import FONTS_PATH
FontDB.LoadFromDir(str(ASSETS)) FontDB.LoadFromDir(str(FONTS_PATH))
FontDB.SetDefaultEmojiOptions(EmojiOptions( FontDB.SetDefaultEmojiOptions(EmojiOptions(
parse_shortcodes=False, parse_shortcodes=False,

View File

@ -1,3 +0,0 @@
from pathlib import Path
ASSETS = Path(__file__).parent.parent.parent / "assets"

View File

@ -4,10 +4,11 @@ from typing import Any, cast
import imagetext_py import imagetext_py
import PIL.Image import PIL.Image
from .base.fonts import HARMONYOS_SANS_SC_BLACK from konabot.common.path import ASSETS_PATH
from .base.path import ASSETS
geimao_image = PIL.Image.open(ASSETS / "geimao.jpg").convert("RGBA") from .base.fonts import HARMONYOS_SANS_SC_BLACK
geimao_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "geimao.jpg").convert("RGBA")
def _draw_geimao(saying: str): def _draw_geimao(saying: str):

View File

@ -3,10 +3,11 @@ import asyncio
import imagetext_py import imagetext_py
import PIL.Image import PIL.Image
from .base.fonts import HARMONYOS_SANS_SC_REGULAR from konabot.common.path import ASSETS_PATH
from .base.path import ASSETS
pt_image = PIL.Image.open(ASSETS / "ptsay.png").convert("RGBA") from .base.fonts import HARMONYOS_SANS_SC_REGULAR
pt_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "ptsay.png").convert("RGBA")
def _draw_pt(saying: str): def _draw_pt(saying: str):

View File

@ -1,9 +1,11 @@
from io import BytesIO from io import BytesIO
import cv2 import cv2
import numpy as np import numpy as np
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
from konabot.plugins.roll_dice.base.path import ASSETS from konabot.common.path import ASSETS_PATH, FONTS_PATH
def text_to_transparent_image(text, font_size=40, padding=0, text_color=(0, 0, 0)): def text_to_transparent_image(text, font_size=40, padding=0, text_color=(0, 0, 0)):
""" """
@ -13,15 +15,7 @@ def text_to_transparent_image(text, font_size=40, padding=0, text_color=(0, 0, 0
temp_image = Image.new('RGB', (1, 1), (255, 255, 255)) temp_image = Image.new('RGB', (1, 1), (255, 255, 255))
temp_draw = ImageDraw.Draw(temp_image) temp_draw = ImageDraw.Draw(temp_image)
font = ImageFont.truetype(ASSETS / "montserrat.otf", font_size) font = ImageFont.truetype(FONTS_PATH / "montserrat.otf", font_size)
# try:
# font = ImageFont.truetype(ASSETS / "montserrat.otf", font_size)
# except:
# try:
# font = ImageFont.truetype("arial.ttf", font_size)
# except:
# # 如果系统字体不可用,使用默认字体
# font = ImageFont.load_default()
# 获取文本边界框 # 获取文本边界框
bbox = temp_draw.textbbox((0, 0), text, font=font) bbox = temp_draw.textbbox((0, 0), text, font=font)
@ -177,7 +171,7 @@ async def generate_dice_image(number: int) -> BytesIO:
], dtype=np.float32) ], dtype=np.float32)
# 加载背景图像,保留透明通道 # 加载背景图像,保留透明通道
background = cv2.imread(str(ASSETS / "template.png"), cv2.IMREAD_UNCHANGED) background = cv2.imread(str(ASSETS_PATH / "img" / "dice" / "template.png"), cv2.IMREAD_UNCHANGED)
# 对文本图像进行3D变换保持透明通道 # 对文本图像进行3D变换保持透明通道
@ -189,7 +183,7 @@ async def generate_dice_image(number: int) -> BytesIO:
pil_final = Image.fromarray(final_image_simple) pil_final = Image.fromarray(final_image_simple)
# 导入一系列图像 # 导入一系列图像
images: list[Image.Image] = [Image.open(ASSETS / f"{i}.png") for i in range(1, 12)] images: list[Image.Image] = [Image.open(ASSETS_PATH / "img" / "dice" / f"{i}.png") for i in range(1, 12)]
images.append(pil_final) images.append(pil_final)
frame_durations = [100] * (len(images) - 1) + [100000] frame_durations = [100] * (len(images) - 1) + [100000]
# 保存为BytesIO对象 # 保存为BytesIO对象

View File

@ -8,7 +8,9 @@ nonebot.load_plugins("konabot/plugins")
plugins = nonebot.get_loaded_plugins() plugins = nonebot.get_loaded_plugins()
len_requires = len( len_requires = len(
[f for f in Path("konabot/plugins").iterdir() if f.is_dir() and (f / "__init__.py").exists()] [f for f in (
Path(__file__).parent.parent / "konabot" / "plugins"
).iterdir() if f.is_dir() and (f / "__init__.py").exists()]
) )
plugins = [p for p in plugins if p.module.__name__.startswith("konabot.plugins")] plugins = [p for p in plugins if p.module.__name__.startswith("konabot.plugins")]