Capability Negotiation#
Management of IRC capability negotiation.
New in version 8.0.
This module contains the Capabilities
class which tracks the state of
the capability negotiation with the IRC server: it can store and update the
state of available and enabled capabilities.
Important
Plugin authors should not instantiate this class directly, as the bot
exposes an instance through its capabilities
attribute.
All state handling methods (such as Capabilities.handle_ls()
) are
used by the coretasks
plugin, and should not be used outside.
- class sopel.irc.capabilities.Capabilities#
Capabilities negotiated with the server.
This stores a representation of the capability negotiation state between the bot and the server: it stores the list of
available
andenabled
capabilities, and can track the state by handling variousCAP
subcommands:handle_ls()
forCAP LS
handle_ack()
forCAP ACK
handle_nak()
forCAP NAK
handle_new()
forCAP NEW
handle_del()
forCAP ADD
- property available: dict[str, str | None]#
Dict of available server capabilities.
Each key is the name of a capability advertised by the server, and each value is the parameters as advertised (if any) for this capability.
If a capability is not in this
dict
, it means the server doesn’t advertise it, and it cannot be requested.
- property enabled: frozenset[str]#
Set of enabled server capabilities.
Each element is the name of a capability that is enabled on the server.
- get_capability_info(
- name: str,
Retrieve metadata about a capability.
The returned
CapabilityInfo
will tell if the capability is advertised by the server; and if so, its parameters and whether it is enabled.If the capability is unknown, then its
available
attribute will beFalse
, and itsparams
attribute will beNone
.
- handle_ack(bot: SopelWrapper, trigger: Trigger) tuple[str, ...] #
Handle a
CAP ACK
command.This method behaves as a plugin callable with its
bot
andtrigger
arguments, with the precise goals to handleCAP ACK
command only, registering enabled or disabled capabilities and tracking acknowledgement.Then it returns the list of acknowledged capability requests.
- handle_del(bot: SopelWrapper, trigger: Trigger) tuple[str, ...] #
Handle a
CAP DEL
command.This method behaves as a plugin callable with its
bot
andtrigger
arguments, with the precise goals to handleCAP DEL
command only.It registers which capabilities are not available and not enabled anymore, then returns this list.
- handle_ls(bot: SopelWrapper, trigger: Trigger) bool #
Handle a
CAP LS
command.This method behaves as a plugin callable with its
bot
andtrigger
arguments, with the precise goals to handleCAP LS
command only, registering available capabilities.Then it returns if there is no more
LS
command to handle (in case of multi-lineLS
).
- handle_nak(bot: SopelWrapper, trigger: Trigger) tuple[str, ...] #
Handle a
CAP NAK
command.This method behaves as a plugin callable with its
bot
andtrigger
arguments, with the precise goals to handleCAP NAK
command only.Then it returns the list of denied capability requests.
- handle_new(bot: SopelWrapper, trigger: Trigger) tuple[str, ...] #
Handle a
CAP NEW
command.This method behaves as a plugin callable with its
bot
andtrigger
arguments, with the precise goals to handleCAP NEW
command only.It registers which new capabilities are available, then returns this list.
- class sopel.irc.capabilities.CapabilityInfo#
Capability metadata.
This contains the details of a capability: if
available
,enabled
, and itsparams
(if advertised).Note
You can get a capability’s info through
Capabilities.get_capability_info()
.- available: bool#
Flag to tell if the server advertises this capability or not.
This is
True
if theCAP LS
subcommand contains the capability.
- name: str#
Name of the capability.
The name of a capability is the name as it appears in the
CAP LS
subcommand, such asmulti-prefix
orsasl
.
- params: str | None#
Advertised parameters for this capability.
When a server supports
CAP
version 302, capabilities can have parameters. The format and the meaning of the parameters depend on the capability itself.For example, the
sasl
capability can provide the list of SASL mechanisms the server supports, such asPLAIN,EXTERNAL
.