onilink_

Irc bot translator

Dec 16th, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <onidev/network.h>
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5.  
  6. std::string translate(std::string str)
  7. {
  8.     while(str.find(' ') != -1)
  9.         str.replace(str.find(' '), 1, "%20");
  10.    
  11.     std::string json = od::Http::download("http://translate.google.com/translate_a/t?client=p&text="+str+"&sl=fr&tl=en&sc=1&ssel=0&tsel=0");
  12.     std::cout << json << std::endl;
  13.    
  14.     int p = json.find("\"trans\"");
  15.     p += 9;
  16.     return json.substr(p, json.find('\"', p) - p);
  17. }
  18.  
  19. int main()
  20. {
  21.     using namespace od;
  22.     using namespace std;
  23.    
  24.     string server = "irc.mibbit.net", chan = "#CBNA", username = "trans";
  25.     //std::cin >> username;
  26.    
  27.     Irc irc(server, 6667, true);
  28.     irc.connect();
  29.     irc.nick(username);
  30.     irc.user(username, "host", server, server);
  31.     irc.join(chan, "");
  32.    
  33.     while(true)
  34.     {
  35.         irc.getMessage();
  36.        
  37.         if(irc.messageType() == Irc::Message || irc.messageType() == Irc::PrivateMessage)
  38.         {
  39.             string msg = irc.messageString();
  40.             irc.privmsg(chan, translate(msg.substr(0, msg.length()-1))+"\n");
  41.         }
  42.         else if(irc.messageType() == Irc::Kick)
  43.         {
  44.             cout << "You have been kicked by " << irc.messageUsername() << endl;
  45.             irc.join(chan, "");
  46.         }
  47.     }
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment