mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
添加单例注解
This commit is contained in:
parent
0dda0a228a
commit
c039015e8f
@ -300,6 +300,7 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能
|
|||||||
|
|
||||||
* 词条问题支持真寻的昵称开头与at真寻开头并优化回复
|
* 词条问题支持真寻的昵称开头与at真寻开头并优化回复
|
||||||
* 更正私聊时功能管理回复错误
|
* 更正私聊时功能管理回复错误
|
||||||
|
* 添加单例注解
|
||||||
* 添加统计表
|
* 添加统计表
|
||||||
|
|
||||||
### 2022/12/10
|
### 2022/12/10
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
from typing import List, Tuple, Dict, Optional
|
from typing import List, Tuple, Dict, Optional
|
||||||
from configs.path_config import IMAGE_PATH
|
from configs.path_config import IMAGE_PATH
|
||||||
|
from utils.decorator import Singleton
|
||||||
from utils.image_utils import BuildImage
|
from utils.image_utils import BuildImage
|
||||||
from configs.config import Config
|
from configs.config import Config
|
||||||
import os
|
import os
|
||||||
@ -109,20 +110,15 @@ def group_image(image_list: List[BuildImage]) -> Tuple[List[List[BuildImage]], i
|
|||||||
return image_group, max(max_h + 250, max_w + 70)
|
return image_group, max(max_h + 250, max_w + 70)
|
||||||
|
|
||||||
|
|
||||||
|
@Singleton
|
||||||
class HelpImageBuild:
|
class HelpImageBuild:
|
||||||
|
|
||||||
build: Optional["HelpImageBuild"] = None
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
print('初始化咯')
|
||||||
self._data: Dict[str, PluginData] = plugin_data_manager.get_data()
|
self._data: Dict[str, PluginData] = plugin_data_manager.get_data()
|
||||||
self._sort_data: Dict[str, List[PluginData]] = {}
|
self._sort_data: Dict[str, List[PluginData]] = {}
|
||||||
self._image_list = []
|
self._image_list = []
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
|
||||||
if not cls.build:
|
|
||||||
cls.build = super().__new__(cls)
|
|
||||||
return cls.build
|
|
||||||
|
|
||||||
def sort_type(self):
|
def sort_type(self):
|
||||||
"""
|
"""
|
||||||
说明:
|
说明:
|
||||||
@ -156,7 +152,8 @@ class HelpImageBuild:
|
|||||||
:param group_id: 群号
|
:param group_id: 群号
|
||||||
"""
|
"""
|
||||||
self._image_list = []
|
self._image_list = []
|
||||||
self.sort_type()
|
if not self._sort_data.keys():
|
||||||
|
self.sort_type()
|
||||||
font_size = 24
|
font_size = 24
|
||||||
build_type = Config.get_config("help", "TYPE")
|
build_type = Config.get_config("help", "TYPE")
|
||||||
_image = BuildImage(0, 0, plain_text="1", font_size=font_size)
|
_image = BuildImage(0, 0, plain_text="1", font_size=font_size)
|
||||||
|
|||||||
@ -19,6 +19,7 @@ from models.friend_user import FriendUser
|
|||||||
from models.group_member_info import GroupInfoUser
|
from models.group_member_info import GroupInfoUser
|
||||||
from models.level_user import LevelUser
|
from models.level_user import LevelUser
|
||||||
from models.user_shop_gold_log import UserShopGoldLog
|
from models.user_shop_gold_log import UserShopGoldLog
|
||||||
|
from utils.decorator import Singleton
|
||||||
from utils.manager import (
|
from utils.manager import (
|
||||||
plugins2block_manager,
|
plugins2block_manager,
|
||||||
StaticData,
|
StaticData,
|
||||||
@ -119,24 +120,18 @@ class ReturnException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@Singleton
|
||||||
class AuthChecker:
|
class AuthChecker:
|
||||||
"""
|
"""
|
||||||
权限检查
|
权限检查
|
||||||
"""
|
"""
|
||||||
|
|
||||||
checker: Optional["AuthChecker"] = None
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._flmt = FreqLimiter(Config.get_config("hook", "CHECK_NOTICE_INFO_CD"))
|
self._flmt = FreqLimiter(Config.get_config("hook", "CHECK_NOTICE_INFO_CD"))
|
||||||
self._flmt_g = FreqLimiter(Config.get_config("hook", "CHECK_NOTICE_INFO_CD"))
|
self._flmt_g = FreqLimiter(Config.get_config("hook", "CHECK_NOTICE_INFO_CD"))
|
||||||
self._flmt_s = FreqLimiter(Config.get_config("hook", "CHECK_NOTICE_INFO_CD"))
|
self._flmt_s = FreqLimiter(Config.get_config("hook", "CHECK_NOTICE_INFO_CD"))
|
||||||
self._flmt_c = FreqLimiter(Config.get_config("hook", "CHECK_NOTICE_INFO_CD"))
|
self._flmt_c = FreqLimiter(Config.get_config("hook", "CHECK_NOTICE_INFO_CD"))
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
|
||||||
if not cls.checker:
|
|
||||||
cls.checker = super().__new__(cls)
|
|
||||||
return cls.checker
|
|
||||||
|
|
||||||
async def auth(self, matcher: Matcher, bot: Bot, event: Event):
|
async def auth(self, matcher: Matcher, bot: Bot, event: Event):
|
||||||
"""
|
"""
|
||||||
说明:
|
说明:
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
class Singleton:
|
||||||
|
|
||||||
|
"""
|
||||||
|
单例注解
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, cls):
|
||||||
|
self._cls = cls
|
||||||
|
|
||||||
|
def __call__(self, *args, **kw):
|
||||||
|
if not hasattr(self, "_instance"):
|
||||||
|
self._instance = self._cls(*args, **kw)
|
||||||
|
return self._instance
|
||||||
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user