diff --git a/Dockerfile b/Dockerfile index ebdf55d..7f673db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,6 @@ 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 +# RUN PYPPETEER_DOWNLOAD_HOST='http://npm.taobao.org/mirrors' pyppeteer-install COPY . /app/ CMD ["python", "bot.py"] diff --git a/src/plugins/hk_reporter/utils.py b/src/plugins/hk_reporter/utils.py index 1d89ea2..f593c7e 100644 --- a/src/plugins/hk_reporter/utils.py +++ b/src/plugins/hk_reporter/utils.py @@ -1,4 +1,5 @@ import nonebot +import base64 from pyppeteer import launch from html import escape from hashlib import sha256 @@ -26,7 +27,7 @@ class Render(metaclass=Singleton): browser = await launch(args=['--no-sandbox']) self.page = await browser.newPage() - async def text_to_pic(self, text: str) -> str: + async def text_to_pic(self, text: str) -> bytes: hash_text = sha256(text.encode()).hexdigest()[:20] lines = text.split('\n') parsed_lines = list(map(lambda x: '
{}
'.format(escape(x)), lines)) @@ -35,13 +36,11 @@ class Render(metaclass=Singleton): f.write(html_text) await self.page.goto('file:///tmp/text-{}.html'.format(hash_text)) div = await self.page.querySelector('div') - path = '/tmp/img-{}.png'.format(hash_text) - await div.screenshot(path=path) - return path + return await div.screenshot() async def text_to_pic_cqcode(self, text:str) -> str: - path = await self.text_to_pic(text) - return '[CQ:image,file=file://{}]'.format(path) + data = await self.text_to_pic(text) + return '[CQ:image,file=base64://{}]'.format(base64.b64encode(data).decode()) async def _start(): r = Render()