]> jfr.im git - irc/evilnet/mod.chanfix.git/blame - INFOCommand.cc
Fixed missing include, corebug fix was already applied here.
[irc/evilnet/mod.chanfix.git] / INFOCommand.cc
CommitLineData
ad033759 1/**
2 * INFOCommand.cc
3 *
4 * 07/20/2005 - Reed Loden <reed@reedloden.com>
5 * Initial Version
6 *
7 * Shows all notes of this channel, and whether it has been blocked
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$
25 */
26
ad033759 27#include "gnuworld_config.h"
28#include "Network.h"
29
30#include "chanfix.h"
91cad274 31#include "responses.h"
ad033759 32#include "StringTokenizer.h"
33#include "sqlChannel.h"
13a50edb 34#include "sqlcfUser.h"
ad033759 35
36RCSTAG("$Id$");
37
38namespace gnuworld
39{
1d54d2a1 40namespace cf
41{
ad033759 42
13a50edb 43void INFOCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message)
ad033759 44{
45StringTokenizer st(Message);
dee49a74 46
ff696c26 47bool isBlocked = bot->isTempBlocked(st[1]);
48
ad033759 49sqlChannel* theChan = bot->getChannelRecord(st[1]);
ff696c26 50
ccc771d8 51if (!theChan) {
ff696c26 52 if (isBlocked) {
53 bot->SendTo(theClient,
87fb1731 54 bot->getResponse(theUser,
ff696c26 55 language::temporarily_blocked,
1458465b 56 std::string("%s is temporarily blocked. (Use OVERRIDE to bypass)")).c_str(),
ff696c26 57 st[1].c_str());
58 return;
59 }
60
91cad274 61 bot->SendTo(theClient,
62 bot->getResponse(theUser,
63 language::no_info_for_chan,
64 std::string("No information on %s in the database.")).c_str(),
65 st[1].c_str());
ad033759 66 return;
67}
68
91cad274 69bot->SendTo(theClient,
70 bot->getResponse(theUser,
71 language::information_on,
72 std::string("Information on %s:")).c_str(),
73 theChan->getChannel().c_str());
ad033759 74
87fb1731 75if (isBlocked)
ff696c26 76 bot->SendTo(theClient,
77 bot->getResponse(theUser,
78 language::temporarily_blocked,
1458465b 79 std::string("%s is temporarily blocked. (Use OVERRIDE to bypass)")).c_str(),
ff696c26 80 st[1].c_str());
ff696c26 81
ad033759 82if (theChan->getFlag(sqlChannel::F_BLOCKED))
91cad274 83 bot->SendTo(theClient,
84 bot->getResponse(theUser,
85 language::info_chan_blocked,
86 std::string("%s is BLOCKED.")).c_str(),
87 theChan->getChannel().c_str());
ad033759 88else if (theChan->getFlag(sqlChannel::F_ALERT))
91cad274 89 bot->SendTo(theClient,
90 bot->getResponse(theUser,
91 language::info_chan_alerted,
92 std::string("%s is ALERTED.")).c_str(),
93 theChan->getChannel().c_str());
ad033759 94
95Channel* netChan = Network->findChannel(st[1]);
87fb1731 96if (netChan && bot->isBeingFixed(netChan)) {
ad033759 97 if (bot->isBeingChanFixed(netChan))
91cad274 98 bot->SendTo(theClient,
99 bot->getResponse(theUser,
100 language::info_chan_being_fixed,
101 std::string("%s is being chanfixed.")).c_str(),
102 theChan->getChannel().c_str());
ad033759 103 if (bot->isBeingAutoFixed(netChan))
91cad274 104 bot->SendTo(theClient,
105 bot->getResponse(theUser,
106 language::info_chan_being_autofixed,
107 std::string("%s is being autofixed.")).c_str(),
108 theChan->getChannel().c_str());
97018285 109
87fb1731 110 if (theChan->getFixStart() > 0)
111 bot->SendTo(theClient,
97018285 112 bot->getResponse(theUser,
113 language::info_fix_started,
114 std::string("Current fix has been running for %s")).c_str(),
115 bot->prettyDuration(theChan->getFixStart()).c_str());
87fb1731 116 else
117 bot->SendTo(theClient,
97018285 118 bot->getResponse(theUser,
119 language::info_fix_waiting,
120 std::string("Current fix is on hold (waiting for ops to join)")).c_str());
ad033759 121}
122
ccc771d8 123if (!theChan->useSQL()) {
87fb1731 124 bot->logAdminMessage("%s (%s) INFO %s",
125 theUser ? theUser->getUserName().c_str() : "!NOT-LOGGED-IN!",
126 theClient->getRealNickUserHost().c_str(),
127 theChan->getChannel().c_str());
ccc771d8 128 bot->SendTo(theClient,
129 bot->getResponse(theUser,
130 language::end_of_information,
131 std::string("End of information.")).c_str());
132 return;
133}
134
dbbf1647 135/* Get a connection instance to our backend */
23cb8771 136dbHandle* cacheCon = bot->getLocalDBHandle();
dbbf1647 137
92b0a9b9 138/*
139 * Perform a query to list all notes belonging to this channel.
140 */
141std::stringstream allNotesQuery;
e0282ee9 142allNotesQuery << "SELECT notes.id, notes.ts, notes.user_name, notes.event, notes.message "
adf4d06b 143 << "FROM notes "
e0282ee9 144 << "WHERE notes.channelID = "
92b0a9b9 145 << theChan->getID()
146 << " ORDER BY notes.ts DESC"
a6218cc3 147 ;
92b0a9b9 148
23cb8771 149if (!cacheCon->Exec(allNotesQuery.str(),true)) {
dbbf1647 150 elog << "INFOCommand> SQL Error: "
151 << cacheCon->ErrorMessage()
152 << std::endl;
92b0a9b9 153
dbbf1647 154 bot->SendTo(theClient,
155 bot->getResponse(theUser,
156 language::error_occured_notes,
157 std::string("An unknown error occurred while reading this channel's notes.")).c_str());
92b0a9b9 158
dbbf1647 159 /* Dispose of our connection instance */
23cb8771 160 //bot->theManager->removeConnection(cacheCon);
92b0a9b9 161
dbbf1647 162 return ;
163}
164
165unsigned int noteCount = cacheCon->Tuples();
92b0a9b9 166
167if (noteCount > 0) {
91cad274 168 bot->SendTo(theClient,
169 bot->getResponse(theUser,
170 language::info_notes_count,
171 std::string("Notes (%d):")).c_str(), noteCount);
92b0a9b9 172
173 for (unsigned int i = 0; i < noteCount; i++) {
dbbf1647 174 unsigned int note_id = atoi(cacheCon->GetValue(i,0));
175 unsigned int when = atoi(cacheCon->GetValue(i,1));
176 std::string from = cacheCon->GetValue(i,2);
177 unsigned short event = atoi(cacheCon->GetValue(i,3));
178 std::string theMessage = cacheCon->GetValue(i,4);
92b0a9b9 179
91cad274 180 bot->SendTo(theClient,
181 bot->getResponse(theUser,
182 language::info_notes,
183 std::string("[%d:%s] %s \002%s\002%s%s")).c_str(),
184 note_id, from.c_str(),
185 bot->tsToDateTime(when, true).c_str(),
186 bot->getEventName(event).c_str(),
187 (!theMessage.empty()) ? " " : "", theMessage.c_str());
92b0a9b9 188 }
189}
ad033759 190
91cad274 191bot->SendTo(theClient,
192 bot->getResponse(theUser,
193 language::end_of_information,
194 std::string("End of information.")).c_str());
ad033759 195
dbbf1647 196/* Dispose of our connection instance */
23cb8771 197//bot->theManager->removeConnection(cacheCon);
dbbf1647 198
8de4dcba 199bot->logAdminMessage("%s (%s) INFO %s",
87fb1731 200 theUser ? theUser->getUserName().c_str() : "!NOT-LOGGED-IN!",
201 theClient->getRealNickUserHost().c_str(),
202 theChan->getChannel().c_str());
8de4dcba 203
25f00d30 204bot->logLastComMessage(theClient, Message);
205
ad033759 206return;
207}
1d54d2a1 208
209} // namespace cf
ad033759 210} // namespace gnuworld