tele.cpp

Go to the documentation of this file.
00001 /*
00002 #########################################################################
00003 #
00004 #  This file is part of trustyRC.
00005 #
00006 #  trustyRC, fully modular IRC robot 
00007 #  Copyright (C) 2006-2008 Nicoleau Fabien 
00008 #
00009 #  trustyRC is free software: you can redistribute it and/or modify
00010 #  it under the terms of the GNU General Public License as published by
00011 #  the Free Software Foundation, either version 3 of the License, or
00012 #  (at your option) any later version.
00013 #
00014 #  trustyRC is distributed in the hope that it will be useful,
00015 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 #  GNU General Public License for more details.
00018 #
00019 #  You should have received a copy of the GNU General Public License
00020 #  along with trustyRC.  If not, see <http://www.gnu.org/licenses/>.
00021 #
00022 #########################################################################
00023 */
00024 
00029 #include "tele.h"
00030 
00034 Tele::Tele(BotKernel*b)
00035 {
00036         this->author = "eponyme";
00037         this->description = "Display french TV program";
00038         this->version = VERSION;
00039         this->name = "tele";
00040         this->bindFunction("tele",IN_COMMAND_HANDLER,"tele",0,35);
00041         this->bindFunction("tv",IN_COMMAND_HANDLER,"tele",0,35);
00042 }
00043 
00044 extern "C"
00045 {
00046         Plugin *contruct_tele(BotKernel*b)
00047         {
00048                 return new Tele(b);
00049         }
00050         void destroy_tele(Plugin*p)
00051         {
00052                 delete p;
00053         }
00054         bool tele(Message*m,Plugin*p,BotKernel*b)
00055         {
00056       const string HERTZ = "class=\"homeProgramHertz\">" ;
00057       const string TITLE = "title=\"";
00058       const string ALT = "alt=\"";
00059       const string END_CHANNEL = "</tr>";
00060       const string CHANNEL7 = "<tr id=\"ctl00_cphM_HP1_Repeater1_ctl07_trItem\"" ;
00061       string channel = "";
00062       string buffer;
00063       string::size_type pos ;
00064       unsigned int i = 0 ;
00065       Socket sock = Socket();
00066       if (m->isPublic())
00067       {
00068          if (!sock.connectSock(80,"www.telephant.com","")) {
00069             b->send(IRCProtocol::sendMsg(m->getSource(), "* Unable to connect to www.telephant.com *") );
00070             return true;
00071          }
00072          sock.sendStr("GET /programme-tv-en-ce-moment.html HTTP/1.1\nHost: www.telephant.com\n\n") ;
00073          while ((buffer.find(CHANNEL7)==string::npos)&&(buffer.find("</body>")==string::npos)) {
00074             buffer += sock.receive();
00075          }
00076          pos = buffer.find(HERTZ) ;
00077          if ( pos != string::npos) {
00078             buffer = buffer.substr(pos+HERTZ.length()) ;
00079             pos = buffer.find(TITLE); 
00080             while ( pos != string::npos) {
00081                buffer =  buffer.substr(buffer.find(ALT)+ALT.length());
00082                channel = buffer.substr(0,buffer.find("\"")) ;
00083                pos = buffer.find(TITLE);
00084                buffer = buffer.substr(pos+TITLE.length());
00085                b->send(IRCProtocol::sendMsg(m->getSource(),Tools::clearAccents(Tools::cleanHTML(channel+" : "+buffer.substr(0,buffer.find("\"")))))) ;
00086                buffer = buffer.substr(buffer.find(END_CHANNEL));
00087                pos = buffer.find(TITLE);
00088                i++;
00089             }
00090          }
00091          else {
00092             b->send(IRCProtocol::sendMsg(m->getSource(),"* Parse error *")) ;
00093          }
00094       }
00095                 return true;
00096         }
00097 }

Generated on Sun Aug 16 15:28:29 2009 for trustyRC by  doxygen 1.5.8