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 "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 }