Extensions¶
This chapter presents the extensions that are included by default with PyIRC. Extensions are the mechanism PyIRC uses to implement various functionality that may overlap or conflict, whilst ensuring everything cooperates.
autojoin
--- Automatically join channels on connection¶
Join channels on connection automatically
-
class
PyIRC.extensions.autojoin.
AutoJoin
(*args, **kwargs)¶ This extension will autojoin the channels you specify, without flooding off the network. The initial delay to first join and delay between each successive channel is customisable.
-
__init__
(*args, **kwargs)¶ Initialise the AutoJoin extension.
Key join: A Mapping (dictionary type) or Iterable of channels to join. If a Mapping is passed, keys are treated as channel names and values are used as keys to join the channel. If an Iterable is passed, each value is a channel and no keys are specified when joining. Key autojoin_wait_start: How much time, in seconds, to wait for autojoin to begin. The default is 0.75 seconds. Key autojoin_wait_interval: How much time, in seconds, to wait between each join. The default is 0.25 seconds.
-
bantrack
--- Track and introspect ban and list modes¶
Track IRC ban modes (+beIq)
In order to be taught about new types, this extension must know the numerics used for ban listing.
-
class
PyIRC.extensions.bantrack.
BanEntry
(string, setter, timestamp)¶ -
__getnewargs__
()¶ Return self as a plain tuple. Used by copy and pickle.
-
__getstate__
()¶ Exclude the OrderedDict from pickling
-
static
__new__
(_cls, string, setter, timestamp)¶ Create new instance of BanEntry(string, setter, timestamp)
-
__repr__
()¶ Return a nicely formatted representation string
-
setter
¶ Alias for field number 1
-
string
¶ Alias for field number 0
-
timestamp
¶ Alias for field number 2
-
-
class
PyIRC.extensions.bantrack.
BanTrack
(base, **kwargs)¶ Track bans and other "list" modes.
This augments the
ChannelTrack
extension.Although the actual reporting is done by
BaseTrack
, this helps with the actual retrieval of the modes, and setting synched states.Note
Unless you are opped, your view of modes such as +eI may be limited and incomplete.
basetrack
--- Core tracking functionality¶
Base tracking API.
This is not really meant for direct use; it converts commands into events for ingestion into the other tracking components.
-
class
PyIRC.extensions.basetrack.
BaseTrack
(*args, **kwargs)¶ Base tracking extension, providing events for other tracking extensions.
This extension adds
base.base_track
as itself as an alias forget_extension("BaseTrack").
.
-
class
PyIRC.extensions.basetrack.
Mode
(mode, param, adding)¶ A mode being added or removed
-
__getnewargs__
()¶ Return self as a plain tuple. Used by copy and pickle.
-
__getstate__
()¶ Exclude the OrderedDict from pickling
-
static
__new__
(_cls, mode, param, adding)¶ Create new instance of Mode(mode, param, adding)
-
__repr__
()¶ Return a nicely formatted representation string
-
adding
¶ Alias for field number 2
-
mode
¶ Alias for field number 0
-
param
¶ Alias for field number 1
-
-
class
PyIRC.extensions.basetrack.
ModeEvent
(event, setter, target, mode, param=None, adding=True, timestamp=None)¶ An event triggered upon mode changes.
-
__init__
(event, setter, target, mode, param=None, adding=True, timestamp=None)¶ Initalise the ModeEvent instance.
Parameters: - event -- The event fired
- line -- The
Line
instance of the firing mode. - setter -- The
Hostmask
of the setter of this mode, orNone
when unknown. - target -- The target of this command, as a regular string.
- adding -- Set to
True
if the mode is being added to the target, orFalse
if being removed. Consumers should be prepared for redundant modes, as many IRC daemons do not do strict checking for performance reasons. - mode -- The mode being set or unset.
- param -- The parameter of the mode, set to
None
for most modes. - timestamp -- The time this mode was set. If None, the current system time will be used.
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
PyIRC.extensions.basetrack.
ScopeEvent
(event, target, scope=None, leaving=None, reason=None, gecos=None, account=None, modes=None, cause=None)¶ User changing scope event
-
__init__
(event, target, scope=None, leaving=None, reason=None, gecos=None, account=None, modes=None, cause=None)¶ Initalise the UserScopeEvent instance
Parameters: - target --
Hostmask
of user that is changing scope. - scope -- Scope of the change, None for global, or set to a channel.
- leaving -- Whether or not the user is leaving, may be
None
for not applicable. - reason -- Reason for change.
- gecos -- GECOS of the user changing scope, may be
None
. - account -- Account of the user changing scope, may be
None
. - modes -- Modes of the user that are being explicitly added or removed by scope change.
- cause -- User that caused this change.
- target --
-
basicapi
--- High-level, easy-to-use IRC API¶
A basic easy-to-use API
This provides simple interfaces to messaging, responses, topic setting, and basic channel access control.
-
class
PyIRC.extensions.basicapi.
BasicAPI
(*args, **kwargs)¶ Basic API functions, designed to make things easier to use.
This extension adds
base.basicapi
as itself as an alias forget_extension("basicapi").
.-
ban
(channel, *args)¶ Ban a user (or users) on a given channel.
Parameters: Note
All items are passed through
process_bantargs
.
-
banexempt
(channel, *args)¶ Exempt a user (or users) from being banned on a given channel.
Most (but not all) servers support this. IRCNet notably does not.
Parameters: Note
All items are passed through
process_bantargs
.
-
dehalfop
(channel, *args)¶ Dehalfop a user (or users) on a given channel.
This may not be supported by your IRC server. Notably, FreeNode, EfNet, and IRCNet do not support this.
Parameters:
-
deop
(channel, *args)¶ Deop a user (or users) on a given channel.
Parameters:
-
devoice
(channel, *args)¶ Devoice a user (or users) on a given channel.
Parameters:
-
halfop
(channel, *args)¶ Halfop a user (or users) on a given channel.
This may not be supported by your IRC server. Notably, FreeNode, EfNet, and IRCNet do not support this.
Parameters:
-
inviteexempt
(channel, *args)¶ Invite exempt a user (or users) on a given channel.
Most (but not all) servers support this. IRCNet notably does not.
Parameters: Note
All items are passed through
process_bantargs
.
-
join
(channel, key=None)¶ Attempt to join a channel.
Parameters: - channel -- Name of the Channel to join.
- key -- Channel key to use, if needed.
-
kick
(channel, user, reason=None)¶ Kick a user from a channel.
..note:: This command usually requires channel operator privileges.
Parameters:
-
message
(target, message, notice=False)¶ Send a message to a target.
Parameters: Warning
Use notice judiciously, as many users find them irritating!
-
mode_params
(add, mode, target, *args)¶ Set modes on a channel with a given target list.
This is suitable for mass bans/unbans, special status modes, and more.
Parameters:
-
op
(channel, *args)¶ Op a user (or users) on a given channel.
Parameters:
-
part
(channel, reason=None)¶ Part a channel.
Parameters: - channel -- Channel to part from. This can be a
Channel
instance, or a string. - reason -- Freeform reason to leave the channel.
- channel -- Channel to part from. This can be a
-
process_bantargs
(*args)¶ Process ban targets (as used by ban modes).
Note
The default mask format is $a:account if an account is available for the user. This only works on servers that support extended bans. The fallback is
*!*@host
. This may not be suitable for all uses. It is recommended more advanced users use strings instead of User instances.
-
quiet
(channel, *args)¶ Quiet a user (or users) on a given channel.
Many servers do not support this. This supports the charybdis-derived variant. This means it will work on Charybdis and ircd-seven networks (notably FreeNode) but few others.
InspIRCd and (UnrealIRCd) support will come eventually.
This requires
ISupport
be enabled, to disambiguate quiet from owner on UnrealIRCd and InspIRCd.Parameters: Note
All items are passed through
process_bantargs
.
-
reply_target
(line)¶ Get the appropriate target to reply to a given line.
Parameters: line -- Line
instance of the message to get the reply target of. This is needed due to the limitations of the IRC framing format.Returns: Target to reply to
-
topic
(channel, topic)¶ Set the topic in a channel.
Note
You usually must be opped to set the topic in a channel. This command may fail, and this function cannot tell you due to IRC's asynchronous nature.
Parameters: - channel -- Channel to set the topic in. This can be either a
Channel
instance or a string. - topic -- Topic to set in channel. Will unset the topic if set to None or the empty string.
- channel -- Channel to set the topic in. This can be either a
-
unban
(channel, *args)¶ Unban a user (or users) on a given channel.
Note at present this is not reliable if User instances are passed in. This is an unfortunate side effect of the way IRC works (ban masks may be freeform). Another extension may provide enhanced capability to do this in the future.
Parameters: Note
All items are passed through
process_bantargs
.
-
unbanexempt
(channel, *args)¶ Un-exempt a user (or users) from being banned on a given channel.
Most (but not all) servers support this. IRCNet notably does not.
Note at present this is not reliable if User instances are passed in. This is an unfortunate side effect of the way IRC works (ban masks may be freeform). Another extension may provide enhanced capability to do this in the future.
Parameters: Note
All items are passed through
process_bantargs
.
-
uninviteexempt
(channel, *args)¶ Un-invite exempt a user (or users) on a given channel.
Most (but not all) servers support this. IRCNet notably does not.
Note at present this is not reliable if User instances are passed in. This is an unfortunate side effect of the way IRC works (masks may be freeform). Another extension may provide enhanced capability to do this in the future.
Parameters: Note
All items are passed through
process_bantargs
.
-
unquiet
(channel, *args)¶ Unquiet a user (or users) on a given channel.
Many servers do not support this. This supports the charybdis-derived variant. This means it will work on Charybdis and ircd-seven networks (notably FreeNode) but few others.
InspIRCd and (UnrealIRCd) support will come eventually.
This requires
ISupport
be enabled, to disambiguate quiet from owner on UnrealIRCd and InspIRCd.Note at present this is not reliable if
User
instances are passed in. This is an unfortunate side effect of the way IRC works (masks may be freeform). Another extension may provide enhanced capability to do this in the future.Parameters: Note
All items are passed through
process_bantargs
.
-
basicrfc
--- Core RFC 1459 components¶
Bare minimum IRC RFC standards support
-
class
PyIRC.extensions.basicrfc.
BasicRFC
(*args, **kwargs)¶ Basic RFC1459 support.
This is basically just a module that ensures your bot doesn't time out and can track its own nick. Nobody is making you use this implementation, but it is highly recommended.
This extension adds
base.basic_rfc
as itself as an alias forget_extension("BasicRFC").
.Variables: - nick -- Our present real nickname as reported by the IRC server.
- prev_nick -- If we get a NICK event from the server, and it's for us, our last nick will be stored here. Useful in case of services collisions that change our nick, SANICK/FORCENICK operator abuse, or another extension changes our nick.
cap
--- CAP command support¶
IRC CAP negotation sub-protocol extensions
For more information, see: http://ircv3.atheme.org/specification/capability-negotiation-3.1
-
class
PyIRC.extensions.cap.
CAPEvent
(event, line, caps)¶ A CAP ACK/NEW event
-
class
PyIRC.extensions.cap.
CapNegotiate
(*args, **kwargs)¶ Basic CAP negotiation
IRCv3.2 negotiation is attempted, but earlier specifications will be used in a backwards compatible manner.
This extension does little on its own, but provides a public API.
This extension adds
base.cap_negotiate
as itself as an alias forget_extension("CapNegotiate").
.Variables: - supported -- Supported capabilities - these are the capabilities we support, at least, in theory.
- remote -- Remote capabilities - that is, what the server supports.
- local -- Local capabilities - these are what we actually support.
- negotiating -- Whether or not CAP negotiation is in progress.
-
cont
(event)¶ Continue negotiation of caps
-
static
create_str
(cap, params)¶ Create a capability string
-
dispatch
(event)¶ Dispatch the CAP command
-
static
extract_caps
(line)¶ Extract caps from a line
-
static
parse_cap
(string)¶ Parse a capability string
-
register
(cap, params=[], replace=False)¶ Register that we support a specific CAP
Parameters: - cap -- The capability to register support for
- params -- The parameters to pass for the CAP (IRCv3 extension)
- replace -- Replace existing CAP report, if present
-
requires
= ['BasicRFC']¶ Presently supported maximum CAP version.
-
unregister
(cap)¶ Unregister support for a specific CAP.
Parameters: cap -- Capability to remove
channeltrack
--- Track and introspect channel properties and metadata¶
Track channels that we have joined and their associated data
This data includes ops, modes, the topic, and associated data.
-
class
PyIRC.extensions.channeltrack.
Channel
(case, name, **kwargs)¶ A channel entity
-
__init__
(case, name, **kwargs)¶ Store the data for a channel.
Unknown values are stored as None, whereas empty ones are stored as '' or 0, so take care in comparisons involving values from this class.
Key name: Name of the channel, not casemapped. Key topic: The channel topic. Key topictime: Time the channel topic was set, in Unix time. Key topicwho: Who set the topic, as a freeform string. Key users: A mapping containing user to their channel status modes. Key timestamp: Timestamp of the channel (channel creation), in Unix time. Key url: URL of the channel, sent on some IRC servers.
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
PyIRC.extensions.channeltrack.
ChannelTrack
(*args, **kwargs)¶ Tracks channels and the users on the channels.
Only the user's casemapped nicks are stored, as well as their statuses. They are stored casemapped to make it easier to look them up in other extensions.
This extension adds
base.channel_track
as itself as an alias forget_extension("ChannelTrack").
.- channels
- Mapping of channels, where the keys are casemapped channel names, and the values are Channel instances.
For more elaborate user tracking, see :py:module::~PyIRC.extensions.usertrack.
-
add_channel
(name, **kwargs)¶ Add a channel to the tracking dictionary.
Avoid using this method directly unless you know what you are doing.
-
get_channel
(name)¶ Retrieve a channel from the tracking dictionary based on name.
Use of this method is preferred to directly accessing the channels dictionary.
Returns None if channel not found.
Arguments:
Parameters: name -- Name of the channel to retrieve.
-
remove_channel
(name)¶ Remove a channel from the tracking dictionary.
Avoid using this method directly unless you know what you are doing.
ctcp
--- Easy handling of CTCP messages¶
Client to Client Protocol extensions and events
-
class
PyIRC.extensions.ctcp.
CTCP
(*args, **kwargs)¶ Add CTCP dispatch functionaltiy.
Hooks may be added by having a commands_ctcp or commands_nctcp mapping in your base class.
-
__init__
(*args, **kwargs)¶ Initalise the CTCP extension.
Key ctcp_version: Version string to use, defaults to default_version.
-
c_ping
(event)¶ Respond to CTCP ping
-
c_version
(event)¶ Respond to CTCP version
-
ctcp
(target, command, param=None)¶ CTCP a target a given command
-
ctcp_in
(event)¶ Check message for CTCP (incoming) and dispatch if necessary.
-
default_version
= 'Powered by PyIRC v3.0-a[0a224e5]'¶ Default CTCP version string to use
-
nctcp
(target, command, param=None)¶ Reply to a CTCP
-
nctcp_in
(event)¶ Check message for NCTCP (incoming) and dispatch if necessary.
-
-
class
PyIRC.extensions.ctcp.
CTCPEvent
(event, ctcp, line)¶ A CTCP event
isupport
--- Introspect server properties and metadata¶
Enumeration of IRC server features and extensions
ISUPPORT is a non-standard but widely supported IRC extension that is used to advertise what a server supports to a client. Whilst non-standard, most servers follow a standard format for many parameters.
-
class
PyIRC.extensions.isupport.
ISupport
(*args, **kwargs)¶ Parse ISUPPORT attributes into useful things.
Parsing is done according to the semantics defined by
isupport_parse`
.This extension adds
base.isupport
as itself as an alias forget_extension("ISupport").
.Variables: supported -- Parsed ISUPPORT data from the server. Do note that because ISUPPORT is technically non-standard, users should be prepared for data that does not conform to any implied standard. -
defaults
= {'CHANTYPES': '#&!+', 'CASEMAPPING': 'RFC1459', 'NICKLEN': '8', 'CHANMODES': ['b', 'k', 'l', 'imnstp'], 'PREFIX': ['o', 'v', '@', '+']}¶ Defaults until overridden, for old server compat.
-
get
(string)¶ Get an ISUPPORT string.
Returns False if not found, True for keyless values, and the value for keyed values.
The following values are guaranteed to be present:
- CHANTYPES (value is a string)
- PREFIX (value is of format "(modes)symbols for modes")
- CASEMAPPING (ascii or rfc1459)
- NICKLEN (value is a number, but stored as a string)
- CHANMODES (list of values enumerating modes into four distinct classes, respectively: list modes, modes that send a parameter, modes that send a parameter only when set, and parameterless modes)
Parameters: string -- ISUPPORT string to look up.
-
isupport
(event)¶ Handle ISUPPORT event
-
kickrejoin
--- Automatically rejoin channel after KICK/REMOVE¶
Rejoin automatically after being kicked from a channel.
This extension is also meant to serve as an example for extension authors. It is heavily documented and designed to be very easy to follow.
-
class
PyIRC.extensions.kickrejoin.
KickRejoin
(*args, **kwargs)¶ Rejoin a channel automatically after being kicked or removed.
-
__init__
(*args, **kwargs)¶ Initialise the KickRejoin extension.
Key rejoin_delay: Seconds to delay until the channel is rejoined. This defaults to 5, but can be set to anything. Some people may think you're rude if you set it to 0. Key rejoin_on_remove: Boolean defining whether to rejoin if you are 'removed'. Note that most servers propogate REMOVE as KICK to clients so it won't always work (the sole exception in testing this extension was Freenode). Defaults to True, because REMOVE is silly anyway.
-
join
(channel)¶ Join the specified channel and remove the channel from the pending rejoin list.
-
on_disconnected
(event)¶ Disconnection event handler.
We must ensure that any pending rejoins are unscheduled, so that we don't do something silly like sending JOIN to a closed socket.
-
on_kick
(event)¶ Command handler for KICK and PART.
This method receives a LineEvent object as its parameter, and will use it to determine if we were the ones kick/removed, and what action to take.
-
on_part_out
(event)¶ Command handler for PART's that are outgoing
This is used to ensure we know when we PART a channel, it's voluntary.
-
requires
= ['BasicRFC', 'ISupport']¶ Describes what extensions are required to use this extension. We use the
basicrfc.BasicRFC
extension for nick tracking.isupport.ISupport
is used for prefixes discovery.
-
lag
--- Track lag to the IRC server¶
Latency measurements to the server
-
class
PyIRC.extensions.lag.
LagCheck
(*args, **kwargs)¶ Lag measurement extension. Checks latency periodically.
Variables: lag -- Current lag measurements from the server, measured in seconds. It is not advisable to rely on less than a millisecond of precision on most systems and real-world networks. -
__init__
(*args, **kwargs)¶ Initialise the LagCheck extension
Key lagcheck: Time interval to do periodic lag checks to update the lag timer. Defaults to 15 seconds. Setting the value too low may result in being disconnected by the server.
-
ping
()¶ Callback for ping
-
pong
(event)¶ Use PONG reply to check lag
-
start
(event)¶ Begin sending PING requests as soon as possible
-
static
timestr
(time)¶ Return a random string based on the current time
-
sasl
--- SASL authentication services¶
Identification to services
SASL is a mechanism used by IRCv3 to authenticate clients to services in a standard and user-friendly way. A variety of mechanisms are supported by most servers, but only PLAIN is supported by this module at the moment.
services¶
Utilities for interacting with IRC services
-
class
PyIRC.extensions.services.
ServicesLogin
(*args, **kwargs)¶ Support services login.
Use of this module is discouraged. Use the SASL module if at all possible. It is not possible to know if our authentication was a success or failure, because services may use any string to report back authentication results, and they are often localised depending on IRC network.
It also creates a security hole, as you can never be 100% sure who or what you're talking to (though some networks support a full nick!user@host in the target to message a user). This makes password disclosure much more likely.
This extension adds
base.services_login` as itself as an alias for ``get_extension("ServicesLogin").
.-
__init__
(*args, **kwargs)¶ Initalise the ServicesLogin extension.
Key services_username: The username to use for authentication. Key services_password: The password to use for authentication. Key services_idenitfy_fmt: A format string using {username} and {password} to send the correct message to services. Key services_bot: The user to send authentication to (defaults to NickServ). Can be a full nick!user@host set for the networks that support or require this mechanism. Key services_command: Command to use to authenticate. Defaults to PRIVMSG, but NS/NICKSERV are recommended for networks that support it for some improved security.
-
starttls
--- Upgrade connection to SSL (where supported)¶
Automatic SSL negotiation
It's a little like the ESMTP STARTTLS command, but the server does not forget all of the client state after it is issued. Therefore, it should be issued as quickly as possible.
usertrack
--- Track and introspect user properties and metadata¶
Track users we have seen and their associated data
Tracks users we know about, whether on channels or through private messages. Maintains state such as nicknames, channel statuses, away status, and the like.
-
class
PyIRC.extensions.usertrack.
User
(case, nick, **kwargs)¶ A user entity.
Variables: channels -- Mapping of channels, where the keys are casemapped channel names, and the values are their status modes on the channel. For more elaborate channel tracking, see :py:module::~PyIRC.extensions.channeltrack.
-
__init__
(case, nick, **kwargs)¶ Store the data for a user.
Unknown values are stored as None, whereas empty ones are stored as '' or 0, so take care in comparisons involving values from this class.
Parameters: - nick -- Nickname of the user, not casemapped.
- case -- Casemapping to use for channels member.
Key username: Username of the user, or ident (depending on IRC daemon).
Key host: Hostname of the user. May be fake due to a cloak.
Key gecos: The GECOS (aka "real name") of a user. Usually just freeform data of dubious usefulness.
Key account: Services account name of the user.
Key server: Server the user is on. Not always reliable or present.
Key secure: User is using SSL. Always assume unsecured unless set to True.
Key operator: User is an operator. Being set to None does not guarantee a user is not an operator due to IRC daemon limitations and data hiding.
Key signon: Signon time for the user. May not be set.
Key ip: IP for the user reported from the server. May be bogus and likely nonexistent on networks with host cloaking.
Key realhost: Real hostname for a user. Probably not present in most cases.
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
PyIRC.extensions.usertrack.
UserTrack
(*args, **kwargs)¶ Track various user metrics, such as account info, and some channel tracking.
This extension adds
base.user_track
as itself as an alias forget_extension("UserlTrack").
.Variables: users -- Mapping of users, where the keys are casemapped nicks, and values are User instances. You should probably prefer get_user
to direct lookups on this dictionary.-
add_user
(nick, **kwargs)¶ Add a user to the tracking dictionary.
Avoid using this method directly unless you know what you are doing.
-
authenticate
(nick, callback)¶ Get authentication for a user and return result in a callback
Parameters: - nick -- Nickname of user to check authentication for
- callback -- Callback to call for user when authentication is discovered. The User instance is passed in as the first parameter, or None if the user is not found. Use functools.partial to pass other arguments.
-
get_user
(nick)¶ Retrieve a user from the tracking dictionary based on nick.
Use of this method is preferred to directly accessing the user dictionary.
Parameters: nick -- Nickname of the user to retrieve. Returns: A User
instance, or None if user not found.
-
remove_user
(nick)¶ Remove a user from the tracking dictionary.
Avoid using this method directly unless you know what you are doing.
-
timeout_user
(nick)¶ Time a user out, cancelling existing timeouts
Avoid using this method directly unless you know what you are doing.
-
update_username_host
(hostmask_or_line)¶ Update a user's basic info, based on line hostmask info.
Avoid using this method directly unless you know what you are doing.
Note
This mostly exists for brain-dead networks that don't quit users when they get cloaked.
-