Internet Relay Chat protocol for client and server.

Future Plans

The way the IRCClient class works here encourages people to implement IRC clients by subclassing the ephemeral protocol class, and it tends to end up with way more state than it should for an object which will be destroyed as soon as the TCP transport drops. Someone oughta do something about that, ya know?

The DCC support needs to have more hooks for the client for it to be able to ask the user things like "Do you want to accept this session?" and "Transfer #2 is 67% done." and otherwise manage the DCC sessions.

Test coverage needs to be better.

AuthorKevin Turner
See AlsoRFC 1459: Internet Relay Chat Protocol
RFC 2812: Internet Relay Chat: Client Protocol
The Client-To-Client-Protocol
Variable MAX_COMMAND_LENGTH The maximum length of a command, as defined by RFC 2812 section 2.3.
Variable attributes Singleton instance of _CharacterAttributes, used for constructing formatted text information.
Class IRCBadMessage Undocumented
Class IRCPasswordMismatch Undocumented
Class IRCBadModes A malformed mode was encountered while attempting to parse a mode string.
Function parsemsg Breaks a message from an IRC server into its prefix, command, and arguments.
Function split Split a string into multiple lines.
Class UnhandledCommand A command dispatcher could not locate an appropriate command handler.
Function parseModes Parse an IRC mode string.
Class IRC Internet Relay Chat server protocol.
Class ServerSupportedFeatures Handle ISUPPORT messages.
Class IRCClient Internet Relay Chat client protocol, with sprinkles.
Function dccParseAddress Undocumented
Class DccFileReceiveBasic Bare protocol to receive a Direct Client Connection SEND stream.
Class DccSendProtocol Protocol for an outgoing Direct Client Connection SEND.
Class DccSendFactory Undocumented
Function fileSize I'll try my damndest to determine the size of this file object.
Class DccChat Direct Client Connection protocol type CHAT.
Class DccChatFactory Undocumented
Function dccDescribe Given the data chunk from a DCC query, return a descriptive string.
Class DccFileReceive Higher-level coverage for getting a file from DCC SEND.
Function parseFormattedText Parse text containing IRC formatting codes into structured information.
Function assembleFormattedText Assemble formatted text from structured information.
Function stripFormatting Remove all formatting codes from text, leaving only the text.
Function ctcpExtract Extract CTCP data from a string.
Function lowQuote Undocumented
Function lowDequote Undocumented
Function ctcpQuote Undocumented
Function ctcpDequote Undocumented
Function ctcpStringify
Function _intOrDefault Convert a value to an integer if possible.
Class _CommandDispatcherMixin Dispatch commands to handlers based on their name.
Class _CharacterAttributes Factory for character attributes, including foreground and background color and non-color attributes such as bold, reverse video and underline.
Class _FormattingState Formatting state/attributes of a single character.
Function _foldr Apply a function of two arguments cumulatively to the items of a sequence, from right to left, so as to reduce the sequence to a single value.
Class _FormattingParser A finite-state machine that parses formatted IRC text.
MAX_COMMAND_LENGTH =
The maximum length of a command, as defined by RFC 2812 section 2.3.
attributes =
Singleton instance of _CharacterAttributes, used for constructing formatted text information.
def parsemsg(s): (source)

Breaks a message from an IRC server into its prefix, command, and arguments.

ParameterssThe message to break. (type: bytes)
ReturnsA tuple of (prefix, command, args). (type: tuple)
def split(str, length=80): (source)

Split a string into multiple lines.

Whitespace near str[length] will be preferred as a breaking point. "\n" will also be used as a breaking point.

ParametersstrThe string to split. (type: str)
lengthThe maximum length which will be allowed for any string in the result. (type: int)
Returnslist of str
def _intOrDefault(value, default=None): (source)

Convert a value to an integer if possible.

ReturnsAn integer when value can be converted to an integer, otherwise return default (type: int or type of default)
def parseModes(modes, params, paramModes=('', '')): (source)

Parse an IRC mode string.

The mode string is parsed into two lists of mode changes (added and removed), with each mode change represented as (mode, param) where mode is the mode character, and param is the parameter passed for that mode, or None if no parameter is required.

ParametersmodesModes string to parse. (type: str)
paramsParameters specified along with modes. (type: list)
paramModesA pair of strings ((add, remove)) that indicate which modes take parameters when added or removed. (type: (str, str))
ReturnsTwo lists of mode changes, one for modes added and the other for modes removed respectively, mode changes in each list are represented as (mode, param).
def dccParseAddress(address): (source)
Undocumented
def fileSize(file): (source)

I'll try my damndest to determine the size of this file object.

ParametersfileThe file object to determine the size of. (type: file)
ReturnsThe size of the file object as an integer if it can be determined, otherwise return None. (type: int or None)
def dccDescribe(data): (source)

Given the data chunk from a DCC query, return a descriptive string.

ParametersdataThe data from a DCC query. (type: bytes)
ReturnsA descriptive string. (type: bytes)
def _foldr(f, z, xs): (source)

Apply a function of two arguments cumulatively to the items of a sequence, from right to left, so as to reduce the sequence to a single value.

ParameterszInitial value.
xsSequence to reduce.
ReturnsSingle value resulting from reducing xs.
def parseFormattedText(text): (source)

Parse text containing IRC formatting codes into structured information.

Color codes are mapped from 0 to 15 and wrap around if greater than 15.

ParameterstextFormatted text to parse. (type: str)
ReturnsStructured text and attributes.
Present Since13.1
def assembleFormattedText(formatted): (source)

Assemble formatted text from structured information.

Currently handled formatting includes: bold, reverse, underline, mIRC color codes and the ability to remove all current formatting.

It is worth noting that assembled text will always begin with the control code to disable other attributes for the sake of correctness.

For example:

   from twisted.words.protocols.irc import attributes as A
   assembleFormattedText(
       A.normal[A.bold['Time: '], A.fg.lightRed['Now!']])

Would produce "Time: " in bold formatting, followed by "Now!" with a foreground color of light red and without any additional formatting.

Available attributes are:

  • bold
  • reverseVideo
  • underline

Available colors are:

  1. white
  2. black
  3. blue
  4. green
  5. light red
  6. red
  7. magenta
  8. orange
  9. yellow
  10. light green
  11. cyan
  12. light cyan
  13. light blue
  14. light magenta
  15. gray
  16. light gray
ParametersformattedStructured text and attributes.
ReturnsString containing mIRC control sequences that mimic those specified by formatted. (type: str)
See Alsohttp://www.mirc.co.uk/help/color.txt
Present Since13.1
def stripFormatting(text): (source)

Remove all formatting codes from text, leaving only the text.

ParameterstextFormatted text to parse. (type: str)
ReturnsPlain text without any control sequences. (type: str)
Present Since13.1
def ctcpExtract(message): (source)

Extract CTCP data from a string.

ReturnsA dict containing two keys:
  • 'extended': A list of CTCP (tag, data) tuples.
  • 'normal': A list of strings which were not inside a CTCP delimiter.
def lowQuote(s): (source)
Undocumented
def lowDequote(s): (source)
Undocumented
def ctcpQuote(s): (source)
Undocumented
def ctcpDequote(s): (source)
Undocumented
def ctcpStringify(messages): (source)
ReturnsString
API Documentation for Twisted, generated by pydoctor at 2017-06-11 10:59:01.