onilink_

Irc Bot MILLE!

Dec 16th, 2014
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. #include <onidev/network.h>
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5. bool mille(const std::string & msg)
  6. {
  7.     char str[6] = "mile";
  8.     char str2[6] = "MILE";
  9.     int cursor = 0;
  10.    
  11.     for(size_t i=0; i<msg.length(); ++i)
  12.     {
  13.         char c = msg[i];
  14.         if(cursor == 0)
  15.         {
  16.             if(c == 'm' || c == 'M') cursor++;
  17.         }
  18.         else
  19.         {
  20.             if(c == str[cursor] || c == str2[cursor]) cursor++;
  21.             else if(c == ' ' || c == '_' || c == str[cursor-1] || c == str2[cursor-1]);
  22.             else cursor = 0;
  23.         }
  24.        
  25.         if(cursor == 4)
  26.             return true;
  27.     }
  28.    
  29.    
  30.     return false;
  31. }
  32.  
  33. int main()
  34. {
  35.     using namespace od;
  36.     using namespace std;
  37.    
  38.    
  39.     string server = "irc.mibbit.net", chan = "#CBNA", username = "emille v2";
  40.    
  41.     std::cin >> username;
  42.    
  43.     Irc irc(server, 6667, true);
  44.     irc.connect();
  45.     irc.nick(username);
  46.     irc.user(username, "host", server, server);
  47.     irc.join(chan, "");
  48.    
  49.     switch(rand()%3) {
  50.         case 0: irc.privmsg(chan, "millemille"); break;
  51.         case 1: irc.privmsg(chan, "mille"); break;
  52.         case 2: irc.privmsg(chan, "MIIILLE"); break;
  53.     }
  54.    
  55.     while(true)
  56.     {
  57.         irc.getMessage();
  58.        
  59.         if(irc.messageType() == Irc::Message || irc.messageType() == Irc::PrivateMessage)
  60.         {
  61.             string msg = irc.messageString();
  62.            
  63.             if(mille(msg))
  64.             {
  65.                 int r = rand()%5;
  66.                 switch(r) {
  67.                 case 0: irc.privmsg(chan, "MILLE!"); break;
  68.                 case 1: irc.privmsg(chan, "Miiiille!"); break;
  69.                 case 2: irc.privmsg(chan, "Miiilleuumillemille!"); break;
  70.                 case 3: irc.privmsg(chan, "MILLEUH!"); break;
  71.                 case 4: irc.privmsg(chan, "Mille"); break;
  72.                 }
  73.             }
  74.            
  75.             //if(msg.find("mille"))
  76.             //    cout << "Miiiiillemillemille";
  77.             ///cout << irc.messageUsername() << ": " << msg << endl;
  78.             // Answer example
  79.             ///irc.privmsg(chan, msg);
  80.         }
  81.         else if(irc.messageType() == Irc::Kick)
  82.         {
  83.             cout << "You have been kicked by " << irc.messageUsername() << endl;
  84.             irc.join(chan, "");
  85.         }
  86.     }
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment