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_LENGTH
characters, withtail
appended. 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
True
if name belongs to a channel, according to the server-provided list of channel prefixes, orFalse
otherwise.
-
suspend_joins
()¶ Suspend all channel joins until
resume_joins
is 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
CaseMapping
currently in effect on this connection. Defaults torfc1459
if none is explicitly provided by the server.
-
parser
¶ The
RawMessageParser
being 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 ofHostmask
objects.
-
nicks
= None¶ A dictionary mapping nicks to
VenueUserInfo
objects.
-
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
Connection
on 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
Hostmask
corresponding to the message prefix, indicating the message’s true origin. In some cases,unknown
messages will set this attribute toNone
if a prefix could not be parsed.
-
venue
¶ -
target
¶ -
subaction
¶ -
content
¶ Optional attributes, whose presence and meaning depend on the message type. An attribute is
None
if 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
.Message
is anamedtuple
type, and thus its instances are immutable. To create a new object based on the attributes of an existing one, use an instance’s_replace
method.-
-
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 theprivmsg
type.
-
ctcpquery
= <MessageType.ctcpquery: 2>¶ Represents an otherwise unrecognized CTCP query wrapped in a
PRIVMSG
.venue
is the nick or channel name of the recipient.subaction
is the CTCP message tag.content
is 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 thectcpquery
type.
-
kick
= <MessageType.kick: 5>¶ Represents a kick.
venue
is the channel the kick took place in.target
is the nick of the kicked user.content
is the kick message.
-
mode
= <MessageType.mode: 6>¶ Represents a mode change.
venue
is the affected channel or nick.content
is the mode change string.
-
part
= <MessageType.part: 9>¶ Represents a channel part.
venue
is the channel being departed from.content
is the part message.
-
privmsg
= <MessageType.privmsg: 10>¶ Represents a typical message.
venue
is the nick or channel name of the recipient. (private
can also be used to determine whether a message was sent to a single user or a channel.)content
is the text of the message.
-
quit
= <MessageType.quit: 11>¶ Represents a client quit from the IRC network.
content
is the quit message.
-
topic
= <MessageType.topic: 12>¶ Represents a topic change.
venue
is the affected channel.content
is 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.
subaction
is the IRC command name or numeric.content
is 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
parser
attribute of aConnection
to 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 toNone
if not present.-
classmethod
from_string
(string)[source]¶ Return a new
Hostmask
object parsed from string, according to the definition of<prefix>
in RFC 1459#section-2.3.1.
-
has_wildcard
¶ True
if this hostmask contains a wildcard or anyNone
components. Otherwise,False
otherwise.
-
matches
(other, case_mapping=None)[source]¶ Check whether this hostmask matches the pattern in other, which can be a
Hostmask
object or a string in the form"nick!user@host"
, according to the wildcard expansion rules in RFC 2812#section-2.5. ACaseMapping
object 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 equalNone
are assumed to match all possible values for that component.Warning
This method only matches wildcards in other, not the
Hostmask
object 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
CASEMAPPING
parameter of aRPL_ISUPPORT
IRC 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
ascii
case mapping to further treat {}| as the lowercase versions of []\. This matches the rules specified in RFC 1459#section-2.2.
-
rfc1459
Extends the
strict-rfc1459
case mapping to further treat ~ as the lowercase version of ^. This corresponds to most servers’ actual implementation of the RFC 1459 rules.
ValueError
is 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
CaseMapping
or 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
datetime
object, 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”).