This file holds objects and methods related to sending messages out of the socket to the IRC server.
This object and its methods serves as the bot's point of contact for sending things out of the socket and for utilizing various IRC-specific functionality.
class irc.socketConnection()
-
socketConnection.readFromSocket(self)
Attempts to return data received from the socket. asocket.timeout
exception is caught, a message of the socket timing out will be logged to the bot's error log under log levellogging.ERROR
, andrunState
will be set toFalse
to trigger socket termination. -
socketConnection.buildMessageQueue(self)
Creates a message queue and adds messages received from thesocketConnection.readFromSocket()
method to the queue. If an existing queue is found, the messages will be added to that queue instead. This method will check if the last message in the queue was an incomplete message. If this is the case, the first line will be appended to this incomplete message queue instead of being separately added to the queue. This checking ensures that even if all the socket data is not delivered in a single call ofsocketConnection.readFromSocket()
, all messages will be completed by the time they are parsed by the bot. If no incomplete line is found, lines received from the socket will be individually added to the queue. -
socketConnection.readQueue(self)
Safely assembles an array of items currently in the queue of received messages without popping any of the messages off the queue. -
socketConnection.connect(self, host, port, nick, ident, userMode[, serverPass])
Attempts to establish and IRC connection by issuingPASS
,NICK
, andUSER
commands to the server after the socket is connected. -
socketConnection.socketShutdown(self)
Safely issues a socket shutdown and close by passingsocket.SHUT_WR
and an argument to the socket'sshutdown()
method, as well as invoking the socket'sclose()
method. -
socketConnection.pong(self, host)
Issues aPONG
to host. -
socketConnection.joinChannels(self, channels)
If channels is an array (typelist
), it will individually issueJOIN
commands for each item in the array. Otherwise (typestr
), it will issue just a singleJOIN
command. -
socketConnection.partChannels(self, channel[, message])
Issues aPART
command for channel, including a part message string, if supplied in message. -
socketConnection.sendToChannel(self, channel, message)
Sends message to the specified channel with aPRIVMSG
command. -
socketConnection.quit(self[, message)
Disconnects from an IRC server with aQUIT
command, including a quit string, if supplied in message. -
socketConnection.kick(self, user, channel[, message])
Kicks user from channel with aKICK
command, including a kick reason string, if supplied in message. -
socketConnection.topic(self, channel, topic)
Sets the topic in channel to the string provided in topic with aTOPIC
command. -
socketConnection.userMode(self, user, mode)
Applies the specified modes in mode to user by issuing aMODE
command. -
socketConnection.channelMode(self, channel, modes[, extraArgs])
Applies the specified modes in mode to the channel specified in channel, with extraArgs appended to the command for data such as the user mask when setting a+/- b
mode. -
socketConnection.invite(self, nick, channel)
Invites the specified nick in nick to a particular channel given in channel with theINVITE
command. -
socketConnection.time(self[, server])
Issues aTIME
command to the server the bot is connected to, or a specific server if given in server. -
socketConnection.nick(self, nick)
Issues aNICK
command to set the bot's nickname to the nickname supplied in nick. -
socketConnection.nsIdentify(self, nick[, password])
Attempts to identify the bot's nickname with NickServ by issuing aNS IDENTIFY
command with the supplied nick and password. -
socketConnection.action(self, channel, action)
Issues aPRIVMSG
to the channel given in channel with the action string wrapped in\u0001ACTION
and\u0001
to form a CTCP ACTION command. -
socketConnection.notice(self, nick, message)
Issues aNOTICE
command to nick with the message string supplied in message.
This object is created by the irc.socketConnection
object to serve as its only point of exit for messages going outbound to the socket. Through this architecture, there is no risk of collisions of methods sending data out of the socket at the same time.
At spawn time, this object will create a queue.Queue()
queuing object, then creating a thread with a target set to it's flushQueue()
method. This thread is called "socket_queueWorker"
.
class irc.socketQueue()
-
socketQueue.addToQueue(self, message)
Puts message onto the object's socket queue. -
socketQueue.flushQueue(self)
Enters a loop, terminated if it's parentirc.socketConnection.runState
boolean is set toFalse
, at which point it will attempt to send all messages in it's socket queue out of the socket with thesend()
method of the socket. Messages sent out of the socket are first explicitly encoded withutf-8
encoding. Items sent out of the socket are logged to the bot's socket log. If the socket loop terminates, this method will automatically shut down the socket connection by way of theirc.socketConnection.socketShutdown()
method.