API reference¶
Connections¶
-
class
omnipresence.connection.Connection[source]¶ Omnipresence’s core IRC client protocol.
See Twisted’s IRCClient documentation for details on methods used to perform basic actions.
-
reply(string, request, tail='')¶ Send a reply string, truncated to
MAX_REPLY_LENGTHcharacters, withtailappended. If the request venue is a channel, send the reply to the venue as a standard message addressed to request‘starget, formatted using thevenue‘s reply format. Otherwise, send the reply as a notice to request‘sactor.
-
is_channel(name)¶ Return
Trueif name belongs to a channel, according to the server-provided list of channel prefixes, orFalseotherwise.
-
suspend_joins()¶ Suspend all channel joins until
resume_joinsis called.
-
resume_joins()¶ Resume immediate joining of channels after suspending it with
suspend_joins, and perform any channel joins that have been queued in the interim.
-
case_mapping¶ The
CaseMappingcurrently in effect on this connection. Defaults torfc1459if none is explicitly provided by the server.
-
parser¶ The
RawMessageParserbeing used on this connection.
-
reactor¶ The reactor in use on this client. This may be overridden when a deterministic clock is needed, such as in unit tests.
-
-
class
omnipresence.connection.VenueInfo(case_mapping=None)[source]¶ A container for information about a venue.
-
modes= None¶ A mapping of modes currently active on this channel to one of
False(not set or invalid),True(set, for modes that take no arguments), a single number or string, or a set ofHostmaskobjects.
-
nicks= None¶ A dictionary mapping nicks to
VenueUserInfoobjects.
-
topic= None¶ This channel’s topic, or the empty string if none is set.
-
-
class
omnipresence.connection.VenueUserInfo[source]¶ A container for information about a user’s state in a particular venue.
-
reply_buffer= None¶ This user’s current channel reply buffer.
-
-
omnipresence.connection.MAX_REPLY_LENGTH= 288¶ The maximum length of a single command reply, in bytes.
Messages¶
-
class
omnipresence.message.Message(connection, outgoing, action, actor=None, venue=None, target=None, subaction=None, content=None)[source]¶ Represents a message, loosely defined as an event to which plugins can respond. Messages have the following basic attributes:
-
connection¶ The
Connectionon which the message was received.
-
outgoing¶ A boolean indicating whether this message resulted from a bot action.
-
action¶ This message’s
MessageType. A string containing a message type name may be passed to the constructor, but the property always contains an enumeration member.
-
actor¶ A
Hostmaskcorresponding to the message prefix, indicating the message’s true origin. In some cases,unknownmessages will set this attribute toNoneif a prefix could not be parsed.
-
venue¶ -
target¶ -
subaction¶ -
content¶ Optional attributes, whose presence and meaning depend on the message type. An attribute is
Noneif and only if it is not used by the current message type, and a string value otherwise.
-
raw¶ If this message was created by parsing a raw message with
RawMessageParser.parse, the original raw IRC message string passed to that function. Otherwise,None.
Note
All string values are byte strings, not Unicode strings, and therefore must be appropriately decoded when necessary.
The following additional properties are derived from the values of one or more basic attributes, and are included for convenience:
-
encoding¶ The character encoding in effect for this message’s venue.
New message objects can be created using either the standard constructor, or by parsing a raw IRC message string using
RawMessageParser.parse.Messageis anamedtupletype, and thus its instances are immutable. To create a new object based on the attributes of an existing one, use an instance’s_replacemethod.-
-
class
omnipresence.message.MessageType[source]¶ An enumeration of valid values of
Message.action.The following message types directly correspond to incoming or outgoing IRC messages (also see RFC 1459#section-4):
-
action= <MessageType.action: 1>¶ Represents a CTCP ACTION (
/me). All attributes are as for theprivmsgtype.
-
ctcpquery= <MessageType.ctcpquery: 2>¶ Represents an otherwise unrecognized CTCP query wrapped in a
PRIVMSG.venueis the nick or channel name of the recipient.subactionis the CTCP message tag.contentis a string containing any trailing arguments.Note
Omnipresence does not support mixed messages containing both normal and CTCP extended content.
-
ctcpreply= <MessageType.ctcpreply: 3>¶ Represents an unrecognized CTCP reply wrapped in a
NOTICE. All attributes are as for thectcpquerytype.
-
kick= <MessageType.kick: 5>¶ Represents a kick.
venueis the channel the kick took place in.targetis the nick of the kicked user.contentis the kick message.
-
mode= <MessageType.mode: 6>¶ Represents a mode change.
venueis the affected channel or nick.contentis the mode change string.
-
part= <MessageType.part: 9>¶ Represents a channel part.
venueis the channel being departed from.contentis the part message.
-
privmsg= <MessageType.privmsg: 10>¶ Represents a typical message.
venueis the nick or channel name of the recipient. (privatecan also be used to determine whether a message was sent to a single user or a channel.)contentis the text of the message.
-
quit= <MessageType.quit: 11>¶ Represents a client quit from the IRC network.
contentis the quit message.
-
topic= <MessageType.topic: 12>¶ Represents a topic change.
venueis the affected channel.contentis the new topic, or an empty string if the topic is being unset.
-
unknown= <MessageType.unknown: 0>¶ Represents a message that is not of any known type, or that could not be correctly parsed.
subactionis the IRC command name or numeric.contentis a string containing any trailing arguments.
Omnipresence defines additional message types for synthetic events:
-
connected= <MessageType.connected: 9001>¶ Created when the server has responded with
RPL_WELCOME. No optional arguments are specified.
-
disconnected= <MessageType.disconnected: 9002>¶ Created when the connection to the server has been closed or lost. No optional arguments are specified.
-
-
class
omnipresence.message.parser.RawMessageParser[source]¶ An implementation of the parsing rules for a specific version of the IRC protocol.
In most cases, you should use the
parserattribute of aConnectionto retrieve an instance of this class.
Hostmasks¶
Operations on IRC hostmasks.
-
class
omnipresence.hostmask.Hostmask[source]¶ Represents an IRC hostmask (sometimes called a message prefix) of the form
nick!user@host. The user and host attributes are optional, and default toNoneif not present.-
classmethod
from_string(string)[source]¶ Return a new
Hostmaskobject parsed from string, according to the definition of<prefix>in RFC 1459#section-2.3.1.
-
has_wildcard¶ Trueif this hostmask contains a wildcard or anyNonecomponents. Otherwise,Falseotherwise.
-
matches(other, case_mapping=None)[source]¶ Check whether this hostmask matches the pattern in other, which can be a
Hostmaskobject or a string in the form"nick!user@host", according to the wildcard expansion rules in RFC 2812#section-2.5. ACaseMappingobject may optionally be provided, in which case nicks are compared case-insensitively according to the mapping’s rules; otherwise, nick comparisons are fully case-sensitive. Users and hosts are always compared case-insensitively, using normal ASCII case folding rules.Briefly,
*and?wildcards match zero or more and exactly one non-delimiter character, respectively; a backslash can be used to escape these special characters. Components that equalNoneare assumed to match all possible values for that component.Warning
This method only matches wildcards in other, not the
Hostmaskobject it is called on:>>> Hostmask.from_string('nick!user@host').matches('nick!*@*') True >>> Hostmask.from_string('nick!*@*').matches('nick!user@host') False
-
classmethod
Case mappings¶
Operations on IRC case mappings.
-
class
omnipresence.case_mapping.CaseMapping(lower, upper)[source]¶ Provides convenience methods for bidirectional string translation given a mapping of characters from lower to upper.
-
classmethod
by_name(name)[source]¶ Return an IRC case mapping given the name used in the
CASEMAPPINGparameter of aRPL_ISUPPORTIRC message (numeric 005). The following mapping names are recognized:-
ascii Treats the letters A-Z as uppercase versions of the letters a-z.
-
strict-rfc1459 Extends the
asciicase mapping to further treat {}| as the lowercase versions of []\. This matches the rules specified in RFC 1459#section-2.2.
-
rfc1459 Extends the
strict-rfc1459case mapping to further treat ~ as the lowercase version of ^. This corresponds to most servers’ actual implementation of the RFC 1459 rules.
ValueErroris raised on an unrecognized mapping name.-
-
equates(one, two)[source]¶ Return a boolean value indicating whether a and b are equal under this case mapping.
-
classmethod
-
class
omnipresence.case_mapping.CaseMappedDict(initial=None, case_mapping=None)[source]¶ A dictionary whose keys are treated case-insensitively according to a
CaseMappingor mapping name string (as given toby_name) provided on instantiation.
Web resource interactions¶
Human-readable output helpers¶
Functions for presenting data in human-readable forms.
-
omnipresence.humanize.ago(then, now=None)[source]¶ Given a
datetimeobject, return an English string giving an approximate relative time, such as “5 days ago”.
-
omnipresence.humanize.andify(seq, two_comma=False)[source]¶ Join the elements of a sequence and return a string of the form “x and y” for a two-element list, or “x, y, and z” for three or more elements. If two_comma is True, insert a comma before “and” even if the list is only two elements long (“x, and y”).