Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //compiling with g++ -std=c++11 main.cpp bot.cpp -o bot -lsfml-system -lsfml-network
- // main.cpp
- #include <iostream>
- #include "bot.hpp"
- int main(int argc, char *argv[])
- {
- irc Bot;
- std::cout<<"Connecting..."<< std::endl;
- if(Bot.connect())
- std::cout<<"Connected."<< std::endl;
- Bot.ircregister();
- }
- //bot.hpp
- #ifndef _ROOT_BOT_HPP
- #define _ROOT_BOT_HPP
- #include <string>
- #include <vector>
- #include <initializer_list>
- #include <SFML/Network.hpp>
- class InternetRelayChat
- {
- public:
- InternetRelayChat();
- InternetRelayChat setServer (std::string);
- InternetRelayChat setChannels(std::initializer_list<std::string>);
- InternetRelayChat setNick (std::string);
- InternetRelayChat setIdent (std::string);
- InternetRelayChat setRealname(std::string);#include "bot.hpp"
- #include <SFML/Network.hpp>
- #include <cstdarg>
- irc::InternetRelayChat() { this->Socket.setBlocking(false); }
- irc irc::setServer (std::string server) { this->Server = server; }
- irc irc::setChannels(std::initializer_list<std::string> ChannelList) { this->Channels = ChannelList; }
- irc irc::setNick (std::string nick) { this->Nick = nick; }
- irc irc::setIdent (std::string ident) { this->Ident = ident; }
- irc irc::setRealname(std::string realname) { this->Realname = realname; }
- irc irc::setPort ( int port) { this->Port = port; }
- std::string irc::getServer () { return this->Server; }
- std::vector<std::string> irc::getChannels() { return this->Channels; }
- std::string irc::getNick () { return this->Nick; }
- std::string irc::getIdent () { return this->Ident; }
- std::string irc::getRealname() { return this->Realname; }
- int irc::getPort () { return this->Port; }
- std::string irc::getBuffer () { return this->Buffer; }
- std::size_t irc::getBytes () { return this->BytesRecieved; }
- bool irc::connect()
- {
- this->Status = this->Socket.connect(this->Server, this->Port);
- return (this->Status != sf::Socket::Done) ? false : true;
- }
- void irc::ircregister()
- {
- this->send("NICK %s", this->Nick.c_str());
- this->send("USER %s %s bla :%s", this->Ident.c_str(), this->Server.c_str(), this->Realname.c_str());
- }
- void irc::receive()
- {
- char *buffer;
- this->Socket.receive(buffer, 1024, this->BytesRecieved);
- this->Buffer = (std::string)buffer;
- }
- void irc::send(std::string Format, ...)
- {
- va_list Arguments;
- std::string Command;
- va_start(Arguments, Format);
- for(char Iterator : Format)
- {
- if(Iterator != '%')
- {
- Command = Command + Iterator;
- continue;
- }
- Iterator++;
- Command += (std::string)va_arg(Arguments, char*);
- }
- va_end(Arguments);
- this->Socket.send(Command.c_str(), 100);
- }
- void irc::sendMsg(std::string Message, ...)
- {
- }
- void irc::pong()
- {
- }
- InternetRelayChat setPort (int);
- std::string getServer ();
- std::vector<std::string> getChannels();
- std::string getNick ();
- std::string getIdent ();
- std::string getRealname();
- int getPort ();
- std::string getBuffer ();
- std::size_t getBytes ();
- bool connect ();
- void ircregister();
- void receive ();
- void send (std::string, ...);
- void sendMsg (std::string, ...);
- void pong ();
- void join ();
- private:
- std:: string Server = "irc.quakenet.org";
- std:: vector<std::string> Channels {"#BotDevGroundZero"};
- std:: string Nick = "DTSBot-v0.0.4";
- std:: string Ident = "DTSBot";
- std:: string Realname = "DTSBot";
- int Port = 6667;
- std:: string Buffer = "";
- sf:: TcpSocket Socket;
- sf::Socket::Status Status;
- std:: size_t BytesRecieved;
- };
- typedef InternetRelayChat irc;
- #endif
- //bot.cpp
- #include "bot.hpp"
- #include <SFML/Network.hpp>
- #include <cstdarg>
- irc::InternetRelayChat() { this->Socket.setBlocking(false); }
- irc irc::setServer (std::string server) { this->Server = server; }#include "bot.hpp"
- #include <SFML/Network.hpp>
- #include <cstdarg>
- irc::InternetRelayChat() { this->Socket.setBlocking(false); }
- irc irc::setServer (std::string server) { this->Server = server; }
- irc irc::setChannels(std::initializer_list<std::string> ChannelList) { this->Channels = ChannelList; }
- irc irc::setNick (std::string nick) { this->Nick = nick; }
- irc irc::setIdent (std::string ident) { this->Ident = ident; }
- irc irc::setRealname(std::string realname) { this->Realname = realname; }
- irc irc::setPort ( int port) { this->Port = port; }
- std::string irc::getServer () { return this->Server; }
- std::vector<std::string> irc::getChannels() { return this->Channels; }
- std::string irc::getNick () { return this->Nick; }
- std::string irc::getIdent () { return this->Ident; }
- std::string irc::getRealname() { return this->Realname; }
- int irc::getPort () { return this->Port; }
- std::string irc::getBuffer () { return this->Buffer; }
- std::size_t irc::getBytes () { return this->BytesRecieved; }
- bool irc::connect()
- {
- this->Status = this->Socket.connect(this->Server, this->Port);
- return (this->Status != sf::Socket::Done) ? false : true;
- }
- void irc::ircregister()
- {
- this->send("NICK %s", this->Nick.c_str());
- this->send("USER %s %s bla :%s", this->Ident.c_str(), this->Server.c_str(), this->Realname.c_str());
- }
- void irc::receive()
- {
- char *buffer;
- this->Socket.receive(buffer, 1024, this->BytesRecieved);
- this->Buffer = (std::string)buffer;
- }
- void irc::send(std::string Format, ...)
- {
- va_list Arguments;
- std::string Command;
- va_start(Arguments, Format);
- for(char Iterator : Format)
- {
- if(Iterator != '%')
- {
- Command = Command + Iterator;
- continue;
- }
- Iterator++;
- Command += (std::string)va_arg(Arguments, char*);
- }
- va_end(Arguments);
- this->Socket.send(Command.c_str(), 100);
- }
- void irc::sendMsg(std::string Message, ...)
- {
- }
- void irc::pong()
- {
- }
- irc irc::setChannels(std::initializer_list<std::string> ChannelList) { this->Channels = ChannelList; }
- irc irc::setNick (std::string nick) { this->Nick = nick; }
- irc irc::setIdent (std::string ident) { this->Ident = ident; }
- irc irc::setRealname(std::string realname) { this->Realname = realname; }
- irc irc::setPort ( int port) { this->Port = port; }
- std::string irc::getServer () { return this->Server; }
- std::vector<std::string> irc::getChannels() { return this->Channels; }
- std::string irc::getNick () { return this->Nick; }
- std::string irc::getIdent () { return this->Ident; }
- std::string irc::getRealname() { return this->Realname; }
- int irc::getPort () { return this->Port; }
- std::string irc::getBuffer () { return this->Buffer; }
- std::size_t irc::getBytes () { return this->BytesRecieved; }
- bool irc::connect()
- {
- this->Status = this->Socket.connect(this->Server, this->Port);
- return (this->Status != sf::Socket::Done) ? false : true;
- }
- void irc::ircregister()
- {
- this->send("NICK %s", this->Nick.c_str());
- this->send("USER %s %s bla :%s", this->Ident.c_str(), this->Server.c_str(), this->Realname.c_str());
- }
- void irc::receive()
- {
- char *buffer;
- this->Socket.receive(buffer, 1024, this->BytesRecieved);
- this->Buffer = (std::string)buffer;
- }
- void irc::send(std::string Format, ...)
- {
- va_list Arguments;
- std::string Command;
- va_start(Arguments, Format);
- for(char Iterator : Format)
- {
- if(Iterator != '%')
- {
- Command = Command + Iterator;
- continue;
- }
- Iterator++;
- Command += (std::string)va_arg(Arguments, char*);
- }
- va_end(Arguments);
- this->Socket.send(Command.c_str(), 100);
- }
- void irc::sendMsg(std::string Message, ...)
- {
- }
- void irc::pong()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement