]> jfr.im git - irc/evilnet/mod.chanfix.git/blob - DELNOTECommand.cc
Fixed missing include, corebug fix was already applied here.
[irc/evilnet/mod.chanfix.git] / DELNOTECommand.cc
1 /**
2 * DELNOTECommand.cc
3 *
4 * 08/18/2005 - Reed Loden <reed@reedloden.com>
5 * Initial Version
6 *
7 * Deletes a note from this channel
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
27 #include "gnuworld_config.h"
28
29 #include "chanfix.h"
30 #include "responses.h"
31 #include "StringTokenizer.h"
32 #include "sqlChannel.h"
33 #include "sqlcfUser.h"
34
35 RCSTAG("$Id$");
36
37 namespace gnuworld
38 {
39 namespace cf
40 {
41
42 void DELNOTECommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message)
43 {
44 StringTokenizer st(Message);
45
46 sqlChannel* theChan = bot->getChannelRecord(st[1]);
47 if (!theChan) {
48 bot->SendTo(theClient,
49 bot->getResponse(theUser,
50 language::no_entry_in_db,
51 std::string("There is no entry in the database for %s.")).c_str(),
52 st[1].c_str());
53 return;
54 }
55
56 if (!theChan->useSQL() || (theChan->countNotes(bot->getLocalDBHandle(),0) <= 0)) {
57 bot->SendTo(theClient,
58 bot->getResponse(theUser,
59 language::chan_has_no_notes,
60 std::string("The channel %s does not have any notes.")).c_str(),
61 theChan->getChannel().c_str());
62 return;
63 }
64
65 unsigned int messageId = atoi(st[2].c_str());
66
67 /* Get a connection instance to our backend */
68 dbHandle* cacheCon = bot->getLocalDBHandle();
69
70 /* Retrieve the note */
71 std::stringstream noteCheckQuery;
72 noteCheckQuery << "SELECT channelID, user_name, event "
73 << "FROM notes "
74 << "WHERE id = "
75 << messageId
76 ;
77
78 if (!cacheCon->Exec(noteCheckQuery.str(),true)) {
79 elog << "DELNOTECommand> SQL Error: "
80 << cacheCon->ErrorMessage()
81 << std::endl ;
82
83 bot->SendTo(theClient,
84 bot->getResponse(theUser,
85 language::error_checking_noteid,
86 std::string("An unknown error occured while checking the note id.")).c_str());
87
88 /* Dispose of our connection instance */
89 //bot->theManager->removeConnection(cacheCon);
90
91 return;
92 }
93
94 if (cacheCon->Tuples() != 1) {
95 bot->SendTo(theClient,
96 bot->getResponse(theUser,
97 language::no_note_with_id,
98 std::string("There is no such note with that note_id.")).c_str());
99 return;
100 }
101
102 unsigned int channelID = atoi(cacheCon->GetValue(0,0));
103 std::string user_name = cacheCon->GetValue(0,1);
104 unsigned short eventType = atoi(cacheCon->GetValue(0,2));
105
106 /* Dispose of our connection instance */
107 //bot->theManager->removeConnection(cacheCon);
108
109 if (channelID != theChan->getID()) {
110 bot->SendTo(theClient,
111 bot->getResponse(theUser,
112 language::no_note_id_for_chan,
113 std::string("No such note #%d for channel %s.")).c_str(),
114 messageId, theChan->getChannel().c_str());
115 return;
116 }
117
118 if (string_lower(user_name) != string_lower(theUser->getUserName()) && !theUser->getFlag(sqlcfUser::F_USERMANAGER)) {
119 bot->SendTo(theClient,
120 bot->getResponse(theUser,
121 language::note_not_added_by_you,
122 std::string("Note #%d for channel %s was not added by you. You can only delete notes that you added.")).c_str(),
123 messageId, theChan->getChannel().c_str());
124 return;
125 }
126
127 if (eventType != sqlChannel::EV_NOTE && !theUser->getFlag(sqlcfUser::F_OWNER)) {
128 bot->SendTo(theClient,
129 bot->getResponse(theUser,
130 language::note_not_manually_added,
131 std::string("Note #%d for channel %s is not a manually added note. You can only delete notes that were manually added.")).c_str(),
132 messageId, theChan->getChannel().c_str());
133 return;
134 }
135
136 theChan->deleteNote(bot->getLocalDBHandle(),messageId);
137
138 bot->SendTo(theClient,
139 bot->getResponse(theUser,
140 language::note_deleted,
141 std::string("Note #%d for channel %s deleted.")).c_str(),
142 messageId, theChan->getChannel().c_str());
143
144 bot->logAdminMessage("%s (%s) DELNOTE %s %d",
145 theUser->getUserName().c_str(),
146 theClient->getRealNickUserHost().c_str(),
147 theChan->getChannel().c_str(), messageId);
148
149 bot->logLastComMessage(theClient, Message);
150
151 return;
152 }
153
154 } // namespace cf
155 } // namespace gnuworld