ircdelayedoperationban.cpp
1 //------------------------------------------------------------------------------
2 // ircdelayedoperationban.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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/ircnetworkadapter.h"
27 #include "irc/ircresponseparser.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)));
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)
68 {
69  Q_UNUSED(nickname);
70  Q_UNUSED(user);
71  QString banString = "*!*@" + hostName;
72  d->network->sendMessage(QString("/mode %1 +b %2").arg(d->channel, banString));
73  d->network->sendMessage(QString("/kick %1 %2 %3").arg(d->channel, d->nickname, d->reason));
74  this->deleteLater();
75 }
76 
77 void IRCDelayedOperationBan::setReason(const QString &reason)
78 {
79  d->reason = reason;
80 }