2021-11-23 21:44:59 +08:00
|
|
|
from utils.manager import (
|
|
|
|
|
plugins2cd_manager,
|
|
|
|
|
plugins2block_manager,
|
|
|
|
|
plugins2count_manager,
|
|
|
|
|
)
|
|
|
|
|
from utils.utils import get_matchers
|
2022-11-21 20:43:41 +08:00
|
|
|
from configs.path_config import DATA_PATH
|
2021-11-23 21:44:59 +08:00
|
|
|
import nonebot
|
|
|
|
|
|
|
|
|
|
|
2022-11-21 20:43:41 +08:00
|
|
|
def init_plugins_cd_limit():
|
2021-11-23 21:44:59 +08:00
|
|
|
"""
|
|
|
|
|
加载 cd 限制
|
|
|
|
|
"""
|
2022-11-21 20:43:41 +08:00
|
|
|
plugins2cd_file = DATA_PATH / "configs" / "plugins2cd.yaml"
|
2021-11-23 21:44:59 +08:00
|
|
|
plugins2cd_file.parent.mkdir(exist_ok=True, parents=True)
|
|
|
|
|
_data = {}
|
2022-11-21 20:43:41 +08:00
|
|
|
for matcher in get_matchers(True):
|
2022-02-19 18:20:19 +08:00
|
|
|
if not plugins2cd_manager.get_plugin_cd_data(matcher.plugin_name):
|
|
|
|
|
_plugin = nonebot.plugin.get_plugin(matcher.plugin_name)
|
2021-11-23 21:44:59 +08:00
|
|
|
try:
|
|
|
|
|
_module = _plugin.module
|
|
|
|
|
plugin_cd_limit = _module.__getattribute__("__plugin_cd_limit__")
|
|
|
|
|
plugins2cd_manager.add_cd_limit(
|
2022-05-24 01:27:55 +08:00
|
|
|
matcher.plugin_name, **plugin_cd_limit
|
2021-11-23 21:44:59 +08:00
|
|
|
)
|
|
|
|
|
except AttributeError:
|
|
|
|
|
pass
|
|
|
|
|
if not plugins2cd_manager.keys():
|
|
|
|
|
plugins2cd_manager.add_cd_limit(
|
|
|
|
|
"这是一个示例"
|
|
|
|
|
)
|
2022-11-21 20:43:41 +08:00
|
|
|
plugins2cd_manager.save()
|
2021-11-23 21:44:59 +08:00
|
|
|
plugins2cd_manager.reload_cd_limit()
|
|
|
|
|
|
|
|
|
|
|
2022-11-21 20:43:41 +08:00
|
|
|
def init_plugins_block_limit():
|
2021-11-23 21:44:59 +08:00
|
|
|
"""
|
|
|
|
|
加载阻塞限制
|
|
|
|
|
"""
|
2022-11-21 20:43:41 +08:00
|
|
|
plugins2block_file = DATA_PATH / "configs" / "plugins2block.yaml"
|
2021-11-23 21:44:59 +08:00
|
|
|
plugins2block_file.parent.mkdir(exist_ok=True, parents=True)
|
2022-11-21 20:43:41 +08:00
|
|
|
for matcher in get_matchers(True):
|
2022-02-19 18:20:19 +08:00
|
|
|
if not plugins2block_manager.get_plugin_block_data(matcher.plugin_name):
|
2022-11-21 20:43:41 +08:00
|
|
|
_plugin = matcher.plugin
|
2021-11-23 21:44:59 +08:00
|
|
|
try:
|
|
|
|
|
_module = _plugin.module
|
|
|
|
|
plugin_block_limit = _module.__getattribute__("__plugin_block_limit__")
|
|
|
|
|
plugins2block_manager.add_block_limit(
|
2022-05-24 01:27:55 +08:00
|
|
|
matcher.plugin_name, **plugin_block_limit
|
2021-11-23 21:44:59 +08:00
|
|
|
)
|
|
|
|
|
except AttributeError:
|
|
|
|
|
pass
|
|
|
|
|
if not plugins2block_manager.keys():
|
|
|
|
|
plugins2block_manager.add_block_limit(
|
|
|
|
|
"这是一个示例"
|
|
|
|
|
)
|
2022-11-21 20:43:41 +08:00
|
|
|
plugins2block_manager.save()
|
2021-11-23 21:44:59 +08:00
|
|
|
plugins2block_manager.reload_block_limit()
|
|
|
|
|
|
|
|
|
|
|
2022-11-21 20:43:41 +08:00
|
|
|
def init_plugins_count_limit():
|
2021-11-23 21:44:59 +08:00
|
|
|
"""
|
|
|
|
|
加载次数限制
|
|
|
|
|
"""
|
2022-11-21 20:43:41 +08:00
|
|
|
plugins2count_file = DATA_PATH / "configs" / "plugins2count.yaml"
|
2021-11-23 21:44:59 +08:00
|
|
|
plugins2count_file.parent.mkdir(exist_ok=True, parents=True)
|
|
|
|
|
_data = {}
|
|
|
|
|
_matchers = get_matchers()
|
|
|
|
|
for matcher in _matchers:
|
2022-02-19 18:20:19 +08:00
|
|
|
if not plugins2count_manager.get_plugin_count_data(matcher.plugin_name):
|
|
|
|
|
_plugin = nonebot.plugin.get_plugin(matcher.plugin_name)
|
2021-11-23 21:44:59 +08:00
|
|
|
try:
|
|
|
|
|
_module = _plugin.module
|
|
|
|
|
plugin_count_limit = _module.__getattribute__("__plugin_count_limit__")
|
|
|
|
|
plugins2count_manager.add_count_limit(
|
2022-05-24 01:27:55 +08:00
|
|
|
matcher.plugin_name, **plugin_count_limit
|
2021-11-23 21:44:59 +08:00
|
|
|
)
|
|
|
|
|
except AttributeError:
|
|
|
|
|
pass
|
|
|
|
|
if not plugins2count_manager.keys():
|
|
|
|
|
plugins2count_manager.add_count_limit(
|
|
|
|
|
"这是一个示例"
|
|
|
|
|
)
|
2022-11-21 20:43:41 +08:00
|
|
|
plugins2count_manager.save()
|
2021-11-23 21:44:59 +08:00
|
|
|
plugins2count_manager.reload_count_limit()
|