tele.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 }