PandoraBotIRC  1.0.0
An irc bot that acts as a Pandora chatter bot
pbirc::irc::IRCConnection Class Reference

IRCConnection class represents a connection to an irc server. More...

#include <IRCConnection.hpp>

Public Member Functions

 IRCConnection ()=default
 Default constructor. More...
 
 ~IRCConnection ()=default
 Default destructor. More...
 
 IRCConnection (IRCConnection const &)=delete
 Copy constructor is deleted. More...
 
IRCConnectionoperator= (IRCConnection const &)
 Copy assignment is disabled. More...
 
bool connect (std::string const &server, std::uint16_t const &port)
 Starts up a connection with an irc server. More...
 
void disconnect ()
 Disconnects from an irc server. More...
 
IRCMessage receive ()
 Receives data from the server and tries to format it into an IRCMessage. More...
 
bool send (IRCMessage const &msg)
 Sends an IRCMessage to the server. More...
 
 operator bool ()
 Operator bool This function returns m_status. More...
 
std::string getServerName () const
 
std::uint16_t getPort () const
 
template<typename Func , typename Obj >
void addCallback (std::string const &cmd, Func function, Obj object)
 Adds a callback function that is a member function of another object. More...
 
template<typename Func >
void addCallback (std::string const &cmd, Func function)
 Adds a callback function that is not a member function of another object. More...
 
void work ()
 This is the main worker function when using callback functionality. More...
 

Detailed Description

IRCConnection class represents a connection to an irc server.

This class can register callback functions to call when a certain command is received.
Call IRCConnection::work on every event loop of the program.
IRCConnection will receive incoming messages, process them, and call corresponding callback functions.

callback functions return type void, and have one parameter of type IRCMessage const &.

This funcitonality is entirely optional. You can use IRCConnection without using it's callback feature.

There are two built in special callback keys that aren't IRC commands.
1.) "ALL" – Callbacks registered with this key are executed for every command.
2.) "DEFAULT" – Callbacks registered with this key are executed if no other callbacks exist for the command.

Example

Possible output for the above code:

 

Constructor & Destructor Documentation

pbirc::irc::IRCConnection::IRCConnection ( )
default

Default constructor.

pbirc::irc::IRCConnection::~IRCConnection ( )
default

Default destructor.

pbirc::irc::IRCConnection::IRCConnection ( IRCConnection const &  )
delete

Copy constructor is deleted.

Member Function Documentation

template<typename Func , typename Obj >
void pbirc::irc::IRCConnection::addCallback ( std::string const &  cmd,
Func  function,
Obj  object 
)
inline

Adds a callback function that is a member function of another object.

Parameters
[in]cmdThe command the callback function is connected to
[in]functionthe callback function
[in]objectA pointer to the object the function belongs to
template<typename Func >
void pbirc::irc::IRCConnection::addCallback ( std::string const &  cmd,
Func  function 
)
inline

Adds a callback function that is not a member function of another object.

Parameters
[in]cmdThe command the callback function is connected to
[in]functionthe callback function
bool pbirc::irc::IRCConnection::connect ( std::string const &  server,
std::uint16_t const &  port 
)

Starts up a connection with an irc server.

Parameters
[in]serverdomain name or IP address of the irc server
[in]portthe port on the server to connect to
void pbirc::irc::IRCConnection::disconnect ( )

Disconnects from an irc server.

std::uint16_t pbirc::irc::IRCConnection::getPort ( ) const
inline
std::string pbirc::irc::IRCConnection::getServerName ( ) const
inline
Returns
name of the server that the object is connected to
pbirc::irc::IRCConnection::operator bool ( )
inline

Operator bool This function returns m_status.

Evaluates to true if all is good and we are connected to the server Evaluates to false if we are disconnected or an error has occured

IRCConnection& pbirc::irc::IRCConnection::operator= ( IRCConnection const &  )

Copy assignment is disabled.

IRCMessage pbirc::irc::IRCConnection::receive ( )

Receives data from the server and tries to format it into an IRCMessage.

Stores excess data in m_data for later access. Will set m_status to false and disconnect upon error.

Returns
IRCMessage received from the server
bool pbirc::irc::IRCConnection::send ( IRCMessage const &  msg)

Sends an IRCMessage to the server.

Will set m_status to false and disconnect upon error.

Parameters
[in]msgIRCMessage object to be sent
Returns
true if everything worked and all is well false if otherwise
void pbirc::irc::IRCConnection::work ( )

This is the main worker function when using callback functionality.

This function tries to receive a message from the server, format it into an IRCMessage object then call the corresponding callbacks for the message.

If no corresponding callback is found for the message, work will try use a callback registered with the "DEFAULT" command. If no callback is found, the message is dropped.

When using callbacks, 'work' should be called on every event loop of the program.


The documentation for this class was generated from the following files: