API¶
Filter Object¶
-
class
content_filter.
Filter
(list_file=None, word_list=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) → 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) → 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) → content_filter.check.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
-
property
list_file
¶ 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, exception_list, additional_list, custom_list, use_default_list, use_custom_file, translation_table, filter_file)[source]¶ Check object which checks a message and can return the results as either a list or a bool.
-
property
as_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
¶ 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
-
property