From a098a970320daea8389c54c98bf031c607e3e901 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Wed, 17 Nov 2021 16:57:04 +0800 Subject: [PATCH] rename vars in code --- src/plugins/nonebot_bison/config.py | 6 +++--- src/plugins/nonebot_bison/platform/platform.py | 4 ++-- src/plugins/nonebot_bison/plugin_config.py | 16 ++++++++-------- src/plugins/nonebot_bison/post.py | 2 +- src/plugins/nonebot_bison/scheduler.py | 2 +- src/plugins/nonebot_bison/send.py | 2 +- src/plugins/nonebot_bison/utils.py | 18 +++++++++--------- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/plugins/nonebot_bison/config.py b/src/plugins/nonebot_bison/config.py index 2f40c29..29b734e 100644 --- a/src/plugins/nonebot_bison/config.py +++ b/src/plugins/nonebot_bison/config.py @@ -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 diff --git a/src/plugins/nonebot_bison/platform/platform.py b/src/plugins/nonebot_bison/platform/platform.py index d01bbe4..0bc181f 100644 --- a/src/plugins/nonebot_bison/platform/platform.py +++ b/src/plugins/nonebot_bison/platform/platform.py @@ -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) diff --git a/src/plugins/nonebot_bison/plugin_config.py b/src/plugins/nonebot_bison/plugin_config.py index 9012462..6fb7cd6 100644 --- a/src/plugins/nonebot_bison/plugin_config.py +++ b/src/plugins/nonebot_bison/plugin_config.py @@ -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') diff --git a/src/plugins/nonebot_bison/post.py b/src/plugins/nonebot_bison/post.py index 7f28b0d..9ef1136 100644 --- a/src/plugins/nonebot_bison/post.py +++ b/src/plugins/nonebot_bison/post.py @@ -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() diff --git a/src/plugins/nonebot_bison/scheduler.py b/src/plugins/nonebot_bison/scheduler.py index 72a8a84..0ae44cc 100644 --- a/src/plugins/nonebot_bison/scheduler.py +++ b/src/plugins/nonebot_bison/scheduler.py @@ -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): diff --git a/src/plugins/nonebot_bison/send.py b/src/plugins/nonebot_bison/send.py index 65ba74f..023de7b 100644 --- a/src/plugins/nonebot_bison/send.py +++ b/src/plugins/nonebot_bison/send.py @@ -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: diff --git a/src/plugins/nonebot_bison/utils.py b/src/plugins/nonebot_bison/utils.py index adb7a40..46c459c 100644 --- a/src/plugins/nonebot_bison/utils.py +++ b/src/plugins/nonebot_bison/utils.py @@ -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: