[docs]classPlainTextCondition:r"""A builtin search condition to check plain text. This condition will only run if the query's text is the same as the text given to this condition. See the :ref:`search handler section <search_handlers>` for more information about using search handlers and conditions. Attributes ---------- text: :class:`str` The text to compare the query to """__slots__=("text",)def__init__(self,text:str)->None:self.text=textdef__call__(self,query:Query)->bool:returnquery.text==self.text
[docs]classRegexCondition:r"""A builtin search condition to check a regex pattern. This condition will only run if the query's text is a match to the regex pattern given to this condition. See the :ref:`search handler section <search_handlers>` for more information about using search handlers and conditions. This condition will set the query's :attr:`~flogin.query.Query.condition_data` attribute to the :class:`re.Match` object. Attributes ---------- pattern: :class:`re.Pattern` The pattern to check the queries against. """__slots__=("pattern",)def__init__(self,pattern:re.Pattern[str])->None:self.pattern=patterndef__call__(self,query:Query[re.Match[str]])->bool:match=self.pattern.match(query.text)ifmatch:query.condition_data=matchreturnTruereturnFalse
[docs]classAllCondition(_MultiCondition):r"""This builtin search condition acts similiarly to the builtin ``all`` function. It only returns ``True`` if all of the given conditions also return ``True``. This condition will set :attr:`flogin.query.Query.condition_data` to a dictionary containing the conditions, where the keys are the conditions, and the values are the condition data that they gave. Attributes ---------- conditions: list[:ref:`condition <condition_example>`] A list that contains all the conditions that should be used with this condition. """def__call__(self,query:Query)->bool:condition_data={}forconditioninself.conditions:ifcondition(query)isFalse:returnFalsecondition_data[condition]=query.condition_dataquery.condition_data=Nonequery.condition_data=condition_datareturnTrue
[docs]classAnyCondition(_MultiCondition):r"""This builtin search condition acts similiarly to the builtin ``any`` function. It only returns ``True`` if any one of the given conditions return ``True``. This condition will set :attr:`flogin.query.Query.condition_data` to a tuple containing two values. The first value will be the condition that returned true, and the second will be the condition data that the condition gave. :: (condition, query.condition_data) Attributes ----------- conditions: list[:ref:`condition <condition_example>`] A list that contains all the conditions that should be used with this condition. """def__call__(self,query:Query)->bool:forconditioninself.conditions:ifcondition(query)isTrue:query.condition_data=(condition,query.condition_data)returnTruereturnFalse
[docs]classKeywordCondition:r"""A builtin search condition to check what keyword was used with the query. If the :attr:`~flogin.conditions.KeywordCondition.allowed_keywords` attribute is given, the handler will only run if the query's keyword is in the list of allowed keywords. If the :attr:`~flogin.conditions.KeywordCondition.disallowed_keywords` attribute is given, the handler will only run if the query's keyword is not in the list of allowed keywords. See the :ref:`search handler section <search_handlers>` for more information about using search handlers and conditions. Attributes ---------- allowed_keywords: Optional[Iterable[:class:`str`]] The allowed keywords disallowed_keywords: Optional[Iterable[:class:`str`]] The disallowed keywords """__slots__="allowed_keywords","disallowed_keywords"def__init__(self,*,allowed_keywords:Iterable[str]|None=None,disallowed_keywords:Iterable[str]|None=None,)->None:ifallowed_keywordsisNoneanddisallowed_keywordsisNone:raiseTypeError("Either the 'allowed_keywords' arg or the 'disallowed_keywords' arg must be given")ifallowed_keywordsisnotNoneanddisallowed_keywordsisnotNone:raiseTypeError("'allowed_keywords' and 'disallowed_keywords' can not be passed together. Use `MultiCondition` if you would like to achieve it.")self.allowed_keywords:Iterable[str]|None=allowed_keywordsorNoneself.disallowed_keywords:Iterable[str]|None=disallowed_keywordsorNonedef__call__(self,query:Query)->bool:ifself.allowed_keywordsisNoneandself.disallowed_keywordsisnotNone:returnquery.keywordnotinself.disallowed_keywordsifself.allowed_keywordsisnotNoneandself.disallowed_keywordsisNone:returnquery.keywordinself.allowed_keywordsraiseRuntimeError("'allowed_keywords' and 'disallowed_keywords' have been modified to be invalid")