ircdelayedoperationban.cpp
1 //------------------------------------------------------------------------------
2 // ircdelayedoperationban.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "ircdelayedoperationban.h"
24 
25 #include "irc/entities/ircuserprefix.h"
26 #include "irc/ircresponseparser.h"
27 #include "irc/ircnetworkadapter.h"
28 
29 DClass<IRCDelayedOperationBan>
30 {
31 public:
32  QString channel;
33  QString nickname;
34  QString reason;
35  IRCNetworkAdapter *network;
36 
37  QString cleanNickname() const
38  {
39  return network->userPrefixes().cleanNickname(nickname);
40  }
41 };
42 
43 DPointered(IRCDelayedOperationBan)
44 
46  const QString &channel, const QString &nickname, QObject *parent)
47 : IRCDelayedOperation(parent)
48 {
49  d->channel = channel;
50  d->nickname = nickname;
51  d->network = network;
52  this->connect(d->network->responseParser(),
53  SIGNAL(whoIsUser(QString, QString, QString, QString)),
54  SLOT(onWhoIsUser(QString, QString, QString, QString)));
55 }
56 
57 IRCDelayedOperationBan::~IRCDelayedOperationBan()
58 {
59 }
60 
61 void IRCDelayedOperationBan::start()
62 {
63  d->network->sendMessage(QString("/whois %1").arg(d->cleanNickname()));
64 }
65 
66 void IRCDelayedOperationBan::onWhoIsUser(const QString& nickname, const QString& user,
67  const QString& hostName, const QString& realName)
68 {
69  QString banString = "*!*@" + hostName;
70  d->network->sendMessage(QString("/mode %1 +b %2").arg(d->channel, banString));
71  d->network->sendMessage(QString("/kick %1 %2 %3").arg(d->channel, d->nickname, d->reason));
72  this->deleteLater();
73 }
74 
75 void IRCDelayedOperationBan::setReason(const QString &reason)
76 {
77  d->reason = reason;
78 }
Interprets communication between the client and the IRC server.
const IRCUserPrefix & userPrefixes() const
All allowed modes with their nickname prefixes for this network.