Communi  3.4.0
A cross-platform IRC framework written with Qt
Public Types | Public Member Functions | Static Public Member Functions | Properties | List of all members
IrcCommand Class Reference

Provides the most common commands. More...

Inherits QObject.

Public Types

enum  Type {
  Admin, Away, Capability, CtcpAction,
  CtcpReply, CtcpRequest, Custom, Info,
  Invite, Join, Kick, Knock,
  List, Message, Mode, Motd,
  Names, Nick, Notice, Part ,
  Quit, Quote, Stats, Time,
  Topic, Trace, Users, Version,
  Who, Whois, Whowas
}
 

Public Member Functions

 IrcCommand (QObject *parent=0)
 
virtual ~IrcCommand ()
 
Q_INVOKABLE IrcMessagetoMessage (const QString &prefix, IrcConnection *connection) const
 
virtual QString toString () const
 

Static Public Member Functions

static Q_INVOKABLE IrcCommandcreateAdmin (const QString &server=QString())
 
static Q_INVOKABLE IrcCommandcreateAway (const QString &reason=QString())
 
static Q_INVOKABLE IrcCommandcreateCapability (const QString &subCommand, const QString &capability)
 
static Q_INVOKABLE IrcCommandcreateCapability (const QString &subCommand, const QStringList &capabilities=QStringList())
 
static Q_INVOKABLE IrcCommandcreateCtcpAction (const QString &target, const QString &action)
 
static Q_INVOKABLE IrcCommandcreateCtcpReply (const QString &target, const QString &reply)
 
static Q_INVOKABLE IrcCommandcreateCtcpRequest (const QString &target, const QString &request)
 
static Q_INVOKABLE IrcCommandcreateInfo (const QString &server=QString())
 
static Q_INVOKABLE IrcCommandcreateInvite (const QString &user, const QString &channel)
 
static Q_INVOKABLE IrcCommandcreateJoin (const QString &channel, const QString &key=QString())
 
static Q_INVOKABLE IrcCommandcreateJoin (const QStringList &channels, const QStringList &keys=QStringList())
 
static Q_INVOKABLE IrcCommandcreateKick (const QString &channel, const QString &user, const QString &reason=QString())
 
static Q_INVOKABLE IrcCommandcreateKnock (const QString &channel, const QString &message=QString())
 
static Q_INVOKABLE IrcCommandcreateList (const QStringList &channels=QStringList(), const QString &server=QString())
 
static Q_INVOKABLE IrcCommandcreateMessage (const QString &target, const QString &message)
 
static Q_INVOKABLE IrcCommandcreateMode (const QString &target, const QString &mode=QString(), const QString &arg=QString())
 
static Q_INVOKABLE IrcCommandcreateMonitor (const QString &command, const QString &target=QString())
 
static Q_INVOKABLE IrcCommandcreateMonitor (const QString &command, const QStringList &targets)
 
static Q_INVOKABLE IrcCommandcreateMotd (const QString &server=QString())
 
static Q_INVOKABLE IrcCommandcreateNames (const QString &channel=QString(), const QString &server=QString())
 
static Q_INVOKABLE IrcCommandcreateNames (const QStringList &channels, const QString &server=QString())
 
static Q_INVOKABLE IrcCommandcreateNick (const QString &nick)
 
static Q_INVOKABLE IrcCommandcreateNotice (const QString &target, const QString &notice)
 
static Q_INVOKABLE IrcCommandcreatePart (const QString &channel, const QString &reason=QString())
 
static Q_INVOKABLE IrcCommandcreatePart (const QStringList &channels, const QString &reason=QString())
 
static Q_INVOKABLE IrcCommandcreatePing (const QString &argument)
 
static Q_INVOKABLE IrcCommandcreatePong (const QString &argument)
 
static Q_INVOKABLE IrcCommandcreateQuit (const QString &reason=QString())
 
static Q_INVOKABLE IrcCommandcreateQuote (const QString &raw)
 
static Q_INVOKABLE IrcCommandcreateQuote (const QStringList &parameters)
 
static Q_INVOKABLE IrcCommandcreateStats (const QString &query, const QString &server=QString())
 
static Q_INVOKABLE IrcCommandcreateTime (const QString &server=QString())
 
static Q_INVOKABLE IrcCommandcreateTopic (const QString &channel, const QString &topic=QString())
 
static Q_INVOKABLE IrcCommandcreateTrace (const QString &target=QString())
 
static Q_INVOKABLE IrcCommandcreateUsers (const QString &server=QString())
 
static Q_INVOKABLE IrcCommandcreateVersion (const QString &user=QString())
 
static Q_INVOKABLE IrcCommandcreateWho (const QString &mask, bool operators=false)
 
static Q_INVOKABLE IrcCommandcreateWhois (const QString &user)
 
static Q_INVOKABLE IrcCommandcreateWhowas (const QString &user, int count=1)
 

Properties

IrcConnection connection
 
QByteArray encoding
 
QStringList parameters
 
Type type
 

Detailed Description

The IrcCommand class supports the most common IRC commands out of the box, and can be extended for custom commands as well. See IrcCommand::Type for the list of built-in command types. IRC commands, as in IrcCommand instances, are sent to the IRC server via IrcConnection::sendCommand().

Creating commands

It is recommended to create IrcCommand instances via static IrcCommand::createXxx() methods.

Warning
IrcCommand instances must be allocated on the heap, since IrcConnection::sendCommand() takes ownership of the command and deletes it once it has been sent.

Custom commands

A "custom command" here refers to command types not listed in IrcCommand::Type, the list of built-in command types. There are two ways to send custom commands:

Example implementation of a custom command:

class IrcServerCommand : public IrcCommand
{
Q_OBJECT
public:
explicit IrcServerCommand(QObject* parent = 0) : IrcCommand(parent)
{
}
// provided for convenience, to ensure correct parameter order
static IrcCommand* create(const QString& serverName, int hopCount, const QString& info)
{
IrcCommand* command = new IrcServerCommand;
command->setParameters(QStringList() << serverName << QString::number(hopCount) << info);
return command;
}
// reimplemented from IrcCommand::toString()
virtual toString() const
{
// SERVER <servername> <hopcount> <info>
return QString("SERVER %1 %2 %3").arg(params.value(0), params.value(1), params.value(2));
}
};
See also
IrcConnection::sendCommand(), IrcConnection::sendRaw(), IrcCommand::Type

Member Enumeration Documentation

This enum describes the built-in command types.

Enumerator
Admin 

An admin command (ADMIN) is used to query server admin info.

Away 

An away command (AWAY) is used to set the away status.

Capability 

A capability command (CAP) is used to manage connection capabilities.

CtcpAction 

A CTCP action command is used to send an action message to channels and users.

CtcpReply 

A CTCP reply command is used to send a reply to a request.

CtcpRequest 

A CTCP request command is used to send a request.

Custom 

A custom command.

Info 

An info command (INFO) is used to query server info.

Invite 

An invite command (INVITE) is used to invite users to a channel.

Join 

A join command (JOIN) is used to start listening a specific channel.

Kick 

A kick command (KICK) is used to forcibly remove a user from a channel.

Knock 

A knock command (KNOCK) is used to request channel invitation.

List 

A list command (LIST) is used to list channels and their topics.

Message 

A message command (PRIVMSG) is used to send private messages to channels and users.

Mode 

A mode command (MODE) is used to change the mode of users and channels.

Motd 

A message of the day command (MOTD) is used to query the message of the day.

Names 

A names command (NAMES) is used to list all nicknames on a channel.

Nick 

A nick command (NICK) is used to give user a nickname or change the previous one.

Notice 

A notice command (NOTICE) is used to send notice messages to channels and users.

Part 

A part command (PART) causes the client to be removed from the channel.

Quit 

A quit command (QUIT) is used to end a client connection.

Quote 

A quote command is used to send a raw message to the server.

Stats 

A stats command (STATS) is used to query server statistics.

Time 

A time command (TIME) is used to query local server time.

Topic 

A topic command (TOPIC) is used to change or view the topic of a channel.

Trace 

A trace command (TRACE) is used to trace the connection path to a target.

Users 

A users command (USERS) is used to query server users.

Version 

A version command (VERSION) is used to query user or server version.

Who 

A who command (WHO) is used to generate a query which returns a list of matching users.

Whois 

A whois command (WHOIS) is used to query information about a particular user.

Whowas 

A whowas command (WHOWAS) is used to query information about a user that no longer exists.

Constructor & Destructor Documentation

IrcCommand::IrcCommand ( QObject parent = 0)
explicit

Constructs a new IrcCommand with parent.

IrcCommand::~IrcCommand ( )
virtual

Destructs the IRC command.

Member Function Documentation

IrcCommand * IrcCommand::createAdmin ( const QString server = QString())
static

Creates a new ADMIN command with type IrcCommand::Admin and optional parameter server.

This command shows admin info for the specified server, or the current server if not specified.

IrcCommand * IrcCommand::createAway ( const QString reason = QString())
static

Creates a new AWAY command with type IrcCommand::Away and optional parameter reason.

Provides the server with reason to automatically send in reply to a private message directed at the user. If reason is omitted, the away status is removed.

IrcCommand * IrcCommand::createCapability ( const QString subCommand,
const QString capability 
)
static

Creates a new capability command with type IrcCommand::Capability and parameters subCommand and a capability.

Available subcommands are: LS, LIST, REQ, ACK, NAK, CLEAR and END.

See also
IRCv3 support
IrcCommand * IrcCommand::createCapability ( const QString subCommand,
const QStringList capabilities = QStringList() 
)
static

Creates a new capability command with type IrcCommand::Capability and parameters subCommand and optional capabilities.

Available subcommands are: LS, LIST, REQ, ACK, NAK, CLEAR and END.

See also
IRCv3 support
IrcCommand * IrcCommand::createCtcpAction ( const QString target,
const QString action 
)
static

Creates a new CTCP action command with type IrcCommand::CtcpAction and parameters target and action.

IrcCommand * IrcCommand::createCtcpReply ( const QString target,
const QString reply 
)
static

Creates a new CTCP reply command with type IrcCommand::CtcpReply and parameters target and reply.

IrcCommand * IrcCommand::createCtcpRequest ( const QString target,
const QString request 
)
static

Creates a new CTCP request command with type IrcCommand::CtcpRequest and parameters target and request.

IrcCommand * IrcCommand::createInfo ( const QString server = QString())
static

Creates a new INFO command with type IrcCommand::Info and optional parameter server.

This command shows info for the specified server, or the current server if not specified.

IrcCommand * IrcCommand::createInvite ( const QString user,
const QString channel 
)
static

Creates a new INVITE command with type IrcCommand::Invite and parameters user and channel.

This command invites user to the channel. The channel does not have to exist, but if it does, only members of the channel are allowed to invite other clients. if the channel mode +i (invite-only) is set, only channel operators may invite other clients.

IrcCommand * IrcCommand::createJoin ( const QString channel,
const QString key = QString() 
)
static

Creates a new JOIN command with type IrcCommand::Join and parameters channel and optional key.

This command joins the channel using key if specified. If the channel does not exist, it will be created.

IrcCommand * IrcCommand::createJoin ( const QStringList channels,
const QStringList keys = QStringList() 
)
static

This overload is provided for convenience.

IrcCommand * IrcCommand::createKick ( const QString channel,
const QString user,
const QString reason = QString() 
)
static

Creates a new KICK command with type IrcCommand::Kick and parameters channel, user and optional reason.

This command forcibly removes user from channel, and may only be issued by channel operators.

IrcCommand * IrcCommand::createKnock ( const QString channel,
const QString message = QString() 
)
static

Creates a new KNOCK command with type IrcCommand::Knock and parameters channel and optional message.

This command sends an invitation request to a channel with an optional message.

Note
The command is not formally defined by an RFC, but is supported by most major IRC daemons. Support is indicated in a RPL_ISUPPORT reply (numeric 005) with the KNOCK keyword.
IrcCommand * IrcCommand::createList ( const QStringList channels = QStringList(),
const QString server = QString() 
)
static

Creates a new LIST command with type IrcCommand::List and optional parameters channels and server.

This command lists all channels on the server. If channels are given, it will list the channel topics. If server is given, the command will be forwarded to server for evaluation.

IrcCommand * IrcCommand::createMessage ( const QString target,
const QString message 
)
static

Creates a new PRIVMSG command with type IrcCommand::Message and parameters target and message.

This command sends message to target, which is usually a user or channel.

IrcCommand * IrcCommand::createMode ( const QString target,
const QString mode = QString(),
const QString arg = QString() 
)
static

Creates a new MODE command with type IrcCommand::Mode and parameters target and optional mode and arg.

This command is used to set both user and channel modes.

IrcCommand * IrcCommand::createMonitor ( const QString command,
const QString target = QString() 
)
static
Since
3.4

Creates a new MONITOR command with type IrcCommand::Monitor and parameters command and and optional target.

Available commands are:

  • + - Adds the given list of targets to the list of targets being monitored.
  • + - Removes the given list of targets from the list of targets being monitored. No output will be returned for use of this command.
  • C - Clears the list of targets being monitored. No output will be returned for use of this command.
  • L - Outputs the current list of targets being monitored. All output will use RPL_MONLIST, and the output will be terminated with RPL_ENDOFMONLIST.
  • S - Outputs for each target in the list being monitored, whether the client is online or offline. All targets that are online will be sent using RPL_MONONLINE, all targets that are offline will be sent using RPL_MONOFFLINE.
See also
IRCv3 support
IrcCommand * IrcCommand::createMonitor ( const QString command,
const QStringList targets 
)
static
Since
3.4

Creates a new MONITOR command with type IrcCommand::Monitor and parameters command and targets.

Available commands are:

  • + - Adds the given list of targets to the list of targets being monitored.
  • + - Removes the given list of targets from the list of targets being monitored. No output will be returned for use of this command.
  • C - Clears the list of targets being monitored. No output will be returned for use of this command.
  • L - Outputs the current list of targets being monitored. All output will use RPL_MONLIST, and the output will be terminated with RPL_ENDOFMONLIST.
  • S - Outputs for each target in the list being monitored, whether the client is online or offline. All targets that are online will be sent using RPL_MONONLINE, all targets that are offline will be sent using RPL_MONOFFLINE.
See also
IRCv3 support
IrcCommand * IrcCommand::createMotd ( const QString server = QString())
static

Creates a new MOTD command with type IrcCommand::Motd and optional parameter server.

This command shows the message of the day on the specified server, or the current server if not specified.

IrcCommand * IrcCommand::createNames ( const QString channel = QString(),
const QString server = QString() 
)
static

Creates a new NAMES command with type IrcCommand::Names and parameter channel.

This command lists all users on the channel, optionally limiting to the given server.

If channel is omitted, all users are shown, grouped by channel name with all users who are not on a channel being shown as part of channel "*". If server is specified, the command is sent to server for evaluation.

IrcCommand * IrcCommand::createNames ( const QStringList channels,
const QString server = QString() 
)
static

This overload is provided for convenience.

IrcCommand * IrcCommand::createNick ( const QString nick)
static

Creates a new NICK command with type IrcCommand::Nick and parameter nick.

This command allows a client to change their IRC nickname.

IrcCommand * IrcCommand::createNotice ( const QString target,
const QString message 
)
static

Creates a new NOTICE command with type IrcCommand::Notice and parameters target and message.

This command sends notice to target, which is usually a user or channel.

Note
The command works similarly to PRIVMSG, except automatic replies must never be sent in reply to NOTICE messages.
IrcCommand * IrcCommand::createPart ( const QString channel,
const QString reason = QString() 
)
static

Creates a new PART command with type IrcCommand::Part and parameters channel and optional reason.

This command causes the client to leave the specified channel.

IrcCommand * IrcCommand::createPart ( const QStringList channels,
const QString reason = QString() 
)
static

This overload is provided for convenience.

IrcCommand * IrcCommand::createPing ( const QString argument)
static

Creates a new PING command with type IrcCommand::Ping and argument.

IrcCommand * IrcCommand::createPong ( const QString argument)
static

