mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
require htmlrender when needed
This commit is contained in:
parent
af8cbf6ecf
commit
6cdb4e625e
@ -1,7 +1,3 @@
|
||||
from nonebot.plugin import require
|
||||
|
||||
require("nonebot_plugin_htmlrender")
|
||||
|
||||
from . import (
|
||||
admin_page,
|
||||
config,
|
||||
|
@ -1,10 +1,9 @@
|
||||
import json
|
||||
from typing import Any, Type
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
from bs4 import BeautifulSoup as bs
|
||||
from nonebot.plugin import require
|
||||
from nonebot_plugin_htmlrender import capture_element
|
||||
|
||||
from ..post import Post
|
||||
from ..types import Category, RawPost, Target
|
||||
@ -52,6 +51,8 @@ class Arknights(NewMessage):
|
||||
if soup.find("div", class_="standerd-container"):
|
||||
# 图文
|
||||
require("nonebot_plugin_htmlrender")
|
||||
from nonebot_plugin_htmlrender import capture_element
|
||||
|
||||
pic_data = await capture_element(
|
||||
announce_url,
|
||||
"div.main",
|
||||
|
@ -1,5 +1,3 @@
|
||||
import warnings
|
||||
|
||||
import nonebot
|
||||
from pydantic import BaseSettings
|
||||
|
||||
@ -13,6 +11,7 @@ class PlugConfig(BaseSettings):
|
||||
bison_outer_url: str = "http://localhost:8080/bison/"
|
||||
bison_filter_log: bool = False
|
||||
bison_to_me: bool = True
|
||||
bison_skip_browser_check: bool = False
|
||||
|
||||
class Config:
|
||||
extra = "ignore"
|
||||
|
@ -6,7 +6,7 @@ import nonebot
|
||||
from bs4 import BeautifulSoup as bs
|
||||
from nonebot.adapters.onebot.v11.message import MessageSegment
|
||||
from nonebot.log import default_format, logger
|
||||
from nonebot_plugin_htmlrender import text_to_pic as _text_to_pic
|
||||
from nonebot.plugin import require
|
||||
|
||||
from .plugin_config import plugin_config
|
||||
|
||||
@ -23,11 +23,18 @@ class Singleton(type):
|
||||
async def parse_text(text: str) -> MessageSegment:
|
||||
"return raw text if don't use pic, otherwise return rendered opcode"
|
||||
if plugin_config.bison_use_pic:
|
||||
require("nonebot_plugin_htmlrender")
|
||||
from nonebot_plugin_htmlrender import text_to_pic as _text_to_pic
|
||||
|
||||
return MessageSegment.image(await _text_to_pic(text))
|
||||
else:
|
||||
return MessageSegment.text(text)
|
||||
|
||||
|
||||
if not plugin_config.bison_skip_browser_check:
|
||||
require("nonebot_plugin_htmlrender")
|
||||
|
||||
|
||||
def html_to_text(html: str, query_dict: dict = {}) -> str:
|
||||
html = re.sub(r"<br\s*/?>", "<br>\n", html)
|
||||
html = html.replace("</p>", "</p>\n")
|
||||
|
Loading…
x
Reference in New Issue
Block a user