naraku9333

Untitled

Jan 15th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. //
  2. // aBot
  3. // ~~~~~~~~~~
  4. //
  5. // Sean Vogel svogel at comcast dot net
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10.  
  11.  
  12. #include "Bot.hpp"
  13. #include <iostream>
  14. #include <thread>
  15. #include <chrono>
  16.  
  17. int main(int argc, char* argv[])
  18. {
  19.     if(argc >= 3)      
  20.     {
  21.         std::string channel = (argc >= 4) ? argv[3] : "##c++";
  22.         std::string port = (argc >= 5) ? argv[4] : "6667";
  23.        
  24.         //API key from http://www.wunderground.com/weather/api/
  25.         //REQUIRED to use weather feature
  26.         std::string api = (argc >= 6) ? argv[5] : "";
  27.  
  28.         sv::Bot bot(argv[1], argv[2], port, api);
  29.        
  30.         try
  31.         {
  32.             using namespace std::chrono;
  33.             bot.connect();
  34.             std::thread t(&sv::Bot::listen, std::ref(bot));
  35.  
  36.             duration<int> seconds(10);
  37.             system_clock::time_point ti = system_clock::now() + seconds;
  38.             while (ti > system_clock::now())
  39.             {
  40.  
  41.             }
  42.  
  43.             bot.join(channel);
  44.             t.join();
  45.         }
  46.         catch(std::exception& e)
  47.         {
  48.             std::cout << e.what() << std::endl;
  49.         }
  50.     }  
  51.     else
  52.         std::cout << "USAGE:\nRun with:  abot <nick> <server> <channel>optional <port>optional" << std::endl;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment