PandoraBotIRC
1.0.0
An irc bot that acts as a Pandora chatter bot
|
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... | |
IRCConnection & | operator= (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... | |
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.
Possible output for the above code:
|
default |
Default constructor.
|
default |
Default destructor.
|
delete |
Copy constructor is deleted.
|
inline |
Adds a callback function that is a member function of another object.
[in] | cmd | The command the callback function is connected to |
[in] | function | the callback function |
[in] | object | A pointer to the object the function belongs to |
|
inline |
Adds a callback function that is not a member function of another object.
[in] | cmd | The command the callback function is connected to |
[in] | function | the callback function |
bool pbirc::irc::IRCConnection::connect | ( | std::string const & | server, |
std::uint16_t const & | port | ||
) |
Starts up a connection with an irc server.
[in] | server | domain name or IP address of the irc server |
[in] | port | the port on the server to connect to |
void pbirc::irc::IRCConnection::disconnect | ( | ) |
Disconnects from an irc server.
|
inline |
|
inline |
|
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.
bool pbirc::irc::IRCConnection::send | ( | IRCMessage const & | msg | ) |
Sends an IRCMessage to the server.
Will set m_status to false and disconnect upon error.
[in] | msg | IRCMessage object to be sent |
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.