Skip to content

Commit

Permalink
bump: 0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Dec 12, 2022
1 parent 6f0c209 commit 6b3cec4
Show file tree
Hide file tree
Showing 13 changed files with 849 additions and 694 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ Telegram:[@lgc2333](https://t.me/lgc2333)

## 📝 更新日志

### 0.6.2

- 修改日程表、羁绊查询的图片背景
- 加上日程表条目的圆角
- 更改 GameKee 日程表的排序方式

### 0.6.1

- 修复一处 Py 3.8 无法运行的代码

### 0.6.0

- 新指令 `ba抽卡` `ba切换卡池` `ba表情` `ba漫画`
Expand Down
2 changes: 1 addition & 1 deletion bawiki-data
2 changes: 1 addition & 1 deletion nonebot_plugin_bawiki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .__main__ import * # type:ignore

__version__ = "0.6.1"
__version__ = "0.6.2"
__plugin_meta__ = PluginMetadata(
name="BAWiki",
description="碧蓝档案Wiki插件",
Expand Down
1 change: 0 additions & 1 deletion nonebot_plugin_bawiki/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from io import BytesIO
from typing import Dict, List, Optional

from PIL import Image
from nonebot import logger, on_command, on_shell_command
from nonebot.adapters.onebot.v11 import (
ActionFailed,
Expand Down
3 changes: 0 additions & 3 deletions nonebot_plugin_bawiki/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
BAWIKI_DB_URL = "https://bawiki.lgc2333.top/"

RES_PATH = Path(__file__).parent / "res"
# RES_FONT = RES_PATH / "SourceHanSansSC-Bold-2.otf"
RES_CALENDER_BANNER = RES_PATH / "calender_banner.png"
RES_SCHALE_BG = RES_PATH / "schale_bg.jpg"

DATA_PATH = Path.cwd() / "data" / "BAWiki"
if not DATA_PATH.exists():
Expand Down
26 changes: 18 additions & 8 deletions nonebot_plugin_bawiki/data_gamekee.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from io import BytesIO
from typing import Any, Dict, List, Union

from PIL import Image
from bs4 import BeautifulSoup, ResultSet, Tag
from nonebot import logger
from nonebot.adapters.onebot.v11 import MessageSegment
from nonebot_plugin_htmlrender import get_new_page
from nonebot_plugin_imageutils import BuildImage, text2image
from playwright.async_api import Page

from .const import RES_CALENDER_BANNER
from .resource import RES_CALENDER_BANNER, RES_GRADIENT_BG
from .util import async_req, parse_time_delta


Expand All @@ -36,7 +37,8 @@ async def game_kee_get_calender():
now = time.time()
li = [x for x in li if (now < x["end_at"])]

li.sort(key=lambda x: x["end_at"])
li.sort(key=lambda x: x["begin_at"] if now < x["begin_at"] else x["end_at"])
li.sort(key=lambda x: now < x["begin_at"])
li.sort(key=lambda x: x["importance"], reverse=True)
return li

Expand Down Expand Up @@ -92,12 +94,12 @@ async def game_kee_calender():
return MessageSegment.image(pic)


async def game_kee_get_calender_page(ret):
async def game_kee_get_calender_page(ret, has_pic=True):
now = datetime.now()

async def draw(it: dict):
_p = None
if _p := it.get("picture"):
if has_pic and (_p := it.get("picture")):
try:
_p = (
BuildImage.open(BytesIO(await async_req(f"https:{_p}", raw=True)))
Expand All @@ -113,6 +115,8 @@ async def draw(it: dict):
time_remain = (end if started else begin) - now
dd, hh, mm, ss = parse_time_delta(time_remain)

# logger.debug(f'{it["title"]} | {started} | {time_remain}')

title_p = text2image(
f'[b]{it["title"]}[/b]', "#ffffff00", max_width=1290, fontsize=65
)
Expand Down Expand Up @@ -173,10 +177,12 @@ async def draw(it: dict):
pics: List[BuildImage] = await asyncio.gather( # type: ignore
*[draw(x) for x in ret]
)

bg_w = 1500
bg_h = 200 + sum([x.height + 50 for x in pics])
bg = (
BuildImage.new("RGBA", (1500, 200 + sum([x.height + 50 for x in pics])))
.gradient_color((138, 213, 244), (251, 226, 229))
.paste(BuildImage.open(RES_CALENDER_BANNER).resize((1500, 150)))
BuildImage.new("RGBA", (bg_w, bg_h))
.paste(RES_CALENDER_BANNER.copy().resize((1500, 150)))
.draw_text(
(50, 0, 1480, 150),
"GameKee丨活动日程",
Expand All @@ -185,11 +191,15 @@ async def draw(it: dict):
fill="#ffffff",
halign="left",
)
.paste(
RES_GRADIENT_BG.copy().resize((1500, bg_h - 150), resample=Image.NEAREST),
(0, 150),
)
)

index = 200
for p in pics:
bg.paste(p, (50, index), True)
bg.paste(p.circle_corner(10), (50, index), True)
index += p.height + 50

return bg.save_jpg()
Expand Down
27 changes: 17 additions & 10 deletions nonebot_plugin_bawiki/data_schaledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

from .const import (
MIRROR_SCHALE_URL,
RES_CALENDER_BANNER,
RES_SCHALE_BG,
SCHALE_URL,
)
from .resource import RES_CALENDER_BANNER, RES_GRADIENT_BG
from .util import async_req, img_invert_rgba, parse_time_delta

PAGE_KWARGS = {
Expand Down Expand Up @@ -426,16 +425,20 @@ async def draw_birth():

return pic

img = await asyncio.gather(draw_gacha(), draw_event(), draw_raid(), draw_birth())
img = [x for x in img if x]
img = await asyncio.gather( # type: ignore
draw_gacha(), draw_event(), draw_raid(), draw_birth()
)
img: List[BuildImage] = [x for x in img if x]
if not img:
img.append(
pic_bg.copy().draw_text((0, 0, 1400, 640), "没有获取到任何数据", max_fontsize=60)
)

bg_w = 1500
bg_h = 200 + sum([x.height + 50 for x in img])
bg = (
BuildImage.new("RGBA", (1500, 200 + sum([x.height + 50 for x in img])))
.gradient_color((138, 213, 244), (251, 226, 229))
.paste(BuildImage.open(RES_CALENDER_BANNER).resize((1500, 150)))
BuildImage.new("RGBA", (bg_w, bg_h))
.paste(RES_CALENDER_BANNER.copy().resize((1500, 150)))
.draw_text(
(50, 0, 1480, 150),
f"SchaleDB丨活动日程丨{localization['ServerName'][str(server)]}",
Expand All @@ -444,11 +447,15 @@ async def draw_birth():
fill="#ffffff",
halign="left",
)
.paste(
RES_GRADIENT_BG.copy().resize((1500, bg_h - 150), resample=Image.NEAREST),
(0, 150),
)
)

h_index = 200
for im in img:
bg.paste(im, (50, h_index), True)
bg.paste(im.circle_corner(10), (50, h_index), True)
h_index += im.height + 50
return bg.convert("RGB").save("png")

Expand Down Expand Up @@ -480,8 +487,8 @@ async def draw_fav_li(lvl):
line = math.ceil(l / line_max_icon)
length = line_max_icon

img = BuildImage.open(RES_SCHALE_BG).resize(
(icon_w * length, icon_h * line + 5), keep_ratio=True
img = RES_GRADIENT_BG.copy().resize(
(icon_w * length, icon_h * line + 5), resample=Image.NEAREST
)

async def draw_stu(name_, dev_name_, line_, index_):
Expand Down
41 changes: 19 additions & 22 deletions nonebot_plugin_bawiki/gacha.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@
from typing import Dict, Iterable, List, Optional, Tuple, TypedDict

import aiofiles
from aiohttp import ClientSession
from nonebot import logger
from nonebot.adapters.onebot.v11 import MessageSegment
from nonebot_plugin_imageutils import BuildImage

from .const import DATA_PATH, RES_PATH
from .data_bawiki import db_get_gacha_data
from .const import DATA_PATH
from .data_schaledb import (
find_current_event,
schale_get,
schale_get_common,
schale_get_stu_dict,
)
from .resource import (
RES_GACHA_BG,
RES_GACHA_CARD_BG,
RES_GACHA_CARD_MASK,
RES_GACHA_NEW,
RES_GACHA_PICKUP,
RES_GACHA_STAR,
RES_GACHA_STU_ERR,
)
from .util import split_list

IMG_GACHA_BG = BuildImage.open(RES_PATH / "gacha_bg.png")
IMG_GACHA_CARD_BG = BuildImage.open(RES_PATH / "gacha_card_bg.png")
IMG_GACHA_CARD_MASK = BuildImage.open(RES_PATH / "gacha_card_mask.png").convert("RGBA")
IMG_GACHA_NEW = BuildImage.open(RES_PATH / "gacha_new.png")
IMG_GACHA_PICKUP = BuildImage.open(RES_PATH / "gacha_pickup.png")
IMG_GACHA_STAR = BuildImage.open(RES_PATH / "gacha_star.png")
IMG_GACHA_STU_ERR = BuildImage.open(RES_PATH / "gacha_stu_err.png")

GACHA_DATA_PATH = DATA_PATH / "gacha.json"
if not GACHA_DATA_PATH.exists():
GACHA_DATA_PATH.write_text("{}")
Expand Down Expand Up @@ -76,7 +73,7 @@ async def gen_stu_img(students: Iterable[GachaStudent]) -> Tuple[BuildImage]:
stu_li = await schale_get_stu_dict("Id")

async def gen_single(stu: GachaStudent) -> BuildImage:
bg = IMG_GACHA_CARD_BG.copy()
bg = RES_GACHA_CARD_BG.copy()

stu_star = 0
try:
Expand All @@ -89,33 +86,33 @@ async def gen_single(stu: GachaStudent) -> BuildImage:
stu_img = BuildImage.open(BytesIO(stu_img))
except:
logger.exception(f"学生数据获取失败 {stu.id}")
stu_img = IMG_GACHA_STU_ERR
stu_img = RES_GACHA_STU_ERR

card_img = BuildImage.new("RGBA", IMG_GACHA_CARD_MASK.size, (0, 0, 0, 0))
card_img = BuildImage.new("RGBA", RES_GACHA_CARD_MASK.size, (0, 0, 0, 0))
card_img.image.paste(
stu_img.resize(IMG_GACHA_CARD_MASK.size, keep_ratio=True).image,
mask=IMG_GACHA_CARD_MASK.image,
stu_img.resize(RES_GACHA_CARD_MASK.size, keep_ratio=True).image,
mask=RES_GACHA_CARD_MASK.image,
)

bg = bg.paste(card_img, (26, 13), True)

star_x_offset = int(26 + (159 - 30 * stu_star) / 2)
star_y_offset = 198
for i in range(stu_star):
bg = bg.paste(IMG_GACHA_STAR, (star_x_offset + i * 30, star_y_offset), True)
bg = bg.paste(RES_GACHA_STAR, (star_x_offset + i * 30, star_y_offset), True)

font_x_offset = 45
font_y_offset = 2

if stu.new:
bg = bg.paste(IMG_GACHA_NEW, (font_x_offset, font_y_offset), True)
bg = bg.paste(RES_GACHA_NEW, (font_x_offset, font_y_offset), True)
font_x_offset -= 2
font_y_offset += 29

if stu.pickup:
font_x_offset -= 4
font_y_offset -= 4
bg = bg.paste(IMG_GACHA_PICKUP, (font_x_offset, font_y_offset), True)
bg = bg.paste(RES_GACHA_PICKUP, (font_x_offset, font_y_offset), True)

return bg

Expand All @@ -131,7 +128,7 @@ async def gen_gacha_img(
return
card_w, card_h = stu_cards[0][0].size

bg = IMG_GACHA_BG.copy()
bg = RES_GACHA_BG.copy()

x_gap = 10
y_gap = 80
Expand Down
Binary file added nonebot_plugin_bawiki/res/gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed nonebot_plugin_bawiki/res/schale_bg.jpg
Binary file not shown.
14 changes: 14 additions & 0 deletions nonebot_plugin_bawiki/resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from nonebot_plugin_imageutils import BuildImage

from .const import RES_PATH

RES_CALENDER_BANNER = BuildImage.open(RES_PATH / "calender_banner.png")
# RES_SCHALE_BG = BuildImage.open(RES_PATH / "schale_bg.jpg")
RES_GRADIENT_BG = BuildImage.open(RES_PATH / "gradient.png")
RES_GACHA_BG = BuildImage.open(RES_PATH / "gacha_bg.png")
RES_GACHA_CARD_BG = BuildImage.open(RES_PATH / "gacha_card_bg.png")
RES_GACHA_CARD_MASK = BuildImage.open(RES_PATH / "gacha_card_mask.png").convert("RGBA")
RES_GACHA_NEW = BuildImage.open(RES_PATH / "gacha_new.png")
RES_GACHA_PICKUP = BuildImage.open(RES_PATH / "gacha_pickup.png")
RES_GACHA_STAR = BuildImage.open(RES_PATH / "gacha_star.png")
RES_GACHA_STU_ERR = BuildImage.open(RES_PATH / "gacha_stu_err.png")
Loading

0 comments on commit 6b3cec4

Please sign in to comment.