-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
85 additions
and
55 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
|
||
from PIL import Image, ImageFont | ||
from PIL.ImageFile import ImageFile | ||
from PIL.ImageFont import FreeTypeFont | ||
from nonebot.plugin import require | ||
from pathlib import Path | ||
|
||
require("nonebot_plugin_localstore") | ||
import nonebot_plugin_localstore as store | ||
|
||
|
||
PLUGIN_PATH: Path = Path(os.path.dirname(os.path.realpath(__file__))) | ||
ASSETS_PATH: Path = PLUGIN_PATH / "assets" | ||
|
||
CHECK_IMG: ImageFile = Image.open(ASSETS_PATH / "[email protected]") | ||
DEERPIPE_IMG: ImageFile = Image.open(ASSETS_PATH / "[email protected]") | ||
|
||
MISANS_FONT: FreeTypeFont = ImageFont.truetype( | ||
ASSETS_PATH / "MiSans-Regular.ttf", | ||
25 | ||
) | ||
|
||
USERDATA_PATH: Path = store.get_plugin_data_file("userdata.json") |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import calendar | ||
import os | ||
import secrets | ||
|
||
from .contants import CHECK_IMG, DEERPIPE_IMG, MISANS_FONT, PLUGIN_PATH | ||
from PIL import Image, ImageDraw | ||
from datetime import datetime | ||
from pathlib import Path | ||
from typing import Sequence | ||
|
||
|
||
def generate_image(now: datetime, name: str, deer: Sequence[int]) -> bytes: | ||
cal: list[list[int]] = calendar.monthcalendar(now.year, now.month) | ||
|
||
IMG_W, IMG_H = 700, 100 * (len(cal) + 1) | ||
BOX_W, BOX_H = 100, 100 | ||
|
||
img: Image.Image = Image.new("RGBA", (IMG_W, IMG_H), "white") | ||
drw: ImageDraw.ImageDraw = ImageDraw.Draw(img) | ||
|
||
for week_idx, week in enumerate(cal): | ||
for day_idx, day in enumerate(week): | ||
x0: int = day_idx * BOX_W | ||
y0: int = (week_idx + 1) * BOX_H | ||
if day != 0: | ||
img.paste(DEERPIPE_IMG, (x0, y0)) | ||
drw.text((x0 + 5, y0 + BOX_H - 35), str(day), fill='black', font=MISANS_FONT) | ||
if day in deer: | ||
img.paste(CHECK_IMG, (x0, y0), CHECK_IMG) | ||
|
||
drw.text((5, 5), f"{now.year}-{now.month:02} 签到", fill="black", font=MISANS_FONT) | ||
drw.text((5, 50), name, fill="black", font=MISANS_FONT) | ||
|
||
img_path: Path = PLUGIN_PATH / f"{secrets.token_hex()}.png" | ||
img.save(img_path) | ||
|
||
with open(img_path, "rb") as f: | ||
raw: bytes = f.read() | ||
os.remove(img_path) | ||
|
||
return raw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "nonebot-plugin-deer-pipe" | ||
version = "0.0.4" | ||
version = "0.0.5" | ||
authors = [ | ||
{ name="SNRainiar", email="[email protected]" }, | ||
] | ||
|
@@ -21,6 +21,7 @@ dependencies = [ | |
"nonebot2", | ||
"nonebot-adapter-onebot", | ||
"nonebot-plugin-alconna", | ||
"nonebot-plugin-localstore", | ||
"nonebot_plugin_userinfo" | ||
] | ||
|
||
|