Creates a new PONG command with type IrcCommand::Pong and argument.

IrcCommand * IrcCommand::createQuit ( const QString reason = QString())
static

Creates a new QUIT command with type IrcCommand::Quit and optional parameter reason.

IrcCommand * IrcCommand::createQuote ( const QString raw)
static

Creates a new QUOTE command with type IrcCommand::Quote and raw.

IrcCommand * IrcCommand::createQuote ( const QStringList parameters)
static

Creates a new QUOTE command with type IrcCommand::Quote and parameters.

IrcCommand * IrcCommand::createStats ( const QString query,
const QString server = QString() 
)
static

Creates a new STATS command with type IrcCommand::Stats and parameters query and optional server.

This command queries statistics about the specified server, or the current server if not specified.

IrcCommand * IrcCommand::createTime ( const QString server = QString())
static

Creates a new TIME command with type IrcCommand::Time and optional parameter server.

This command queries local time of the specified server, or the current server if not specified.

IrcCommand * IrcCommand::createTopic ( const QString channel,
const QString topic = QString() 
)
static

Creates a new TOPIC command with type IrcCommand::Topic and parameters channel and optional topic.

This command allows the client to query or set the channel topic on channel. If topic is given, it sets the channel topic to topic. If channel mode +t is set, only a channel operator may set the topic.

IrcCommand * IrcCommand::createTrace ( const QString target = QString())
static

Creates a new TRACE command with type IrcCommand::Trace and optional parameter target.

This command traces the connection path across the IRC network to the current server or to a specific target (server or client) in a similar method to traceroute.

IrcCommand * IrcCommand::createUsers ( const QString server = QString())
static

Creates a new USERS command with type IrcCommand::Users and optional parameter server.

This command queries the users of the specified server, or the current server if not specified.

IrcCommand * IrcCommand::createVersion ( const QString user = QString())
static

Creates a new command with type IrcCommand::Version and optional parameter user.

This command queries the version of the specified user's client (CTCP REQUEST VERSION), or the current server (VERSION) if not specified.

IrcCommand * IrcCommand::createWho ( const QString mask,
bool  operators = false 
)
static

Creates a new WHO command with type IrcCommand::Who and parameters mask and optional operators.

This command returns a list of users who match mask, optionally matching only IRC operators.

IrcCommand * IrcCommand::createWhois ( const QString user)
static

Creates a new WHOIS command with type IrcCommand::Whois and parameter user.

This command returns information about user.

IrcCommand * IrcCommand::createWhowas ( const QString user,
int  count = 1 
)
static

Creates a new WHOWAS command with type IrcCommand::Whowas and parameters user and optional count.

This command returns information about a user that is no longer online (due to client disconnection, or nickname changes). If given, the server will return information from the last count times the nickname has been used.

IrcMessage * IrcCommand::toMessage ( const QString prefix,
IrcConnection connection 
) const

Creates a new message from this command for prefix and connection.

Notice that IRC servers do not echo sent message commands back to the client. This function is particularly useful for converting sent message commands as messages for presentation purposes.

if (command->type() == IrcCommand::Message) {
IrcMessage* message = command->toMessage(connection->nickName(), connection);
receiveMessage(message);
message->deleteLater();
}
QString IrcCommand::toString ( ) const
virtual

Returns the command as a string.

Reimplement for custom commands.

See also
IrcCommand::Custom

Property Documentation

IrcConnection * IrcCommand::connection
read
Since
3.3

This property holds the connection that this command was sent to.

The connection is only set if the command has been passed to IrcConnection::sendCommand(). It is mostly usable to know the associated connection in IrcCommandFilter::commandFilter().

Access function:
QByteArray IrcCommand::encoding
readwrite

This property holds the encoding that is used when sending the command via IrcConnection::sendCommand().

See QTextCodec::availableCodes() for the list of supported encodings. The default value is "UTF-8".

Access functions:
See also
QTextCodec::availableCodecs()
QStringList IrcCommand::parameters
readwrite

This property holds the command parameters.

Access functions:
IrcCommand::Type IrcCommand::type
readwrite

This property holds the command type.

Access functions: