supybot.irclib¶
Irc¶
It is usually the irc object given to plugin commands.
-
class
supybot.irclib.
Irc
(network, callbacks=[])[source]¶ Bases:
supybot.irclib.IrcCommandDispatcher
,supybot.log.Firewalled
The base class for an IRC connection.
Handles PING commands already.
-
zombie
¶ Whether or not this object represents a living IRC connection.
Type: bool
-
network
¶ The name of the network this object is connected to.
Type: str
-
startedAt
¶ When this connection was (re)started.
Type: float
-
callbacks
¶ List of all callbacks (ie. plugins) currently loaded
Type: List[IrcCallback]
-
queue
¶ Queue of messages waiting to be sent. Plugins should use the
queueMsg
method instead of accessing this directly.Type: IrcMsgQueue
-
fastqueue
¶ Same as
queue
, but for messages with high priority. Plugins should use thesendMsg
method instead of accessing this directly (or queueMsg if the message isn’t high priority).Type: smallqueue
-
driver
¶ Driver of the IRC connection (normally, a
supybot.drivers.Socket.SocketDriver
object). Plugins normally do not need to access this.
-
startedSync
¶ When joining a channel, a
'#channel': time.time()
entry is added to this dict, which is then removed when the join is completed. Plugins should not change this value, it is automatically handled when they send a JOIN.Type: ircutils.IrcDict[str, float]
-
monitoring
¶ A dict with nicks as keys and the number of plugins monitoring this nick as value. Plugins should not access this directly, and should use the
monitor
andunmonitor
methods instead.Type: ircutils.IrcDict[str, int]
-
state
¶ An
supybot.irclib.IrcState
object, which stores all the known information about the connection with the IRC network.Type: supybot.irclib.IrcState
-
REQUEST_CAPABILITIES
= {'account-notify', 'account-tag', 'away-notify', 'batch', 'chghost', 'echo-message', 'extended-join', 'invite-notify', 'labeled-response', 'message-tags', 'metadata-notify', 'msgid', 'multi-prefix', 'server-time', 'setname', 'userhost-in-names'}¶ IRCv3 capabilities requested when they are available.
echo-message is special-cased to be requested only with labeled-response.
To check if a capability was negotiated, use irc.state.capabilities_ack.
-
addCallback
(callback)[source]¶ Adds a callback to the callbacks list.
Parameters: callback (supybot.irclib.IrcCallback) – A callback object
-
capUpkeep
(msg)[source]¶ Called after getting a CAP ACK/NAK to check it’s consistent with what was requested, and to end the cap negotiation when we received all the ACK/NAKs we were waiting for.
msg is the message that triggered this call.
-
die
(*args, **kwargs)¶ Makes the Irc object promise to die – but it won’t die (of its own volition) until all its queues are clear. Isn’t that cool?
-
dispatchCommand
(command, args=None)¶ Given a string ‘command’, dispatches to doCommand.
-
feedMsg
(*args, **kwargs)¶ Called by the IrcDriver; feeds a message received.
tag=False is used when simulating echo messages, to skip adding received* tags.
-
isChannel
(s)[source]¶ Helper function to check whether a given string is a channel on the network this Irc object is connected to.
-
monitor
(targets)[source]¶ Increment a counter of how many callbacks monitor each target; and send a MONITOR + to the server if the target is not yet monitored.
-
takeMsg
(*args, **kwargs)¶ Called by the IrcDriver; takes a message to be sent.
-
IrcState¶
Used mainly as the state
attribute of supybot.irclib.Irc
objects.
-
class
supybot.irclib.
IrcState
(history=None, supported=None, nicksToHostmasks=None, channels=None, capabilities_req=None, capabilities_ack=None, capabilities_nak=None, capabilities_ls=None)[source]¶ Bases:
supybot.irclib.IrcCommandDispatcher
,supybot.log.Firewalled
Maintains state of the Irc connection. Should also become smarter.
-
fsm
¶ A finite-state machine representing the current state of the IRC connection: various steps while connecting, then remains in the CONNECTED state (or CONNECTED_SASL when doing SASL in the middle of a connection).
Type: IrcStateFsm
-
capabilities_req
¶ Set of all capabilities requested from the server. See <https://ircv3.net/specs/core/capability-negotiation>
Type: Set[str]
-
capabilities_acq
¶ Set of all capabilities requested from and acknowledged by the server. See <https://ircv3.net/specs/core/capability-negotiation>
Type: Set[str]
-
capabilities_nak
¶ Set of all capabilities requested from and refused by the server. This should always be empty unless the bot, a plugin, or the server is misbehaving. See <https://ircv3.net/specs/core/capability-negotiation>
Type: Set[str]
-
capabilities_ls
¶ Stores all the capabilities advertised by the server, as well as their value, if any.
Type: Dict[str, Optional[str]]
-
ircd
¶ Identification string of the software running the server we are connected to. See <https://defs.ircdocs.horse/defs/numerics.html#rpl-myinfo-004>
Type: str
-
supported
¶ Stores the value of ISUPPORT sent when connecting. See <https://defs.ircdocs.horse/defs/isupport.html> for the list of keys.
Type: utils.InsensitivePreservingDict[str, Any]
-
history
¶ History of messages received from the network. Automatically discards messages so it doesn’t exceed
supybot.protocols.irc.maxHistoryLength
.Type: RingBuffer[ircmsgs.IrcMsg]
-
channels
¶ Store channel states.
Type: ircutils.IrcDict[str, ChannelState]
-
addMsg
(*args, **kwargs)¶ Updates the state based on the irc object and the message.
-
dispatchCommand
(command, args=None)¶ Given a string ‘command’, dispatches to doCommand.
-
nickToHostmask
(nick)[source] Returns the hostmask for a given nick.
-
IrcStateFsm¶
Used as the fsm
attribute of supybot.irclib.IrcState
objects
-
class
supybot.irclib.
IrcStateFsm
[source]¶ Bases:
object
Finite State Machine keeping track of what part of the connection initialization we are in.
-
class
States
[source]¶ Bases:
enum.Enum
Enumeration of all the states of an IRC connection.
-
CONNECTED
= 70¶ Normal state of the connections
-
CONNECTED_SASL
= 80¶ Doing SASL authentication in the middle of a connection.
-
INIT_CAP_NEGOTIATION
= 20¶ Sent CAP LS, did not send CAP END yet
-
INIT_MOTD
= 60¶ Waiting for end of MOTD
-
INIT_SASL
= 30¶ In an AUTHENTICATE session
-
INIT_WAITING_MOTD
= 50¶ Waiting for start of MOTD
-
UNINITIALIZED
= 10¶ Nothing received yet (except server notices)
-
-
class
ChannelState¶
Used mainly as the channels[‘#chan’] attribute of
supybot.irclib.Irc
objects.
-
class
supybot.irclib.
ChannelState
[source]¶ Bases:
supybot.utils.python.Object
Represents the known state of an IRC channel.
-
topic
¶ The topic of a channel (possibly the empty stringà
Type: str
-
created
¶ Timestamp of the channel creation, according to the server.
Type: int
-
ops
¶ Set of the nicks of all the operators of the channel.
Type: ircutils.IrcSet[str]
-
halfops
¶ Set of the nicks of all the half-operators of the channel.
Type: ircutils.IrcSet[str]
-
voices
¶ Set of the nicks of all the voiced users of the channel.
Type: ircutils.IrcSet[str]
-
users
¶ Set of the nicks of all the users in the channel.
Type: ircutils.IrcSet[str]
-
bans
¶ Set of the all the banmasks set in the channel.
Type: ircutils.IrcSet[str]
-
modes
¶ Dict of all the modes set in the channel, with they value, if any. This excludes the following modes: ovhbeq
Type: Dict[str, Optional[str]]
-
Other classes¶
-
class
supybot.irclib.
Batch
(type, arguments, messages)¶ Bases:
tuple
Represents a batch of messages, see <https://ircv3.net/specs/extensions/batch-3.2>
-
arguments
¶ Alias for field number 1
-
messages
¶ Alias for field number 2
-
type
¶ Alias for field number 0
-
-
class
supybot.irclib.
IrcCallback
(*args, **kwargs)[source]¶ Bases:
supybot.irclib.IrcCommandDispatcher
,supybot.log.Firewalled
Base class for standard callbacks.
Callbacks derived from this class should have methods of the form “doCommand” – doPrivmsg, doNick, do433, etc. These will be called on matching messages.
-
callPrecedence
(*args, **kwargs)¶ Returns a pair of (callbacks to call before me, callbacks to call after me)
-
die
(*args, **kwargs)¶ Makes the callback die. Called when the parent Irc object dies.
-
inFilter
(*args, **kwargs)¶ Used for filtering/modifying messages as they’re entering.
ircmsgs.IrcMsg objects are immutable, so this method is expected to return another ircmsgs.IrcMsg object. Obviously the same IrcMsg can be returned.
-
name
(*args, **kwargs)¶ Returns the name of the callback.
-
outFilter
(*args, **kwargs)¶ Used for filtering/modifying messages as they’re leaving.
As with inFilter, an IrcMsg is returned.
-
postTransition
(*args, **kwargs)¶ Called when the state of the IRC connection changes.
msg is the message that triggered the transition, if any.
-
reset
(*args, **kwargs)¶ Resets the callback. Called when reconnecting to the server.
-
-
class
supybot.irclib.
IrcCommandDispatcher
[source]¶ Bases:
object
Base class for classes that must dispatch on a command.
-
class
supybot.irclib.
IrcMsgQueue
(iterable=())[source]¶ Bases:
object
Class for a queue of IrcMsgs. Eventually, it should be smart.
Probably smarter than it is now, though it’s gotten quite a bit smarter than it originally was. A method to “score” methods, and a heapq to maintain a priority queue of the messages would be the ideal way to do intelligent queuing.
As it stands, however, we simply keep track of ‘high priority’ messages, ‘low priority’ messages, and normal messages, and just make sure to return the ‘high priority’ ones before the normal ones before the ‘low priority’ ones.