IRCCore — IRC protocol client

A simple and generic class for interacting with the IRC protocol.

class pyircbot.irccore.IRCCore(servers, loop, rate_limit=True, rate_max=5.0, rate_int=1.1)[source]

Bases: object

act_ACTION(channel, action, priority=2)[source]

Use the /me <action> command

Parameters:
  • channel (str) – the channel name or target’s name the message is sent to
  • action (str) – the text to send
act_JOIN(channel, priority=3)[source]

Use the /join command

Parameters:channel (str) – the channel to attempt to join
act_KICK(channel, who, comment='', priority=2)[source]

Use the /kick <user> <message> command

Parameters:
  • channel (str) – the channel from which the user will be kicked
  • who – the nickname of the user to kick
  • comment (str) – the kick message
act_MODE(channel, mode, extra=None, priority=2)[source]

Use the /mode command

Parameters:
  • channel (str) – the channel this mode is for
  • mode (str) – the mode string. Example: +b
  • extra (str) – additional argument if the mode needs it. Example: user@*!*
act_NICK(newNick, priority=2)[source]

Use the /nick command

Parameters:newNick (str) – new nick for the bot
act_PASS(password, priority=1)[source]

Send server password, for use on connection

act_PONG(data, priority=1)[source]

Use the /pong command - respond to server pings

Parameters:data (str) – the string or number the server sent with it’s ping
act_PRIVMSG(towho, message, priority=3)[source]

Use the /msg command

Parameters:
  • towho (str) – the target #channel or user’s name
  • message (str) – the message to send
act_QUIT(message, priority=2)[source]

Use the /quit command

Parameters:message (str) – quit message
act_USER(username, hostname, realname, priority=2)[source]

Use the USER protocol command. Used during connection

Parameters:
  • username (str) – the bot’s username
  • hostname (str) – the bot’s hostname
  • realname (str) – the bot’s realname
addHook(command, method)[source]

Internal. Enable (connect) a single hook of a module

Parameters:
  • command (str) – command this hook will trigger on
  • method (object) – callable method object to hook in
alive = None

True if we should try to stay connected

bind_addr = None

Optionally bind to a specific address. This should be a (host, port) tuple.

buffer = None

cStringIO used as a buffer

connected = None

If we’re connected or not

connection_family = None

Socket family. 0 will auto-detect ipv4 or v6. Change this to socket.AF_INET or socket.AF_INET6 force use of ipv4 or ipv6.

static decodePrefix(prefix)[source]

Given a prefix like nick!username@hostname, return an object with these properties

Parameters:prefix (str) – the prefix to disassemble
Returns:object – an UserPrefix object with the properties nick, username, hostname or a ServerPrefix

object with the property hostname

fire_hook(command, args=None, prefix=None, trailing=None)[source]

Run any listeners for a specific hook

Parameters:
  • command (str) – the hook to fire
  • args (list) – the list of arguments, if any, the command was passed
  • prefix (str) – prefix of the sender of this command
  • trailing (str) – data payload of the command
static fulltrace()[source]

Return the stack trace of the bot as a string

get_nick()[source]

Get the bot’s current nick

Returns:str - the bot’s current nickname
initHooks()[source]

Defines hooks that modules can listen for events of

kill(message='Help! Another thread is killing me :(', forever=True)[source]

Send quit message, flush queue, and close the socket

Parameters:message (str) – Quit message to send before disconnecting
log = None

Reference to logger object

loop(loop)[source]
outputqueue()[source]
packetAsObject(command, args, prefix, trailing)[source]

Given an irc message’s args, prefix, and trailing data return an object with these properties

Parameters:
  • args (list) – list of args from the IRC packet
  • prefix (ServerPrefix or UserPrefix) – prefix object parsed from the IRC packet
  • trailing (str) – trailing data from the IRC packet
Returns:

object – a IRCEvent object with the args, prefix, trailing

port = None

Server port

removeHook(command, method)[source]

Internal. Disable (disconnect) a single hook of a module

Parameters:
  • command (str) – command this hook triggers on
  • method (object) – callable method that should be removed
sendRaw(data, priority=None)[source]

Send data on the wire. Lower priorities are sent first. :param data: unicode data to send. will be converted to utf-8 :param priority: numerical priority value. If not None, the message will likely be sent first. Otherwise, an

ever-increasing sequence number is used to maintain order. For a minimum priority message, use a priority value of sys.maxsize.
server = None

Current server index

servers = None

List of server address

static trace()[source]

Return the stack trace of the bot as a string

class pyircbot.irccore.IRCEvent(command, args, prefix, trailing)

Bases: tuple

args

Alias for field number 1

command

Alias for field number 0

prefix

Alias for field number 2

trailing

Alias for field number 3

class pyircbot.irccore.ServerPrefix(hostname)

Bases: tuple

hostname

Alias for field number 0

class pyircbot.irccore.UserPrefix(nick, username, hostname)

Bases: tuple

hostname

Alias for field number 2

nick

Alias for field number 0

username

Alias for field number 1