evennia.server.portal.irc

This connects to an IRC network/channel and launches an ‘bot’ onto it. The bot then pipes what is being said between the IRC channel and one or more Evennia channels.

evennia.server.portal.irc.parse_ansi_to_irc(string)[source]

Parse |-type syntax and replace with IRC color markers

Parameters

string (str) – String to parse for ANSI colors.

Returns

parsed_string (str) – String with replaced ANSI colors.

evennia.server.portal.irc.parse_irc_to_ansi(string)[source]

Parse IRC mIRC color syntax and replace with Evennia ANSI color markers

Parameters

string (str) – String to parse for IRC colors.

Returns

parsed_string (str) – String with replaced IRC colors.

class evennia.server.portal.irc.IRCBot[source]

Bases: twisted.words.protocols.irc.IRCClient, evennia.server.session.Session

An IRC bot that tracks activity in a channel as well as sends text to it when prompted

lineRate = 1
nickname = None
logger = None
factory = None
channel = None
sourceURL = 'http://code.evennia.com'
signedOn()[source]

This is called when we successfully connect to the network. We make sure to now register with the game as a full session.

disconnect(reason='')[source]

Called by sessionhandler to disconnect this protocol.

Parameters

reason (str) – Motivation for the disconnect.

at_login()[source]
privmsg(user, channel, msg)[source]

Called when the connected channel receives a message.

Parameters
  • user (str) – User name sending the message.

  • channel (str) – Channel name seeing the message.

  • msg (str) – The message arriving from channel.

action(user, channel, msg)[source]

Called when an action is detected in channel.

Parameters
  • user (str) – User name sending the message.

  • channel (str) – Channel name seeing the message.

  • msg (str) – The message arriving from channel.

get_nicklist()[source]

Retrieve name list from the channel. The return is handled by the catch methods below.

irc_RPL_NAMREPLY(prefix, params)[source]

“Handles IRC NAME request returns (nicklist)

irc_RPL_ENDOFNAMES(prefix, params)[source]

Called when the nicklist has finished being returned.

pong(user, time)[source]

Called with the return timing from a PING.

Parameters
  • user (str) – Name of user

  • time (float) – Ping time in secs.

data_in(text=None, **kwargs)[source]

Data IRC -> Server.

Keyword Arguments
  • text (str) – Ingoing text.

  • kwargs (any) – Other data from protocol.

send_channel(*args, **kwargs)[source]

Send channel text to IRC channel (visible to all). Note that we don’t handle the “text” send (it’s rerouted to send_default which does nothing) - this is because the IRC bot is a normal session and would otherwise report anything that happens to it to the IRC channel (such as it seeing server reload messages).

Parameters

text (str) – Outgoing text

send_privmsg(*args, **kwargs)[source]

Send message only to specific user.

Parameters

text (str) – Outgoing text.

Keyword Arguments

user (str) – the nick to send privately to.

send_request_nicklist(*args, **kwargs)[source]

Send a request for the channel nicklist. The return (handled by self.irc_RPL_ENDOFNAMES) will be sent back as a message with type **nicklist’.

send_ping(*args, **kwargs)[source]

Send a ping. The return (handled by self.pong) will be sent back as a message of type ‘ping’.

send_reconnect(*args, **kwargs)[source]

The server instructs us to rebuild the connection by force, probably because the client silently lost connection.

send_default(*args, **kwargs)[source]

Ignore other types of sends.

class evennia.server.portal.irc.IRCBotFactory(sessionhandler, uid=None, botname=None, channel=None, network=None, port=None, ssl=None)[source]

Bases: twisted.internet.protocol.ReconnectingClientFactory

Creates instances of IRCBot, connecting with a staggered increase in delay

initialDelay = 1
factor = 1.5
maxDelay = 60
__init__(sessionhandler, uid=None, botname=None, channel=None, network=None, port=None, ssl=None)[source]

Storing some important protocol properties.

Parameters

sessionhandler (SessionHandler) – Reference to the main Sessionhandler.

Keyword Arguments
  • uid (int) – Bot user id.

  • botname (str) – Bot name (seen in IRC channel).

  • channel (str) – IRC channel to connect to.

  • network (str) – Network address to connect to.

  • port (str) – Port of the network.

  • ssl (bool) – Indicates SSL connection.

buildProtocol(addr)[source]

Build the protocol and assign it some properties.

Parameters

addr (str) – Not used; using factory data.

startedConnecting(connector)[source]

Tracks reconnections for debugging.

Parameters

connector (Connector) – Represents the connection.

clientConnectionFailed(connector, reason)[source]

Called when Client failed to connect.

Parameters
  • connector (Connection) – Represents the connection.

  • reason (str) – The reason for the failure.

clientConnectionLost(connector, reason)[source]

Called when Client loses connection.

Parameters
  • connector (Connection) – Represents the connection.

  • reason (str) – The reason for the failure.

reconnect()[source]

Force a reconnection of the bot protocol. This requires de-registering the session and then reattaching a new one, otherwise you end up with an ever growing number of bot sessions.

start()[source]

Connect session to sessionhandler.