Jump to content

C++ IRC Class v 1.1 - IRC bots made easy


`Rοmeο

Recommended Posts

C++ IRC Library 1.1

 

Hey guys, sorry about the screw up on the last version, but this one should be all fixed! (thanks to Montage's help)

 

This version uses the C++ string class instead of C-style char arrays, so its more up to date.

 

Info

 

What this library does is make it a lot easier to connect to an IRC server in C++, just include the header files and the IRC class takes care of all the protocol and socket programming, and lets you take care of the bot itself.

 

Here's an example of a simple IRC bot skeleton using this library:

 

 

/*  Example of IRC class usage
    Coded by delme
*/

#include "irc.cpp"

int main() {
    //set options here
    string IRCServer = "irc.swiftirc.net";
    int IRCPort = 6667;
    string Nick = "BotNick";
    string Channel = "#bot-test";

    string sBuffer;
    int i;

    IRC irc;
    if (irc.Connect(IRCServer,IRCPort) != IRC_CONNECT_SUCESS) {
        return 0;
    }
    irc.Register(Nick);
    irc.Join(Channel);

    while(1) {
        sBuffer = irc.RecvData();
        if (irc.GetLastError()!=IRC_RECIEVE_ERROR) {
            i = irc.ParseData(sBuffer);
            if (i==IRC_PRIVMSG) {
                //privmsg
                if (irc.s_privmsg.Message=="!quit") {
                    irc.Notice("Quitting...",irc.s_privmsg.User);
                    break;
                }
            }
        } else {
            break;
        }
    }
    irc.Quit();
    return 0;
}

 

All it does is idle in a channel until it receives the command, "!quit", and then it will send you a notice and close, quitting from the IRC server.

 

Credits: FearOfTheDark  :good sir:

Link to comment
Share on other sites

  • 2 months later...
Guest
This topic is now closed to further replies.


×
×
  • Create New...