mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
rename vars in code
This commit is contained in:
parent
e9de860058
commit
a098a97032
@ -14,14 +14,14 @@ from .platform import platform_manager
|
||||
supported_target_type = platform_manager.keys()
|
||||
|
||||
def get_config_path() -> str:
|
||||
if plugin_config.hk_reporter_config_path:
|
||||
data_dir = plugin_config.hk_reporter_config_path
|
||||
if plugin_config.bison_config_path:
|
||||
data_dir = plugin_config.bison_config_path
|
||||
else:
|
||||
working_dir = os.getcwd()
|
||||
data_dir = path.join(working_dir, 'data')
|
||||
if not path.isdir(data_dir):
|
||||
os.makedirs(data_dir)
|
||||
return path.join(data_dir, 'hk_reporter.json')
|
||||
return path.join(data_dir, 'bison.json')
|
||||
|
||||
class NoSuchUserException(Exception):
|
||||
pass
|
||||
|
@ -134,7 +134,7 @@ class MessageProcessMixin(PlatformNameMixin, CategoryMixin, ParsePostMixin, abst
|
||||
# if post_id in exists_posts_set:
|
||||
# continue
|
||||
if (post_time := self.get_date(raw_post)) and time.time() - post_time > 2 * 60 * 60 and \
|
||||
plugin_config.hk_reporter_init_filter:
|
||||
plugin_config.bison_init_filter:
|
||||
continue
|
||||
try:
|
||||
self.get_category(raw_post)
|
||||
@ -157,7 +157,7 @@ class NewMessageProcessMixin(StorageMixinProto, MessageProcessMixin, abstract=Tr
|
||||
filtered_post = await self.filter_common(raw_post_list)
|
||||
store = self.get_stored_data(target) or self.MessageStorage(False, set())
|
||||
res = []
|
||||
if not store.inited and plugin_config.hk_reporter_init_filter:
|
||||
if not store.inited and plugin_config.bison_init_filter:
|
||||
# target not init
|
||||
for raw_post in filtered_post:
|
||||
post_id = self.get_id(raw_post)
|
||||
|
@ -5,17 +5,17 @@ import nonebot
|
||||
|
||||
class PlugConfig(BaseSettings):
|
||||
|
||||
hk_reporter_config_path: str = ""
|
||||
hk_reporter_use_pic: bool = False
|
||||
hk_reporter_use_local: bool = False
|
||||
hk_reporter_browser: str = ''
|
||||
hk_reporter_init_filter: bool = True
|
||||
hk_reporter_use_queue: bool = True
|
||||
bison_config_path: str = ""
|
||||
bison_use_pic: bool = False
|
||||
bison_use_local: bool = False
|
||||
bison_browser: str = ''
|
||||
bison_init_filter: bool = True
|
||||
bison_use_queue: bool = True
|
||||
|
||||
class Config:
|
||||
extra = 'ignore'
|
||||
|
||||
global_config = nonebot.get_driver().config
|
||||
plugin_config = PlugConfig(**global_config.dict())
|
||||
if plugin_config.hk_reporter_use_local:
|
||||
warnings.warn('HK_REPORTER_USE_LOCAL is deprecated, please use HK_REPORTER_BROWSER')
|
||||
if plugin_config.bison_use_local:
|
||||
warnings.warn('BISON_USE_LOCAL is deprecated, please use BISON_BROWSER')
|
||||
|
@ -29,7 +29,7 @@ class Post:
|
||||
def _use_pic(self):
|
||||
if not self.override_use_pic is None:
|
||||
return self.override_use_pic
|
||||
return plugin_config.hk_reporter_use_pic
|
||||
return plugin_config.bison_use_pic
|
||||
|
||||
async def _pic_url_to_image(self, data: Union[str, bytes]) -> Image.Image:
|
||||
pic_buffer = BytesIO()
|
||||
|
@ -53,7 +53,7 @@ for platform_name, platform in platform_manager.items():
|
||||
fetch_and_send, platform.schedule_type, **platform.schedule_kw,
|
||||
args=(platform_name,))
|
||||
|
||||
if plugin_config.hk_reporter_use_queue:
|
||||
if plugin_config.bison_use_queue:
|
||||
scheduler.add_job(do_send_msgs, 'interval', seconds=0.3, coalesce=True)
|
||||
|
||||
class SchedulerLogFilter(logging.Filter):
|
||||
|
@ -33,7 +33,7 @@ async def do_send_msgs():
|
||||
LAST_SEND_TIME = time.time()
|
||||
|
||||
async def send_msgs(bot, user, user_type, msgs):
|
||||
if plugin_config.hk_reporter_use_queue:
|
||||
if plugin_config.bison_use_queue:
|
||||
for msg in msgs:
|
||||
QUEUE.append((bot, user, user_type, msg, 2))
|
||||
else:
|
||||
|
@ -24,7 +24,7 @@ class Singleton(type):
|
||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls._instances[cls]
|
||||
|
||||
if not plugin_config.hk_reporter_browser and not plugin_config.hk_reporter_use_local \
|
||||
if not plugin_config.bison_browser and not plugin_config.bison_use_local \
|
||||
and not check_chromium():
|
||||
os.environ['PYPPETEER_DOWNLOAD_HOST'] = 'http://npm.taobao.org/mirrors'
|
||||
download_chromium()
|
||||
@ -38,15 +38,15 @@ class Render(metaclass=Singleton):
|
||||
self.remote_browser = False
|
||||
|
||||
async def get_browser(self) -> Browser:
|
||||
if plugin_config.hk_reporter_browser:
|
||||
if plugin_config.hk_reporter_browser.startswith('local:'):
|
||||
path = plugin_config.hk_reporter_browser.split('local:', 1)[1]
|
||||
if plugin_config.bison_browser:
|
||||
if plugin_config.bison_browser.startswith('local:'):
|
||||
path = plugin_config.bison_browser.split('local:', 1)[1]
|
||||
return await launch(executablePath=path, args=['--no-sandbox'])
|
||||
if plugin_config.hk_reporter_browser.startswith('ws:'):
|
||||
if plugin_config.bison_browser.startswith('ws:'):
|
||||
self.remote_browser = True
|
||||
return await connect(browserWSEndpoint=plugin_config.hk_reporter_browser)
|
||||
raise RuntimeError('HK_REPORTER_BROWSER error')
|
||||
if plugin_config.hk_reporter_use_local:
|
||||
return await connect(browserWSEndpoint=plugin_config.bison_browser)
|
||||
raise RuntimeError('bison_BROWSER error')
|
||||
if plugin_config.bison_use_local:
|
||||
return await launch(executablePath='/usr/bin/chromium', args=['--no-sandbox'])
|
||||
return await launch(args=['--no-sandbox'])
|
||||
|
||||
@ -119,7 +119,7 @@ class Render(metaclass=Singleton):
|
||||
|
||||
async def parse_text(text: str) -> MessageSegment:
|
||||
'return raw text if don\'t use pic, otherwise return rendered opcode'
|
||||
if plugin_config.hk_reporter_use_pic:
|
||||
if plugin_config.bison_use_pic:
|
||||
render = Render()
|
||||
return await render.text_to_pic_cqcode(text)
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user