]>
jfr.im git - irc/evilnet/mod.chanfix.git/blob - LASTCOMCommand.cc
4 * 18/04/2006 - Neil Spierling <sirvulcan@gmail.com>
5 * Based on mod.ccontrol LASTCOM command.
7 * Sends a list of the last X commands.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24 * $Id: LASTCOMCommand.cc,v 1.4 2008/01/16 02:03:37 buzlip01 Exp $
35 #include "chanfixCommands.h"
37 #include "responses.h"
38 #include "sqlChanOp.h"
39 #include "sqlChannel.h"
40 #include "sqlcfUser.h"
44 #include "StringTokenizer.h"
46 #include "gnuworld_config.h"
48 RCSTAG( "$Id: LASTCOMCommand.cc,v 1.4 2008/01/16 02:03:37 buzlip01 Exp $" ) ;
56 void LASTCOMCommand::Exec(iClient
* theClient
, sqlcfUser
* theUser
, const std::string
& Message
)
58 StringTokenizer
st( Message
) ;
59 unsigned int NumOfCom
;
60 unsigned int Days
= 0;
61 std::stringstream theQuery
;
63 dbHandle
* cacheCon
= bot
->getLocalDBHandle();
65 if (st
.size() == 1 ) {
67 static const char* queryHeader
= "SELECT * FROM comlog ";
68 theQuery
<< queryHeader
69 << " ORDER BY ts DESC"
70 << " LIMIT " << NumOfCom
73 NumOfCom
= atoi(st
[1].c_str());
75 Days
= atoi(st
[2].c_str());
77 bot
->SendTo(theClient
,
78 bot
->getResponse(theUser
,
79 language::lastcom_too_far_back
,
80 std::string("You cannot see logs more than one year ago.")).c_str());
83 static const char* queryHeader
= "SELECT * FROM comlog where ts >";
84 theQuery
<< queryHeader
85 << (::time(0) - Days
* 24 * 3600)
87 << " LIMIT " << NumOfCom
90 static const char* queryHeader
= "SELECT * FROM comlog ";
91 theQuery
<< queryHeader
92 << " ORDER BY ts DESC"
93 << " LIMIT " << NumOfCom
98 elog
<< "chanfix::LASTCOM> "
99 << theQuery
.str().c_str()
102 if (!cacheCon
->Exec(theQuery
.str(),true)) {
103 elog
<< "chanfix::LASTCOM> SQL Error: "
104 << cacheCon
->ErrorMessage()
109 // SQL Query succeeded
110 bot
->SendTo(theClient
,
111 bot
->getResponse(theUser
,
112 language::lastcom_listing_messages
,
113 std::string("Listing last %d messages from day %d.")).c_str(),
116 // TODO: Fix this warning
117 for (int i
= (cacheCon
->Tuples() - 1) ; i
>= 0; i
--) {
118 bot
->SendTo(theClient
,"[ %s - %s ] %s",
119 bot
->convertToAscTime(atoi(cacheCon
->GetValue(i
, 0))),
120 cacheCon
->GetValue(i
,1).c_str(),
121 cacheCon
->GetValue(i
,2).c_str());
124 bot
->SendTo(theClient
,
125 bot
->getResponse(theUser
,
126 language::end_of_log
,
127 std::string("End of LASTCOM report.")).c_str());
129 /* Dispose of our connection instance */
130 //bot->theManager->removeConnection(cacheCon);
132 bot
->logLastComMessage(theClient
, Message
);