slidge.core.command.base#

Module Contents#

Classes#

TableResult

Structured data as the result of a command

SearchResult

Results of the search command (search for contacts via Jabber Search)

Confirmation

A confirmation 'dialog'

Form

A form, to request user input

CommandAccess

Defines who can access a given Command

Option

Options to be used for FormField``s of type ``list-*

FormField

Represents a field of the form that a user will see when registering to the gateway

Command

Abstract base class to implement gateway commands (chatbot and ad-hoc)

Functions#

is_admin(jid)

Attributes#

class slidge.core.command.base.TableResult[source]#

Structured data as the result of a command

fields: Collection[FormField][source]#

The ‘columns names’ of the table.

items: Collection[dict[str, str]][source]#

The rows of the table. Each row is a dict where keys are the fields var attribute.

description: str[source]#

A description of the content of the table.

jids_are_mucs: bool = False[source]#
get_xml()[source]#

Get a slixmpp “form” (with <reported> header)to represent the data

Returns:

some XML

class slidge.core.command.base.SearchResult[source]#

Bases: TableResult

Results of the search command (search for contacts via Jabber Search)

description: str = 'Contact search results'[source]#
class slidge.core.command.base.Confirmation[source]#

A confirmation ‘dialog’

prompt: str[source]#

The text presented to the command triggering user

handler: Callable[source]#

An async function that should return a ResponseType

success: str | None[source]#

Text in case of success, used if handler does not return anything

handler_args: Iterable[Any][source]#

arguments passed to the handler

handler_kwargs: dict[str, Any][source]#

keyword arguments passed to the handler

get_form()[source]#

Get the slixmpp form

Returns:

some xml

class slidge.core.command.base.Form[source]#

A form, to request user input

title: str[source]#
instructions: str[source]#
fields: Collection[FormField][source]#
handler: Callable[source]#
handler_args: Iterable[Any][source]#
handler_kwargs: dict[str, Any][source]#
get_values(slix_form)[source]#

Parse form submission

Parameters:

slix_form (slixmpp.plugins.xep_0004.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)

Return type:

dict[str, Union[str, slixmpp.JID]]

get_xml()[source]#

Get the slixmpp “form”

Returns:

some XML

class slidge.core.command.base.CommandAccess[source]#

Bases: int, enum.Enum

Defines who can access a given Command

Initialize self. See help(type(self)) for accurate signature.

ADMIN_ONLY = 0[source]#
USER = 1[source]#
USER_LOGGED = 2[source]#
USER_NON_LOGGED = 3[source]#
NON_USER = 4[source]#
ANY = 5[source]#
class slidge.core.command.base.Option[source]#

Bases: TypedDict

Options to be used for FormField``s of type ``list-*

Initialize self. See help(type(self)) for accurate signature.

label: str[source]#
value: str[source]#
class slidge.core.command.base.FormField[source]#

Represents a field of the form that a user will see when registering to the gateway via their XMPP client.

var: str = ''[source]#

Internal name of the field, will be used to retrieve via slidge.GatewayUser.registration_form

label: str | None[source]#

Description of the field that the user will see

required: bool = False[source]#

Whether this field is mandatory or not

private: bool = False[source]#

For sensitive info that should not be displayed on screen while the user types. Forces field_type to “text-private”

type: slidge.util.types.FieldType = 'text-single'[source]#

Type of the field, see XEP-0004

value: str = ''[source]#

Pre-filled value. Will be automatically pre-filled if a registered user modifies their subscription

options: list[Option] | None[source]#
image_url: str | None[source]#

An image associated to this field, eg, a QR code

dict()[source]#
__post_init__()[source]#
__acceptable_options()[source]#
validate(value)[source]#

Raise appropriate XMPPError if a given value is valid for this field

Parameters:

value (str) – The value to test

Returns:

The same value OR a JID if self.type=jid-single

get_xml()[source]#

Get the field in slixmpp format

Returns:

some XML

slidge.core.command.base.CommandResponseType[source]#
class slidge.core.command.base.Command(xmpp)[source]#

Bases: abc.ABC

Abstract base class to implement gateway commands (chatbot and ad-hoc)

Parameters:

xmpp (slidge.core.gateway.BaseGateway) –

NAME: str[source]#

Friendly name of the command, eg: “do something with stuff”

HELP: str[source]#

Long description of what the command does

NODE: str[source]#

Name of the node used for ad-hoc commands

CHAT_COMMAND: str[source]#

Text to send to the gateway to trigger the command via a message

ACCESS: CommandAccess[source]#

Who can use this command

subclasses[source]#
classmethod __init_subclass__(**kwargs)[source]#
async run(session, ifrom, *args)[source]#

Entry point of the command

Parameters:
  • session (Optional[slidge.core.session.BaseSession]) – If triggered by a registered user, its slidge Session

  • ifrom (slixmpp.JID) – 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

Return type:

CommandResponseType

_get_session(jid)[source]#
Parameters:

jid (slixmpp.JID) –

raise_if_not_authorized(jid)[source]#

Raise an appropriate error is jid is not authorized to use the command

Parameters:

jid (slixmpp.JID) – jid of the entity trying to access the command

:return:session of JID if it exists

slidge.core.command.base.is_admin(jid)[source]#
Parameters:

jid (slixmpp.types.JidStr) –