infos.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 "infos.h"
00030 
00034 Infos::Infos(BotKernel*b)
00035 {
00036         this->author = "eponyme";
00037         this->description = "Infos about kernel";
00038         this->version = VERSION;
00039         this->name = "infos";
00040         this->bindFunction("uptime",IN_COMMAND_HANDLER,"uptime",0,10);
00041         this->bindFunction("version",IN_COMMAND_HANDLER,"version",0,10);
00042         this->bindFunction("sysinfos",IN_COMMAND_HANDLER,"sysinfos",0,10);
00043         this->bindFunction("online",IN_COMMAND_HANDLER,"online",0,10);
00044         this->bindFunction("!prefix",IN_FREE_COMMAND_HANDLER,"prefix",0,10);
00045         this->bindFunction("!help",IN_FREE_COMMAND_HANDLER,"help",0,10);
00046         this->bindFunction("help",IN_COMMAND_HANDLER,"help",0,10);
00047 }
00048 
00049 extern "C"
00050 {
00051         Plugin *contruct_infos(BotKernel*b)
00052         {
00053                 return new Infos(b);
00054         }
00055         void destroy_infos(Plugin*p)
00056         {
00057                 delete p;
00058         }
00059         bool uptime(Message*m,Plugin*p,BotKernel*b)
00060         {
00061       time_t now;
00062       time(&now);
00063       double seconds,minutes,hours,days,weeks;
00064       seconds = difftime(now,b->getStartTime());
00065       minutes = seconds/60 ;
00066       hours = minutes /60;
00067       days = hours / 24 ;
00068       weeks = days / 7 ;
00069       seconds = int(seconds)%60;
00070       minutes = int(minutes)%60;
00071       hours = int(hours)%24;
00072       days = int(days)%7;
00073       weeks = int(weeks);
00074       b->send(IRCProtocol::sendNotice(m->getNickSender(),"* " + Tools::intToStr((int)weeks) + "w " + Tools::intToStr((int)days) + "d "  + Tools::intToStr((int)hours) + "h " +Tools::intToStr((int)minutes) + "m " +Tools::intToStr((int)seconds) + "s *"));  
00075                 return true;
00076         }
00077         bool version(Message*m,Plugin*p,BotKernel*b)
00078         {
00079       b->send(IRCProtocol::sendNotice(m->getNickSender(),b->getVersion()));
00080                 return true;
00081         }
00082         bool sysinfos(Message*m,Plugin*p,BotKernel*b)
00083         {
00084       if (system (((string)"uname -a > "+b->getDatasDir()+"sysinfo.log && uptime >> "+b->getDatasDir()+"sysinfo.log").c_str()) != -1 ) {
00085          std::ifstream fileinfos((b->getDatasDir()+"sysinfo.log").c_str() );
00086          if ( fileinfos ) {
00087             string line; 
00088             while ( getline( fileinfos, line ) ) {
00089                b->send(IRCProtocol::sendNotice(m->getNickSender(),line));
00090             }
00091             fileinfos.close();
00092          }
00093       }
00094       else {
00095          b->send(IRCProtocol::sendNotice(m->getNickSender(),"Execution error"));
00096       }
00097                 return true;
00098         }
00099         bool online(Message*m,Plugin*p,BotKernel*b)
00100         {
00101       time_t now;
00102       time(&now);
00103       double seconds,minutes,hours,days,weeks;
00104       seconds = difftime(now,b->getStartOnline());
00105       minutes = seconds/60 ;
00106       hours = minutes /60;
00107       days = hours / 24 ;
00108       weeks = days / 7 ;
00109       seconds = int(seconds)%60;
00110       minutes = int(minutes)%60;
00111       hours = int(hours)%24;
00112       days = int(days)%7;
00113       weeks = int(weeks);
00114       b->send(IRCProtocol::sendNotice(m->getNickSender(),"* " + Tools::intToStr((int)weeks) + "w " + Tools::intToStr((int)days) + "d " + Tools::intToStr((int)hours) + "h " +Tools::intToStr((int)minutes) + "m " +Tools::intToStr((int)seconds) + "s *"));  
00115                 return true;
00116         }
00117         bool prefix(Message*m,Plugin*p,BotKernel*b)
00118         {
00119       ConfigurationFile*cff = b->getCONFF();
00120       b->send( IRCProtocol::sendNotice(m->getNickSender(),"Prefix for command is : '"+cff->getValue("kernel.command_prefix"))+"'" ); 
00121                 return true;
00122         }
00123         bool help (Message*m,Plugin*p,BotKernel*b)
00124    {
00125       ConfigurationFile*cff = b->getCONFF();
00126       b->send( IRCProtocol::sendNotice(m->getNickSender(),"Prefix for command is : '"+cff->getValue("kernel.command_prefix")+"' - Manual at "+cff->getValue(p->getName()+".helpurl"))) ;
00127       return false;
00128    }
00129 }

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