Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
fllesser committed Jan 8, 2025
1 parent 7f8786f commit 322d950
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
11 changes: 10 additions & 1 deletion nonebot_plugin_fortnite/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
get_level,
get_stats_image
)
from .pve import screenshot_vb_img

timewindow_prefix = ["生涯", ""]
name_args = Args["name?", str]
Expand Down Expand Up @@ -84,4 +85,12 @@ async def _(arp: Arparma, name: str):

@shop.handle()
async def _():
await shop.finish('https://www.fortnite.com/item-shop?lang=zh-Hans')
await shop.finish('https://www.fortnite.com/item-shop?lang=zh-Hans')


vb = on_command('vb图')

@vb.handle()
async def _():
file = await screenshot_vb_img()
await vb.finish(await UniMessage(Image(path=file)).export())
86 changes: 86 additions & 0 deletions nonebot_plugin_fortnite/pve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import asyncio
from playwright.async_api import async_playwright
from .config import cache_dir

async def screenshot_vb_img():
url = "https://freethevbucks.com/timed-missions"
file = cache_dir / "vb.png"
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True) # 启动无头模式的 Chromium 浏览器
page = await browser.new_page()
await page.goto(url) # 打开指定 URL
await page.screenshot(path=file, full_page=True) # 截取整个页面
await browser.close()
return file


# import time
# import httpx

# from bs4 import BeautifulSoup
# from PIL import (
# Image,
# ImageFont
# )
# from PIL.Image import Resampling
# from io import BytesIO
# from pathlib import Path

# from .config import cache_dir, data_dir

# ele_icon_file: Path = data_dir / 'ele_icon.png'
# vb_icon_file: Path = data_dir / 'vb_icon.png'

# async def update_daily_vb() -> str:
# url = "https://freethevbucks.com/timed-missions/"
# vb_url = "https://freethevbucks.com/wp-content/uploads/cropped-v-bucks-3-32x32.png"
# ele_url = "https://img.icons8.com/office/30/000000/lightning-bolt.png"

# # 爬去数据,下载图标
# async with httpx.AsyncClient() as client:
# free_resp = await client.get(url)
# if not ele_icon_file.exists():
# ele_resp = await client.get(ele_url)
# with open(ele_icon_file, 'wb') as f:
# f.write(ele_resp.content)
# if not vb_icon_file.exists():
# vb_resp = await client.get(vb_url)
# with open(vb_icon_file, 'wb') as f:
# f.write(vb_resp.content)
# # bs4 解析html
# soup = BeautifulSoup(free_resp.content, "lxml")

# # 电力图标
# ele_icon_img = Image.open(ele_icon_file)
# ele_icon_img = ele_img.resize((15, 15), Resampling.LANCZOS)
# # vb图标
# vb_icon_img = Image.open(vb_icon_file)
# vb_icon_img = vb_icon.resize((15, 15), Resampling.LANCZOS)
# # vb图
# img = BuildImage(width=256, height=220, font_size=15,
# color=(36, 44, 68), font= FONT_PATH / "gorga.otf")
# # 起始纵坐标
# Y = 30
# timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# await img.text(pos=(0, 185), text=timestr, center_type="width", fill=(255, 255, 255))
# for item in soup.find_all("p"):
# if item.span is not None and item.span.b is not None:
# if not item.img:
# continue
# storm_src = item.img.get("src") # 风暴图标链接
# async with httpx.AsyncClient() as client:
# resp = await client.get(storm_src)
# storm_img = Image.open(BytesIO(resp.content))
# await img.paste(image=storm_img, pos=(40, Y)) # 风暴图标
# # 电力
# await img.text(text=item.b.string, pos=(70, Y - 3), fill=(255, 255, 255))
# await img.paste(image=ele_img, pos=(88, Y + 2)) # 电力图标
# vb_num: str = item.span.text.split(",")[0]
# await img.paste(image=vb_icon, pos=(113, Y + 2))
# await img.text(pos=(130, Y - 3), text=vb_num, fill=(255, 255, 255))
# Y += 30
# if Y == 30:
# img.font = ImageFont.truetype(str(FONT_PATH / "SourceHanSansSC-Bold-2.otf"), 30)
# await img.text(pos=(0, 80), text="今天没有vb图捏", center_type="width", fill=(255, 255, 255))
# await img.save(IMG_PATH / "fn_stw.png")
# return "fn_stw.png"
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ keywords = ["nonebot", "nonebot2"]
[tool.poetry.dependencies]
python = "^3.10"
fortnite-api = "^3.2.1"
pillow = '^10.4.0'
pillow = "^10.4.0"
playwright = "^1.4.9.1"
nonebot2 = "^2.4.0"
nonebot-adapter-onebot = "^2.4.6"
nonebot-plugin-uninfo = "^0.6.5"
Expand Down

0 comments on commit 322d950

Please sign in to comment.