147011eba1
* Extract paths from logs and check for blocked content * Extract paths in command line analyzer * Split disabled paths message if necessary * Log the blocked path that caused a warning * Remove duplicate command alias * Remove bad characters from extracted filepaths * Fix is_path_disabled() only checking the full path * Apply formatting * Improve wording for the warning embeds * Apply formatting
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import json
|
|
import os
|
|
|
|
from robocop_ng.helpers.data_loader import read_json
|
|
|
|
|
|
def get_disabled_paths_path(bot) -> str:
|
|
return os.path.join(bot.state_dir, "data/disabled_paths.json")
|
|
|
|
|
|
def get_disabled_paths(bot) -> list[str]:
|
|
disabled_paths = read_json(bot, get_disabled_paths_path(bot))
|
|
if "paths" not in disabled_paths.keys():
|
|
return []
|
|
return disabled_paths["paths"]
|
|
|
|
|
|
def set_disabled_paths(bot, contents: list[str]):
|
|
with open(get_disabled_paths_path(bot), "w") as f:
|
|
json.dump({"paths": contents}, f)
|
|
|
|
|
|
def is_path_disabled(bot, path: str) -> bool:
|
|
for disabled_path in get_disabled_paths(bot):
|
|
if disabled_path in path.strip().lower():
|
|
return True
|
|
return False
|
|
|
|
|
|
def add_disabled_path(bot, disabled_path: str) -> bool:
|
|
disabled_path = disabled_path.strip().lower()
|
|
disabled_paths = get_disabled_paths(bot)
|
|
if disabled_path not in disabled_paths:
|
|
disabled_paths.append(disabled_path)
|
|
set_disabled_paths(bot, disabled_paths)
|
|
return True
|
|
return False
|
|
|
|
|
|
def remove_disabled_path(bot, disabled_path: str) -> bool:
|
|
disabled_path = disabled_path.strip().lower()
|
|
disabled_paths = get_disabled_paths(bot)
|
|
if disabled_path in disabled_paths:
|
|
disabled_paths.remove(disabled_path)
|
|
set_disabled_paths(bot, disabled_paths)
|
|
return True
|
|
return False
|