API
Filter Object
- class content_filter.Filter(list_file: str | None = None, word_list: List[str] | None = None)[source]
The filter object which contains the filter settings, data, and functions.
- Parameters:
list_file (str, optional) – The path to a file that will be used as the filter list in place of the default filter
word_list (str, optional) – A list of words to be used as the filter in place of the default filter
- Raises:
TypeError – Something other than a
list
was not passed in for word_list.FileNotFoundError – The input file for list_file does not exist.
ValueError – The custom file input is not a JSON file.
- add_exceptions(words: List[str]) None [source]
Allows the user to remove words to the list of pre-defined words to filter for.
- Parameters:
words (list) – A list of strings that will be removed from the default filter checking.
- Raises:
TypeError – Words input are not a list of strings.
- add_words(words: List[str]) None [source]
Allows the user to add words to the list of pre-defined words to filter for.
- Parameters:
words (list) – A list of strings that will be added to the default filter checking.
- Raises:
TypeError – Words input are not a list of strings.
- check(message: str) Check [source]
Checks the provided message for any words that should be filtered.
- Parameters:
message (str) – The message to be filtered. This should be a string.
- Raises:
TypeError – Message is not a string
- Returns:
A check object which contains the results of the filter.
- Return type:
.Check
- property list_file: Path
Gives you the path to the list file if using a custom filter file.
- Raises:
RuntimeError – Not using a custom JSON file.
- Returns:
A path object to the custom json file.
- Return type:
pathlib.Path
Check Object
- class content_filter.check.Check(message: str, exception_list: List[str], additional_list: List[str], custom_list: List[str], use_default_list: bool, use_custom_file: Dict[str, Any], translation_table: Dict[str, Any], filter_file: Path)[source]
Check object which checks a message and can return the results as either a list or a bool.
- property as_bool: bool
Outputs the check results as a bool.
- Returns:
True if the message contains a filter word, False if it doesn’t.
- Return type:
bool
- property as_list: List[Dict[str, Any]]
Outputs the check results as a list.
- Returns:
List of all the words found in the message. A blank list is returned if no words are found.
- Return type:
list