diff --git a/__init__.py b/__init__.py index 27ff8ed..30f9456 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ from nonebot.adapters.onebot.v11 import Message, Bot, MessageEvent, MessageSegment from nonebot.params import CommandArg -from .utils.draw import draw_obtain + from .utils.Artifact import ( artifact_obtain, ARTIFACT_LIST, @@ -12,6 +12,7 @@ from .config.config import STAMINA_RESTORE, MAX_STAMINA, Config from .utils.json_rw import init_user_info, updata_uid_stamina, user_info, save_user_info from .utils.artifact_eval import * +from pathlib import Path from base64 import b64encode from io import BytesIO @@ -39,10 +40,7 @@ async def get_obtain_(bot: Bot): use_pic = Config.parse_obj(get_driver().config.dict()).use_pic if use_pic: - data = [] - for name, artifact in artifact_obtain.items(): - data.append((name, " ".join(artifact))) - pic = draw_obtain(data) + pic = Path(__file__).parent / "resources" / "table.png" await get_obtain.send(MessageSegment.image(pic)) else: mes = "当前副本如下\n" diff --git a/requirements.txt b/requirements.txt index 0338d19..892906e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,3 @@ httpx~=0.23.0 -Pillow~=9.3.0 requests~=2.28.1 -pandas~=1.5.2 -matplotlib~=3.6.2 pydantic~=1.9.2 \ No newline at end of file diff --git a/resources/table.png b/resources/table.png new file mode 100644 index 0000000..5bd0506 Binary files /dev/null and b/resources/table.png differ diff --git a/utils/draw.py b/utils/draw.py deleted file mode 100644 index 3badfab..0000000 --- a/utils/draw.py +++ /dev/null @@ -1,37 +0,0 @@ -import os -import pandas as pd -import matplotlib.pyplot as plt -import matplotlib.font_manager as fm - -from io import BytesIO - -FILE_PATH = os.path.dirname(__file__) -FONT_PATH = os.path.join(FILE_PATH, "../resources/fonts/MSYH.TTC") - - -def draw_obtain(data_t): - # 创建 DataFrame 对象 - df = pd.DataFrame(data_t, columns=["副本名称", "可刷取的圣遗物"]) - table_height = len(df.columns) * 1.6 # 每列宽度为 1.6 英寸 - table_width = len(df) * 0.45 # 每行高度为 0.45 英寸 - plt.rcParams["figure.figsize"] = (table_width, table_height) - # 创建图形并绘制表格 - font_prop = fm.FontProperties(fname=FONT_PATH) - fig, ax = plt.subplots() - ax.axis("off") - table = ax.table( - cellText=df.values, colLabels=df.columns, cellLoc="center", loc="center" - ) - # 设置表格字体 - for cell in table.get_celld().values(): - cell.set_text_props(fontproperties=font_prop) - plt.subplots_adjust(top=1, bottom=0, right=1, left=0) - # 将图片保存到内存中 - buf = BytesIO() - fig.savefig(buf, format="png", dpi=1000) - buf.seek(0) - # 使用 Image 对象打开保存在内存中的图片 - image_bytes = buf.getvalue() - # 关闭 buffer 和图形 - buf.close() - return image_bytes