slidge.command¶
This module implements an unified API to define adhoc
or chatbot commands. Just subclass a Command,
and make sures it is imported in your legacy module’s __init__.py.
Submodules¶
Package Contents¶
- class slidge.command.Command(xmpp: slidge.util.types.AnyGateway)¶
Bases:
_CommandMixin,Generic[slidge.util.types.SessionType]Abstract base class to implement gateway commands (chatbot and ad-hoc)
- ACCESS: CommandAccess = NotImplemented¶
Who can use this command
- CATEGORY: str | slidge.command.categories.CommandCategory | None = None¶
If used, the command will be under this top-level category. Use the same string for several commands to group them. This hierarchy only used for the adhoc interface, not the chat command interface.
- async run(session: slidge.util.types.SessionType | None, ifrom: slixmpp.JID, *args: str) CommandResponseSessionType[slidge.util.types.SessionType]¶
Entry point of the command
- Parameters:
session – If triggered by a registered user, its slidge Session
ifrom – JID of the command-triggering entity
args – When triggered via chatbot type message, additional words after the CHAT_COMMAND string was passed
- Returns:
Either a TableResult, a Form, a Confirmation, a text, or None
- raise_if_not_authorized(jid: slixmpp.JID, fetch_session: bool = True, session: slidge.util.types.SessionType | None = None) slidge.util.types.SessionType | None¶
Raise an appropriate error is jid is not authorized to use the command
- Parameters:
jid – jid of the entity trying to access the command
fetch_session
session
:return:session of JID if it exists
- class slidge.command.Confirmation¶
A confirmation ‘dialog’
- handler: Any¶
An async function that should return a ResponseType
- handler_args: collections.abc.Iterable[Any] = []¶
arguments passed to the handler
- get_form() slixmpp.plugins.xep_0004.Form¶
Get the slixmpp form
- Returns:
some xml
- class slidge.command.ContactCommand¶
Bases:
_RecipientCommand[slidge.util.types.LegacyContactType],Generic[slidge.util.types.LegacyContactType]A command that will be avaible on a contact.
It implicitly requires the user to be registered and logged. It is never instantiated, so all methods must be static methods. Its entrypoint is the
run()static method.
- class slidge.command.Form¶
A form, to request user input
- get_values(slix_form: slixmpp.plugins.xep_0004.Form) dict[str, list[str] | list[slixmpp.JID] | str | slixmpp.JID | bool | None]¶
Parse form submission
- Parameters:
slix_form – the xml received as the submission of a form
- Returns:
A dict where keys=field.var and values are either strings or JIDs (if field.type=jid-single)
- get_xml() slixmpp.plugins.xep_0004.Form¶
Get the slixmpp “form”
- Returns:
some XML
- class slidge.command.FormField¶
Represents a field of the form that a user will see when registering to the gateway via their XMPP client.
- var: str = ''¶
Internal name of the field, will be used to retrieve via
slidge.GatewayUser.registration_form
- private: bool = False¶
For sensitive info that should not be displayed on screen while the user types. Forces field_type to “text-private”
- value: str = ''¶
Pre-filled value. Will be automatically pre-filled if a registered user modifies their subscription
- validate(value: str | list[str] | None) list[str] | list[slixmpp.JID] | str | slixmpp.JID | bool | None¶
Raise appropriate XMPPError if a given value is valid for this field
- Parameters:
value – The value to test
- Returns:
The same value OR a JID if
self.type=jid-single
- get_xml() slixmpp.plugins.xep_0004.stanza.field.FormField¶
Get the field in slixmpp format
- Returns:
some XML
- class slidge.command.MUCCommand¶
Bases:
_RecipientCommand[slidge.util.types.LegacyMUCType],Generic[slidge.util.types.LegacyMUCType]A command that will be avaible on a MUC.
It implicitly requires the user to be registered and logged. It is never instantiated, so all methods must be static methods. Its entrypoint is the
run()static method.
- class slidge.command.SearchResult¶
Bases:
TableResultResults of the search command (search for contacts via Jabber Search)
Return type of
BaseSession.search().- fields: collections.abc.Sequence[FormField]¶
The ‘columns names’ of the table.
- items: collections.abc.Sequence[dict[str, str | slixmpp.JID]]¶
The rows of the table. Each row is a dict where keys are the fields
varattribute.
- get_xml() slixmpp.plugins.xep_0004.Form¶
Get a slixmpp “form” (with <reported> header)to represent the data
- Returns:
some XML
- class slidge.command.TableResult¶
Structured data as the result of a command
- fields: collections.abc.Sequence[FormField]¶
The ‘columns names’ of the table.
- items: collections.abc.Sequence[dict[str, str | slixmpp.JID]]¶
The rows of the table. Each row is a dict where keys are the fields
varattribute.
- get_xml() slixmpp.plugins.xep_0004.Form¶
Get a slixmpp “form” (with <reported> header)to represent the data
- Returns:
some XML