Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <SFML/Network.hpp>
- #include <SFML/System/Utf.hpp>
- #include <stdlib.h>
- #include <iostream>
- #include <string>
- sf::TcpSocket socket;
- sf::Socket::Status status;
- std::string nickname = "tutasbot";
- std::string oauth = "oauth:XXXXXXXXXXXXXX"; //you won't be stealing it now :P
- std::string channel = "coolkidscode";
- bool isRunning = true;
- void sendMessage(std::string message)
- {
- std::string totalMSG = ":" + nickname+"!"+nickname+"@"+nickname+".tmi.twitch.tv PRIVMSG #"+channel+" :" + message + "\r\n";
- socket.send(totalMSG.c_str(),totalMSG.size()+1);
- }
- void doMessage(std::string message,std::string username)
- {
- std::cout<<"I hav message! \a"<<std::endl;
- if(message.find("!help") == 0)
- {
- sendMessage("BOT TUTAS IS HERE TO HELP! <3 <3 <3");
- }else if(message.find("!quit") == 0 && username.find("tutasmaster") != -1)
- {
- std::cout<<"BOT SHUTTING OFF"<<std::endl;
- isRunning = false;
- }else if(message.find("ACTION flips a table!") == 1)
- {
- sendMessage(username + " please stop flipping tables. This is not a crisis.");
- }
- }
- void messageFunc(std::string buffer){
- std::string buf(buffer);
- if (buf.find("PRIVMSG") != -1) {
- //std::cout<<buf<<std::endl;
- int point = 0;
- int userpoint = buf.find("!");
- int messagepoint = buf.find(":",2);
- std::string username;
- if(userpoint != -1){
- username = buf;
- username.erase(userpoint, buf.size() - userpoint);
- username.erase(0,1);
- std::cout<<username;
- if(messagepoint != -1)
- {
- std::string strmessage = buf.erase(0,messagepoint+1);
- std::cout<<":"<<strmessage<<std::endl;
- doMessage(strmessage,username);
- }
- //std::cout<<userpoint<<std::endl;
- //std::cout<<messagepoint<<std::endl;
- }
- }else{
- std::cout<<buffer<<"\a"<<std::endl;
- }
- }
- int main()
- {
- status = socket.connect("irc.twitch.tv", 6667);
- if (status == sf::Socket::Done)
- {
- // error...
- std::cout<<"The socket is working."<<std::endl;
- }
- std::string nick = "NICK "+nickname+"\r\n";
- std::string pass = "PASS "+oauth+"\r\n";
- std::string chan = "JOIN #"+channel+"\r\n";
- std::string pong = "PONG :tmi.twitch.tv\r\n";
- std::string capreq = "CAP REQ :twitch.tv/commands\r\n";
- socket.send(pass.c_str(), pass.size() + 1);
- socket.send(nick.c_str(), nick.size() + 1);
- socket.send(chan.c_str(), chan.size() + 1);
- socket.send(capreq.c_str(),capreq.size() + 1);
- sendMessage("The bot is on!");
- while(isRunning)
- {
- char buffer[500];
- std::size_t received = 0;
- socket.receive(buffer, sizeof(buffer), received);
- if(buffer == "PING :tmi.twitch.tv"){
- socket.send(pong.c_str(),pong.size() + 1);
- std::cout<<"I HAVE BEEN PINGED!"<<std::endl;
- }else{
- messageFunc(buffer);
- }
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement