use local chrome

This commit is contained in:
felinae98 2021-02-08 11:18:16 +08:00
parent e33f33ac3a
commit 2178f9667f
No known key found for this signature in database
GPG Key ID: 00C8B010587FF610
3 changed files with 9 additions and 4 deletions

View File

@ -1,10 +1,11 @@
FROM python:3.9
RUN echo "deb http://mirrors.aliyun.com/debian/ buster main contrib non-free\ndeb http://mirrors.aliyun.com/debian/ buster-updates main contrib non-free" > /etc/apt/sources.list && \
apt-get update && apt-get install chromium -y fonts-wqy-microhei
apt-get update && apt-get install -y fonts-wqy-microhei
RUN python3 -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
RUN python3 -m pip install poetry && poetry config virtualenvs.create false
WORKDIR /app
COPY ./pyproject.toml ./poetry.lock* /app/
RUN poetry install --no-root --no-dev
RUN PYPPETEER_DOWNLOAD_HOST='http://npm.taobao.org/mirrors' pyppeteer-install
COPY . /app/
CMD ["python", "bot.py"]

View File

@ -3,7 +3,8 @@ from pydantic import BaseSettings
class PlugConfig(BaseSettings):
hk_reporter_config_path: str = ""
use_pic: bool = False
hk_reporter_use_pic: bool = False
hk_reporter_use_local: bool = False
class Config:
extra = 'ignore'

View File

@ -20,7 +20,10 @@ class Render(metaclass=Singleton):
self.page = None
async def init(self):
browser = await launch(executablePath='/usr/bin/chromium')
if plugin_config.hk_reporter_use_local:
browser = await launch(executablePath='/usr/bin/chromium')
else:
browser = await launch()
self.page = await browser.newPage()
async def text_to_pic(self, text: str) -> str:
@ -46,7 +49,7 @@ async def _start():
nonebot.get_driver().on_startup(_start)
async def parse_text(text: str):
if plugin_config.use_pic:
if plugin_config.hk_reporter_use_pic:
r = Render()
return await r.text_to_pic_cqcode(text)
else: