Class t.w.p.i.IRCClient(basic.LineReceiver):

Part of twisted.words.protocols.irc View Source View In Hierarchy

Known subclasses: twisted.words.im.ircsupport.IRCProto

Internet Relay Chat client protocol, with sprinkles.

In addition to providing an interface for an IRC client protocol, this class also contains reasonable implementations of many common CTCP methods.

TODO

Instance VariablesnicknameNickname the client will use.
passwordPassword used to log on to the server. May be None.
realnameSupplied to the server during login as the "Real name" or "ircname". May be None.
usernameSupplied to the server during login as the "User name". May be None
userinfoSent in reply to a USERINFO CTCP query. If None, no USERINFO reply will be sent. "This is used to transmit a string which is settable by the user (and never should be set by the client)."
fingerReplySent in reply to a FINGER CTCP query. If None, no FINGER reply will be sent. (type: Callable or String )
versionNameCTCP VERSION reply, client name. If None, no VERSION reply will be sent.
versionNumCTCP VERSION reply, client version,
versionEnvCTCP VERSION reply, environment the client is running in.
sourceURLCTCP SOURCE reply, a URL where the source code of this client may be found. If None, no SOURCE reply will be sent.
lineRateMinimum delay between lines sent to the server. If None, no delay will be imposed. (type: Number of Seconds. )
Line # Kind Name Docs
567 Method _reallySendLine Undocumented
570 Method sendLine Sends a line to the other end of the connection.
578 Method _sendLine Undocumented
593 Method created Called with creation date information about the server, usually at logon.
600 Method yourHost Called with daemon information about the server, usually at logon.
607 Method myInfo Called with information about the server, usually at logon.
623 Method luserClient Called with information about the number of connections, usually at logon.
631 Method bounce Called with information about where the client should reconnect.
639 Method isupport Called with various information about what the server supports.
647 Method luserChannels Called with the number of channels existant on the server.
653 Method luserOp Called with the number of ops logged on to the server.
659 Method luserMe Called with information about the server connected to.
669 Method privmsg Called when I have a message from a user to me or a channel.
674 Method joined Called when I finish joining a channel.
681 Method left Called when I have left a channel.
688 Method noticed Called when I have a notice from a user to me or a channel.
703 Method modeChanged Called when a channel's modes are changed
724 Method pong Called with the results of a CTCP PING query.
729 Method signedOn Called after sucessfully signing on to the server.
734 Method kickedFrom Called when I am kicked from a channel.
739 Method nickChanged Called when my nick has been changed.
747 Method userJoined Called when I see another user joining a channel.
752 Method userLeft Called when I see another user leaving a channel.
757 Method userQuit Called when I see another user disconnect from the network.
762 Method userKicked Called when I observe someone else being kicked from a channel.
767 Method action Called when I see a user perform an ACTION on a channel.
772 Method topicUpdated In channel, user changed the topic to newTopic.
779 Method userRenamed A user changed their name from oldname to newname.
786 Method receivedMOTD I received a message-of-the-day banner from the server.
801 Method join Undocumented
808 Method leave Undocumented
815 Method kick Undocumented
824 Method topic Attempt to set the topic of the given channel, or ask what it is.
838 Method mode Change the modes on a user or channel.
853 Method say Undocumented
857 Method msg Send a message to a user or channel.
892 Method notice Undocumented
895 Method away Undocumented
898 Method register Undocumented
906 Method setNick Undocumented
910 Method quit Undocumented
915 Method me Strike a pose.
924 Method ping Measure round-trip delay to another IRC client.
946 Method dccSend Undocumented
972 Method dccResume Send a DCC RESUME request to another user.
977 Method dccAcceptResume Send a DCC ACCEPT response to clients who have requested a resume.
987 Method irc_ERR_NICKNAMEINUSE Undocumented
990 Method irc_ERR_PASSWDMISMATCH Undocumented
993 Method irc_RPL_WELCOME Undocumented
996 Method irc_JOIN Undocumented
1004 Method irc_PART Undocumented
1012 Method irc_QUIT Undocumented
1016 Method irc_MODE Undocumented
1023 Method irc_PING Undocumented
1026 Method irc_PRIVMSG Undocumented
1045 Method irc_NOTICE Undocumented
1062 Method irc_NICK Undocumented
1069 Method irc_KICK Kicked? Who? Not me, I hope.
1082 Method irc_TOPIC Someone in the channel set the topic.
1090 Method irc_RPL_TOPIC I just joined the channel, and the server is telling me the current topic.
1098 Method irc_RPL_NOTOPIC Undocumented
1104 Method irc_RPL_MOTDSTART Undocumented
1109 Method irc_RPL_MOTD Undocumented
1114 Method irc_RPL_ENDOFMOTD Undocumented
1117 Method irc_RPL_CREATED Undocumented
1120 Method irc_RPL_YOURHOST Undocumented
1123 Method irc_RPL_MYINFO Undocumented
1129 Method irc_RPL_BOUNCE Undocumented
1136 Method irc_RPL_LUSERCLIENT Undocumented
1139 Method irc_RPL_LUSEROP Undocumented
1145 Method irc_RPL_LUSERCHANNELS Undocumented
1151 Method irc_RPL_LUSERME Undocumented
1154 Method irc_unknown Undocumented
1160 Method ctcpQuery Dispatch method for any CTCP queries received.
1170 Method ctcpQuery_ACTION Undocumented
1173 Method ctcpQuery_PING Undocumented
1177 Method ctcpQuery_FINGER Undocumented
1192 Method ctcpQuery_VERSION Undocumented
1204 Method ctcpQuery_SOURCE Undocumented
1217 Method ctcpQuery_USERINFO Undocumented
1225 Method ctcpQuery_CLIENTINFO A master index of what CTCP tags this client knows.
1256 Method ctcpQuery_ERRMSG Undocumented
1263 Method ctcpQuery_TIME Undocumented
1272 Method ctcpQuery_DCC Initiate a Direct Client Connection
1292 Method dcc_SEND Undocumented
1316 Method dcc_ACCEPT Undocumented
1329 Method dcc_RESUME Undocumented
1341 Method dcc_CHAT Undocumented
1359 Method dccDoSend Called when I receive a DCC SEND offer from a client.
1370 Method dccDoResume Called when a client is trying to resume an offered file
1376 Method dccDoAcceptResume Called when a client has verified and accepted a DCC resume
1381 Method dccDoChat Undocumented
1394 Method ctcpUnknownQuery Undocumented
1403 Method ctcpMakeReply Send one or more extended messages as a CTCP reply.
1413 Method ctcpMakeQuery Send one or more extended messages as a CTCP query.
1424 Method ctcpReply Dispatch method for any CTCP replies received.
1434 Method ctcpReply_PING Undocumented
1443 Method ctcpUnknownReply Called when a fitting ctcpReply_ method is not found.
1456 Method badMessage When I get a message that's so broken I can't use it.
1464 Method quirkyMessage This is called when I receive a message which is peculiar,
1472 Method connectionMade Called when a connection is made.
1477 Method dataReceived Called whenever data is received.
1480 Method lineReceived Override this for when each line is received.
1491 Method handleCommand Determine the function to call for the given command and call
1505 Method __getstate__ Undocumented

Inherited from LineReceiver:

Line # Kind Name Docs
208 Method clearLineBuffer Clear buffered data.
242 Method setLineMode Sets the line-mode of this receiver.
257 Method setRawMode Sets the raw mode of this receiver.
264 Method rawDataReceived Override this for when raw data is received.
279 Method lineLengthExceeded Called when the maximum line length has been reached.

Inherited from Protocol (via LineReceiver):

Line # Kind Name Docs
368 Method connectionLost Called when the connection is shut down.

Inherited from BaseProtocol (via LineReceiver, Protocol):

Line # Kind Name Docs
325 Method makeConnection Make a connection to a transport and a server.

Inherited from _PauseableMixin (via LineReceiver):

Line # Kind Name Docs
173 Method pauseProducing Undocumented
177 Method resumeProducing Undocumented
182 Method stopProducing Undocumented
def _reallySendLine(self, line):
Undocumented
def sendLine(self, line):
Sends a line to the other end of the connection.
def _sendLine(self):
Undocumented
def created(self, when):
Called with creation date information about the server, usually at logon.
ParameterswhenA string describing when the server was created, probably. (type: str )
def yourHost(self, info):
Called with daemon information about the server, usually at logon.
Parametersinfo(type: str )
whenA string describing what software the server is running, probably.
def myInfo(self, servername, version, umodes, cmodes):
Called with information about the server, usually at logon.
ParametersservernameThe hostname of this server. (type: str )
versionA description of what software this server runs. (type: str )
umodesAll the available user modes. (type: str )
cmodesAll the available channel modes. (type: str )
def luserClient(self, info):
Called with information about the number of connections, usually at logon.
ParametersinfoA description of the number of clients and servers connected to the network, probably. (type: str )
def bounce(self, info):
Called with information about where the client should reconnect.
ParametersinfoA plaintext description of the address that should be connected to. (type: str )
def isupport(self, options):
Called with various information about what the server supports.
ParametersoptionsDescriptions of features or limits of the server, possibly in the form "NAME=VALUE". (type: list of str )
def luserChannels(self, channels):
Called with the number of channels existant on the server.
Parameterschannels(type: int )
def luserOp(self, ops):
Called with the number of ops logged on to the server.
Parametersops(type: int )
def luserMe(self, info):
Called with information about the server connected to.
ParametersinfoA plaintext string describing the number of users and servers connected to this server. (type: str )
def privmsg(self, user, channel, message):
Called when I have a message from a user to me or a channel.
def joined(self, channel):

Called when I finish joining a channel.

channel has the starting character (# or &) intact.
def left(self, channel):

Called when I have left a channel.

channel has the starting character (# or &) intact.
def noticed(self, user, channel, message):

Called when I have a notice from a user to me or a channel.

By default, this is equivalent to IRCClient.privmsg, but if your client makes any automated replies, you must override this! From the RFC:
   The difference between NOTICE and PRIVMSG is that
   automatic replies MUST NEVER be sent in response to a
   NOTICE message. [...] The object of this rule is to avoid
   loops between clients automatically sending something in
   response to something it received.
def modeChanged(self, user, channel, set, modes, args):
Called when a channel's modes are changed
ParametersuserThe user and hostmask which instigated this change. (type: str )
channelThe channel for which the modes are changing. (type: str )
settrue if the mode is being added, false if it is being removed. (type: bool or int )
modesThe mode or modes which are being changed. (type: str )
argsAny additional information required for the mode change. (type: tuple )
def pong(self, user, secs):
Called with the results of a CTCP PING query.
def signedOn(self):
Called after sucessfully signing on to the server.
def kickedFrom(self, channel, kicker, message):
Called when I am kicked from a channel.
def nickChanged(self, nick):
Called when my nick has been changed.
def userJoined(self, user, channel):
Called when I see another user joining a channel.
def userLeft(self, user, channel):
Called when I see another user leaving a channel.
def userQuit(self, user, quitMessage):
Called when I see another user disconnect from the network.
def userKicked(self, kickee, channel, kicker, message):
Called when I observe someone else being kicked from a channel.
def action(self, user, channel, data):
Called when I see a user perform an ACTION on a channel.
def topicUpdated(self, user, channel, newTopic):

In channel, user changed the topic to newTopic.

Also called when first joining a channel.
def userRenamed(self, oldname, newname):
A user changed their name from oldname to newname.
def receivedMOTD(self, motd):

I received a message-of-the-day banner from the server.

motd is a list of strings, where each string was sent as a seperate message from the server. To display, you might want to use:
   string.join(motd, '\n')
to get a nicely formatted string.
def join(self, channel, key=None):
Undocumented
def leave(self, channel, reason=None):
Undocumented
def kick(self, channel, user, reason=None):
Undocumented
def topic(self, channel, topic=None):

Attempt to set the topic of the given channel, or ask what it is.

If topic is None, then I sent a topic query instead of trying to set the topic. The server should respond with a TOPIC message containing the current topic of the given channel.
def mode(self, chan, set, modes, limit=None, user=None, mask=None):
Change the modes on a user or channel.
def say(self, channel, message, length=None):
Undocumented
def msg(self, user, message, length=None):
Send a message to a user or channel.
ParametersuserThe username or channel name to which to direct the message. (type: str )
messageThe text to send (type: str )
lengthThe maximum number of octets to send at a time. This has the effect of turning a single call to msg() into multiple commands to the server. This is useful when long messages may be sent that would otherwise cause the server to kick us off or silently truncate the text we are sending. If None is passed, the entire message is always send in one command. (type: int )
def notice(self, user, message):
Undocumented
def away(self, message=''):
Undocumented
def register(self, nickname, hostname='foo', servername='bar'):
Undocumented
def setNick(self, nickname):
Undocumented
def quit(self, message=''):
Undocumented
def me(self, channel, action):
Strike a pose.
def ping(self, user, text=None):
Measure round-trip delay to another IRC client.
def dccSend(self, user, file):
Undocumented
def dccResume(self, user, fileName, port, resumePos):
Send a DCC RESUME request to another user.
def dccAcceptResume(self, user, fileName, port, resumePos):
Send a DCC ACCEPT response to clients who have requested a resume.
def irc_ERR_NICKNAMEINUSE(self, prefix, params):
Undocumented
def irc_ERR_PASSWDMISMATCH(self, prefix, params):
Undocumented
def irc_RPL_WELCOME(self, prefix, params):
Undocumented
def irc_JOIN(self, prefix, params):
Undocumented
def irc_PART(self, prefix, params):
Undocumented
def irc_QUIT(self, prefix, params):
Undocumented
def irc_MODE(self, prefix, params):
Undocumented
def irc_PING(self, prefix, params):
Undocumented
def irc_PRIVMSG(self, prefix, params):
Undocumented
def irc_NOTICE(self, prefix, params):
Undocumented
def irc_NICK(self, prefix, params):
Undocumented
def irc_KICK(self, prefix, params):
Kicked? Who? Not me, I hope.
def irc_TOPIC(self, prefix, params):
Someone in the channel set the topic.
def irc_RPL_TOPIC(self, prefix, params):
I just joined the channel, and the server is telling me the current topic.
def irc_RPL_NOTOPIC(self, prefix, params):
Undocumented
def irc_RPL_MOTDSTART(self, prefix, params):
Undocumented
def irc_RPL_MOTD(self, prefix, params):
Undocumented
def irc_RPL_ENDOFMOTD(self, prefix, params):
Undocumented
def irc_RPL_CREATED(self, prefix, params):
Undocumented
def irc_RPL_YOURHOST(self, prefix, params):
Undocumented
def irc_RPL_MYINFO(self, prefix, params):
Undocumented
def irc_RPL_BOUNCE(self, prefix, params):
Undocumented
def irc_RPL_LUSERCLIENT(self, prefix, params):
Undocumented
def irc_RPL_LUSEROP(self, prefix, params):
Undocumented
def irc_RPL_LUSERCHANNELS(self, prefix, params):
Undocumented
def irc_RPL_LUSERME(self, prefix, params):
Undocumented
def irc_unknown(self, prefix, command, params):
Undocumented
def ctcpQuery(self, user, channel, messages):
Dispatch method for any CTCP queries received.
def ctcpQuery_ACTION(self, user, channel, data):
Undocumented
def ctcpQuery_PING(self, user, channel, data):
Undocumented
def ctcpQuery_FINGER(self, user, channel, data):
Undocumented
def ctcpQuery_VERSION(self, user, channel, data):
Undocumented
def ctcpQuery_SOURCE(self, user, channel, data):
Undocumented
def ctcpQuery_USERINFO(self, user, channel, data):
Undocumented
def ctcpQuery_CLIENTINFO(self, user, channel, data):

A master index of what CTCP tags this client knows.

If no arguments are provided, respond with a list of known tags. If an argument is provided, provide human-readable help on the usage of that tag.
def ctcpQuery_ERRMSG(self, user, channel, data):
Undocumented
def ctcpQuery_TIME(self, user, channel, data):
Undocumented
def ctcpQuery_DCC(self, user, channel, data):
Initiate a Direct Client Connection
def dcc_SEND(self, user, channel, data):
Undocumented
def dcc_ACCEPT(self, user, channel, data):
Undocumented
def dcc_RESUME(self, user, channel, data):
Undocumented
def dcc_CHAT(self, user, channel, data):
Undocumented
def dccDoSend(self, user, address, port, fileName, size, data):

Called when I receive a DCC SEND offer from a client.

By default, I do nothing here.
def dccDoResume(self, user, file, port, resumePos):
Called when a client is trying to resume an offered file via DCC send. It should be either replied to with a DCC ACCEPT or ignored (default).
def dccDoAcceptResume(self, user, file, port, resumePos):
Called when a client has verified and accepted a DCC resume request made by us. By default it will do nothing.
def dccDoChat(self, user, channel, address, port, data):
Undocumented
def ctcpUnknownQuery(self, user, channel, tag, data):
Undocumented
def ctcpMakeReply(self, user, messages):
Send one or more extended messages as a CTCP reply.
Parametersmessages(type: a list of extended messages. An extended message is a (tag, data) tuple, where 'data' may be None. )
def ctcpMakeQuery(self, user, messages):
Send one or more extended messages as a CTCP query.
Parametersmessages(type: a list of extended messages. An extended message is a (tag, data) tuple, where 'data' may be None. )
def ctcpReply(self, user, channel, messages):
Dispatch method for any CTCP replies received.
def ctcpReply_PING(self, user, channel, data):
Undocumented
def ctcpUnknownReply(self, user, channel, tag, data):

Called when a fitting ctcpReply_ method is not found.

XXX: If the client makes arbitrary CTCP queries, this method should probably show the responses to them instead of treating them as anomolies.
def badMessage(self, line, excType, excValue, tb):
When I get a message that's so broken I can't use it.
def quirkyMessage(self, s):
This is called when I receive a message which is peculiar, but not wholly indecipherable.
def connectionMade(self):

Called when a connection is made.

This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.
def dataReceived(self, data):

Called whenever data is received.

Use this method to translate to a higher-level message. Usually, some callback will be made upon the receipt of each complete protocol message.
Parametersdataa string of indeterminate length. Please keep in mind that you will probably need to buffer some data, as partial (or multiple) protocol messages may be received! I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.
def lineReceived(self, line):
Override this for when each line is received.
def handleCommand(self, command, prefix, params):
Determine the function to call for the given command and call it with the given arguments.
def __getstate__(self):
Undocumented