2021-11-23 21:44:59 +08:00
|
|
|
from utils.manager import (
|
|
|
|
|
plugins2cd_manager,
|
|
|
|
|
plugins2block_manager,
|
|
|
|
|
plugins2count_manager,
|
2022-12-04 16:46:33 +08:00
|
|
|
plugin_data_manager,
|
2021-11-23 21:44:59 +08:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
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)
|
2022-11-21 20:43:41 +08:00
|
|
|
for matcher in get_matchers(True):
|
2022-12-04 16:46:33 +08:00
|
|
|
if not plugins2cd_manager.get_plugin_cd_data(matcher.plugin_name) and (
|
|
|
|
|
plugin_data := plugin_data_manager.get(matcher.plugin_name)
|
|
|
|
|
):
|
|
|
|
|
if plugin_data.plugin_cd:
|
2021-11-23 21:44:59 +08:00
|
|
|
plugins2cd_manager.add_cd_limit(
|
2022-12-04 16:46:33 +08:00
|
|
|
matcher.plugin_name, plugin_data.plugin_cd
|
2021-11-23 21:44:59 +08:00
|
|
|
)
|
|
|
|
|
if not plugins2cd_manager.keys():
|
2022-12-04 16:46:33 +08:00
|
|
|
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
|
|
|
for matcher in get_matchers(True):
|
2022-12-04 16:46:33 +08:00
|
|
|
if not plugins2block_manager.get_plugin_block_data(matcher.plugin_name) and (
|
|
|
|
|
plugin_data := plugin_data_manager.get(matcher.plugin_name)
|
|
|
|
|
):
|
|
|
|
|
if plugin_data.plugin_block:
|
2021-11-23 21:44:59 +08:00
|
|
|
plugins2block_manager.add_block_limit(
|
2022-12-04 16:46:33 +08:00
|
|
|
matcher.plugin_name, plugin_data.plugin_block
|
2021-11-23 21:44:59 +08:00
|
|
|
)
|
|
|
|
|
if not plugins2block_manager.keys():
|
2022-12-04 16:46:33 +08:00
|
|
|
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-12-04 16:46:33 +08:00
|
|
|
for matcher in get_matchers(True):
|
|
|
|
|
if not plugins2count_manager.get_plugin_count_data(matcher.plugin_name) and (
|
|
|
|
|
plugin_data := plugin_data_manager.get(matcher.plugin_name)
|
|
|
|
|
):
|
|
|
|
|
if plugin_data.plugin_count:
|
2021-11-23 21:44:59 +08:00
|
|
|
plugins2count_manager.add_count_limit(
|
2022-12-04 16:46:33 +08:00
|
|
|
matcher.plugin_name, plugin_data.plugin_count
|
2021-11-23 21:44:59 +08:00
|
|
|
)
|
|
|
|
|
if not plugins2count_manager.keys():
|
2022-12-04 16:46:33 +08:00
|
|
|
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()
|