1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
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. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef COREUSERINPUTHANDLER_H
22 #define COREUSERINPUTHANDLER_H
26 #include "corebasichandler.h"
27 #include "corenetwork.h"
32 class CoreUserInputHandler : public CoreBasicHandler
37 CoreUserInputHandler(CoreNetwork* parent = nullptr);
38 inline CoreNetwork* coreNetwork() const { return qobject_cast<CoreNetwork*>(parent()); }
40 void handleUserInput(const BufferInfo& bufferInfo, const QString& text);
41 int lastParamOverrun(const QString& cmd, const QList<QByteArray>& params);
45 * Handle the away command, marking as away or unaway
47 * Applies to the current network unless text begins with "-all".
49 * @param[in] bufferInfo Currently active buffer
50 * @param[in] text Away message, or blank to set unaway
51 * @param[in] skipFormatting If true, skip timestamp formatting codes (e.g. if already done)
53 void handleAway(const BufferInfo& bufferInfo, const QString& text, const bool skipFormatting = false);
54 void handleBan(const BufferInfo& bufferInfo, const QString& text);
55 void handleUnban(const BufferInfo& bufferInfo, const QString& text);
56 void handleCtcp(const BufferInfo& bufferInfo, const QString& text);
57 void handleDelkey(const BufferInfo& bufferInfo, const QString& text);
58 void handleDeop(const BufferInfo& bufferInfo, const QString& nicks);
59 void handleDehalfop(const BufferInfo& bufferInfo, const QString& nicks);
60 void handleDevoice(const BufferInfo& bufferInfo, const QString& nicks);
61 void handleInvite(const BufferInfo& bufferInfo, const QString& text);
62 void handleJoin(const BufferInfo& bufferInfo, const QString& text);
63 void handleKeyx(const BufferInfo& bufferInfo, const QString& text);
64 void handleKick(const BufferInfo& bufferInfo, const QString& text);
65 void handleKill(const BufferInfo& bufferInfo, const QString& text);
66 void handleList(const BufferInfo& bufferInfo, const QString& text);
67 void handleMe(const BufferInfo& bufferInfo, const QString& text);
68 void handleMode(const BufferInfo& bufferInfo, const QString& text);
69 void handleMsg(const BufferInfo& bufferInfo, const QString& text);
70 void handleNick(const BufferInfo& bufferInfo, const QString& text);
71 void handleNotice(const BufferInfo& bufferInfo, const QString& text);
72 void handleOper(const BufferInfo& bufferInfo, const QString& text);
73 void handleOp(const BufferInfo& bufferInfo, const QString& nicks);
74 void handleHalfop(const BufferInfo& bufferInfo, const QString& nicks);
75 void handlePart(const BufferInfo& bufferInfo, const QString& text);
76 void handlePing(const BufferInfo& bufferInfo, const QString& text);
77 void handlePrint(const BufferInfo& bufferInfo, const QString& text);
78 void handleQuery(const BufferInfo& bufferInfo, const QString& text);
79 void handleQuit(const BufferInfo& bufferInfo, const QString& text);
80 void handleQuote(const BufferInfo& bufferInfo, const QString& text);
81 void handleSay(const BufferInfo& bufferInfo, const QString& text);
82 void handleSetkey(const BufferInfo& bufferInfo, const QString& text);
83 void handleShowkey(const BufferInfo& bufferInfo, const QString& text);
84 void handleTopic(const BufferInfo& bufferInfo, const QString& text);
85 void handleVoice(const BufferInfo& bufferInfo, const QString& text);
86 void handleWait(const BufferInfo& bufferInfo, const QString& text);
87 void handleWho(const BufferInfo& bufferInfo, const QString& text);
88 void handleWhois(const BufferInfo& bufferInfo, const QString& text);
89 void handleWhowas(const BufferInfo& bufferInfo, const QString& text);
91 void defaultHandler(QString cmd, const BufferInfo& bufferInfo, const QString& text);
94 * Send a QUIT to the IRC server, optionally skipping the command queue.
96 * @param reason Reason for quitting, often displayed to other IRC clients
97 * @param forceImmediate Immediately quit, skipping queue of other commands
99 void issueQuit(const QString& reason, bool forceImmediate = false);
102 * Issues the away command, marking as away or unaway on the current network
104 * @param[in] msg Away message, or blank to set unaway
105 * @param[in] autoCheck If true, always set away, defaulting to the identity away message
106 * @param[in] skipFormatting If true, skip timestamp formatting codes (e.g. if already done)
108 void issueAway(const QString& msg, bool autoCheck = true, const bool skipFormatting = false);
111 void timerEvent(QTimerEvent* event) override;
114 void doMode(const BufferInfo& bufferInfo, const QChar& addOrRemove, const QChar& mode, const QString& nickList);
115 void banOrUnban(const BufferInfo& bufferInfo, const QString& text, bool ban);
116 void putPrivmsg(const QString& target,
117 const QString& message,
118 std::function<QByteArray(const QString&, const QString&)> encodeFunc,
119 Cipher* cipher = nullptr);
122 QByteArray encrypt(const QString& target, const QByteArray& message, bool* didEncrypt = nullptr) const;
127 BufferInfo bufferInfo;
129 Command(BufferInfo info, QString command)
130 : bufferInfo(std::move(info))
131 , command(std::move(command))
136 QHash<int, Command> _delayedCommands;