]> jfr.im git - irc/evilnet/mod.chanfix.git/blob - LASTCOMCommand.cc
Fixed missing include, corebug fix was already applied here.
[irc/evilnet/mod.chanfix.git] / LASTCOMCommand.cc
1 /**
2 * LASTCOMCommand.cc
3 *
4 * 18/04/2006 - Neil Spierling <sirvulcan@gmail.com>
5 * Based on mod.ccontrol LASTCOM command.
6 *
7 * Sends a list of the last X commands.
8 *
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.
13 *
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.
18 *
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,
22 * USA.
23 *
24 * $Id: LASTCOMCommand.cc,v 1.4 2008/01/16 02:03:37 buzlip01 Exp $
25 */
26
27 #include <sstream>
28 #include <string>
29 #include <iostream>
30 #include <iomanip>
31
32 #include <cstdlib>
33
34 #include "chanfix.h"
35 #include "chanfixCommands.h"
36 #include "defs.h"
37 #include "responses.h"
38 #include "sqlChanOp.h"
39 #include "sqlChannel.h"
40 #include "sqlcfUser.h"
41
42 #include "Network.h"
43 #include "iClient.h"
44 #include "StringTokenizer.h"
45 #include "ELog.h"
46 #include "gnuworld_config.h"
47
48 RCSTAG( "$Id: LASTCOMCommand.cc,v 1.4 2008/01/16 02:03:37 buzlip01 Exp $" ) ;
49
50 namespace gnuworld
51 {
52
53 namespace cf
54 {
55
56 void LASTCOMCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message)
57 {
58 StringTokenizer st( Message ) ;
59 unsigned int NumOfCom;
60 unsigned int Days = 0;
61 std::stringstream theQuery;
62
63 dbHandle* cacheCon = bot->getLocalDBHandle();
64
65 if (st.size() == 1 ) {
66 NumOfCom = 20;
67 static const char* queryHeader = "SELECT * FROM comlog ";
68 theQuery << queryHeader
69 << " ORDER BY ts DESC"
70 << " LIMIT " << NumOfCom
71 << std::ends;
72 } else {
73 NumOfCom = atoi(st[1].c_str());
74 if (st.size() > 2) {
75 Days = atoi(st[2].c_str());
76 if (Days > 365) {
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());
81 return;
82 }
83 static const char* queryHeader = "SELECT * FROM comlog where ts >";
84 theQuery << queryHeader
85 << (::time(0) - Days * 24 * 3600)
86 << " ORDER BY ts ASC"
87 << " LIMIT " << NumOfCom
88 << std::ends;
89 } else {
90 static const char* queryHeader = "SELECT * FROM comlog ";
91 theQuery << queryHeader
92 << " ORDER BY ts DESC"
93 << " LIMIT " << NumOfCom
94 << std::ends;
95 }
96 }
97
98 elog << "chanfix::LASTCOM> "
99 << theQuery.str().c_str()
100 << std::endl;
101
102 if (!cacheCon->Exec(theQuery.str(),true)) {
103 elog << "chanfix::LASTCOM> SQL Error: "
104 << cacheCon->ErrorMessage()
105 << std::endl ;
106 return;
107 }
108
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(),
114 NumOfCom,Days);
115
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());
122 }
123
124 bot->SendTo(theClient,
125 bot->getResponse(theUser,
126 language::end_of_log,
127 std::string("End of LASTCOM report.")).c_str());
128
129 /* Dispose of our connection instance */
130 //bot->theManager->removeConnection(cacheCon);
131
132 bot->logLastComMessage(theClient, Message);
133
134 return;
135 }
136
137 }
138 }
139