4 * 08/18/2005 - Reed Loden <reed@reedloden.com>
7 * Deletes a note from this channel
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,
27 #include "gnuworld_config.h"
30 #include "responses.h"
31 #include "StringTokenizer.h"
32 #include "sqlChannel.h"
33 #include "sqlcfUser.h"
42 void DELNOTECommand::Exec(iClient
* theClient
, sqlcfUser
* theUser
, const std::string
& Message
)
44 StringTokenizer
st(Message
);
46 sqlChannel
* theChan
= bot
->getChannelRecord(st
[1]);
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(),
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());
65 unsigned int messageId
= atoi(st
[2].c_str());
67 /* Get a connection instance to our backend */
68 dbHandle
* cacheCon
= bot
->getLocalDBHandle();
70 /* Retrieve the note */
71 std::stringstream noteCheckQuery
;
72 noteCheckQuery
<< "SELECT channelID, user_name, event "
78 if (!cacheCon
->Exec(noteCheckQuery
.str(),true)) {
79 elog
<< "DELNOTECommand> SQL Error: "
80 << cacheCon
->ErrorMessage()
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());
88 /* Dispose of our connection instance */
89 //bot->theManager->removeConnection(cacheCon);
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());
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));
106 /* Dispose of our connection instance */
107 //bot->theManager->removeConnection(cacheCon);
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());
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());
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());
136 theChan
->deleteNote(bot
->getLocalDBHandle(),messageId
);
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());
144 bot
->logAdminMessage("%s (%s) DELNOTE %s %d",
145 theUser
->getUserName().c_str(),
146 theClient
->getRealNickUserHost().c_str(),
147 theChan
->getChannel().c_str(), messageId
);
149 bot
->logLastComMessage(theClient
, Message
);
155 } // namespace gnuworld