1 /***************************************************************************
2 * Copyright (C) 2005-2020 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 #include "eventstringifier.h"
23 #include "coresession.h"
24 #include "ctcpevent.h"
26 #include "messageevent.h"
28 EventStringifier::EventStringifier(CoreSession* parent)
29 : BasicHandler("handleCtcp", parent)
30 , _coreSession(parent)
33 connect(this, &EventStringifier::newMessageEvent, coreSession()->eventManager(), &EventManager::postEvent);
36 void EventStringifier::displayMsg(NetworkEvent* event,
37 Message::Type msgType,
41 Message::Flags msgFlags)
43 if (event->flags().testFlag(EventManager::Silent))
46 MessageEvent* msgEvent = createMessageEvent(event, msgType, std::move(msg), std::move(sender), std::move(target), msgFlags);
47 // sendMessageEvent(msgEvent);
48 emit newMessageEvent(msgEvent);
51 MessageEvent* EventStringifier::createMessageEvent(NetworkEvent* event,
52 Message::Type msgType,
56 Message::Flags msgFlags)
58 MessageEvent* msgEvent = new MessageEvent(msgType, event->network(), std::move(msg), std::move(sender), std::move(target), msgFlags, event->timestamp());
62 bool EventStringifier::checkParamCount(IrcEvent* e, int minParams)
64 if (e->params().count() < minParams) {
65 if (e->type() == EventManager::IrcEventNumeric) {
66 qWarning() << "Command " << static_cast<IrcEventNumeric*>(e)->number() << " requires " << minParams
67 << "params, got: " << e->params();
70 QString name = EventManager::enumName(e->type());
71 qWarning() << qPrintable(name) << "requires" << minParams << "params, got:" << e->params();
79 /* These are only for legacy reasons; remove as soon as we handle NetworkSplitEvents properly */
80 void EventStringifier::processNetworkSplitJoin(NetworkSplitEvent* e)
82 QString msg = e->users().join("#:#") + "#:#" + e->quitMessage();
83 displayMsg(e, Message::NetsplitJoin, msg, QString(), e->channel());
86 void EventStringifier::processNetworkSplitQuit(NetworkSplitEvent* e)
88 QString msg = e->users().join("#:#") + "#:#" + e->quitMessage();
89 displayMsg(e, Message::NetsplitQuit, msg, QString(), e->channel());
94 void EventStringifier::processIrcEventNumeric(IrcEventNumeric* e)
96 // qDebug() << e->number();
97 switch (e->number()) {
98 // Welcome, status, info messages. Just display these.
119 displayMsg(e, Message::Server, e->params().join(" "), e->prefix());
122 // Server error messages without param, just display them
144 case 431: // ERR_NONICKNAMEGIVEN
145 displayMsg(e, Message::Error, e->params().join(" "), e->prefix());
148 // Server error messages, display them in red. Colon between first param and rest.
150 if (!checkParamCount(e, 1))
153 QStringList params = e->params();
154 QString target = params.takeFirst();
155 displayMsg(e, Message::Error, target + ": " + params.join(" "), e->prefix(), target, Message::Redirected);
167 if (!checkParamCount(e, 1))
170 QStringList params = e->params();
171 QString channelName = params.takeFirst();
172 displayMsg(e, Message::Error, channelName + ": " + params.join(" "), e->prefix());
176 // Server error messages which will be displayed with a colon between the first param and the rest
182 case 461: // FIXME see below for the 47x codes
192 case 436: // ERR_NICKCOLLISION
194 if (!checkParamCount(e, 1))
197 QStringList params = e->params();
198 QString p = params.takeFirst();
199 displayMsg(e, Message::Error, p + ": " + params.join(" "));
203 // Ignore these commands.
210 // SASL authentication stuff
211 // See: http://ircv3.net/specs/extensions/sasl-3.1.html
212 case 900: // RPL_LOGGEDIN
213 case 901: // RPL_LOGGEDOUT
215 // :server 900 <nick> <nick>!<ident>@<host> <account> :You are now logged in as <user>
216 // :server 901 <nick> <nick>!<ident>@<host> :You are now logged out
217 if (!checkParamCount(e, 3))
219 displayMsg(e, Message::Server, "SASL: " + e->params().at(2));
222 // Ignore SASL success, partially redundant with RPL_LOGGEDIN and RPL_LOGGEDOUT
223 case 903: // RPL_SASLSUCCESS :server 903 <nick> :SASL authentication successful
225 case 902: // ERR_NICKLOCKED :server 902 <nick> :You must use a nick assigned to you
226 case 904: // ERR_SASLFAIL :server 904 <nick> :SASL authentication failed
227 case 905: // ERR_SASLTOOLONG :server 905 <nick> :SASL message too long
228 case 906: // ERR_SASLABORTED :server 906 <nick> :SASL authentication aborted
229 case 907: // ERR_SASLALREADY :server 907 <nick> :You have already authenticated using SASL
230 case 908: // RPL_SASLMECHS :server 908 <nick> <mechanisms> :are available SASL mechanisms
232 displayMsg(e, Message::Server, "SASL: " + e->params().join(""));
236 // Everything else will be marked in red, so we can add them somewhere.
239 // many nets define their own WHOIS fields. we fetch those not in need of special attention here:
240 displayMsg(e, Message::Server, tr("[Whois] ") + e->params().join(" "), e->prefix());
243 // FIXME figure out how/where to do this in the future
244 // if(coreSession()->ircListHelper()->requestInProgress(network()->networkId()))
245 // coreSession()->ircListHelper()->reportError(params.join(" "));
247 displayMsg(e, Message::Error, QString("%1 %2").arg(e->number(), 3, 10, QLatin1Char('0')).arg(e->params().join(" ")), e->prefix());
252 void EventStringifier::processIrcEventInvite(IrcEvent* e)
254 if (!checkParamCount(e, 2))
257 // TODO: provide a nicer UI for invite notifications
258 QString target = e->params().at(0);
259 QString channel = e->params().at(1);
260 if (e->network()->isMyNick(target)) {
261 displayMsg(e, Message::Invite, tr("%1 invited you to channel %2").arg(e->nick(), channel));
264 displayMsg(e, Message::Invite, tr("%1 invited %2 to channel %3").arg(e->nick(), target, channel));
268 void EventStringifier::processIrcEventJoin(IrcEvent* e)
270 if (e->testFlag(EventManager::Netsplit))
273 Message::Flag msgFlags = Message::Flag::None;
274 if (e->testFlag(EventManager::Self)) {
275 // Mark the message as Self
276 msgFlags = Message::Self;
279 displayMsg(e, Message::Join, e->params()[0], e->prefix(), e->params()[0], msgFlags);
282 void EventStringifier::processIrcEventKick(IrcEvent* e)
284 if (!checkParamCount(e, 2))
287 IrcUser* victim = e->network()->ircUser(e->params().at(1));
289 QString channel = e->params().at(0);
290 QString msg = victim->nick();
291 if (e->params().count() > 2)
292 msg += " " + e->params().at(2);
294 Message::Flag msgFlags = Message::Flag::None;
295 if (e->testFlag(EventManager::Self)) {
296 // Mark the message as Self
297 msgFlags = Message::Self;
300 displayMsg(e, Message::Kick, msg, e->prefix(), channel, msgFlags);
304 void EventStringifier::processIrcEventMode(IrcEvent* e)
306 if (e->network()->isChannelName(e->params().first())) {
308 displayMsg(e, Message::Mode, e->params().join(" "), e->prefix(), e->params().first());
314 Message::Flag msgFlags = Message::Flag::None;
315 if (e->testFlag(EventManager::Self)) {
316 // Mark the message as Self
317 msgFlags = Message::Self;
319 displayMsg(e, Message::Mode, e->params().join(" "), e->prefix(), QString(), msgFlags);
323 // this needs to be called before the ircuser is renamed!
324 void EventStringifier::processIrcEventNick(IrcEvent* e)
326 if (!checkParamCount(e, 1))
329 IrcUser* ircuser = e->network()->updateNickFromMask(e->prefix());
331 qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
335 QString newnick = e->params().at(0);
338 Message::Flag msgFlags = Message::Flag::None;
339 if (e->testFlag(EventManager::Self)) {
340 // Treat the sender as the new nickname, mark the message as Self
342 msgFlags = Message::Self;
345 // Take the sender from the event prefix, don't mark the message
346 sender = e->prefix();
349 // Announce to all channels the IrcUser is in
350 for (const QString& channel : ircuser->channels()) {
351 displayMsg(e, Message::Nick, newnick, sender, channel, msgFlags);
355 void EventStringifier::processIrcEventPart(IrcEvent* e)
357 if (!checkParamCount(e, 1))
360 QString channel = e->params().at(0);
361 QString msg = e->params().count() > 1 ? e->params().at(1) : QString();
363 Message::Flag msgFlags = Message::Flag::None;
364 if (e->testFlag(EventManager::Self)) {
365 // Mark the message as Self
366 msgFlags = Message::Self;
369 displayMsg(e, Message::Part, msg, e->prefix(), channel, msgFlags);
372 void EventStringifier::processIrcEventPong(IrcEvent* e)
374 // CoreSessionEventProcessor will flag automated PONG replies as EventManager::Silent. There's
375 // no need to handle that specially here.
377 // Format the PONG reply for display
378 displayMsg(e, Message::Server, "PONG " + e->params().join(" "), e->prefix());
381 void EventStringifier::processIrcEventQuit(IrcEvent* e)
383 if (e->testFlag(EventManager::Netsplit))
386 IrcUser* ircuser = e->network()->updateNickFromMask(e->prefix());
390 Message::Flag msgFlags = Message::Flag::None;
391 if (e->testFlag(EventManager::Self)) {
392 // Mark the message as Self
393 msgFlags = Message::Self;
396 // Announce to all channels the IrcUser is in
397 for (const QString& channel : ircuser->channels()) {
398 displayMsg(e, Message::Quit, e->params().count() ? e->params().first() : QString(), e->prefix(), channel, msgFlags);
402 void EventStringifier::processIrcEventTopic(IrcEvent* e)
404 Message::Flag msgFlags = Message::Flag::None;
405 if (e->testFlag(EventManager::Self)) {
406 // Mark the message as Self
407 msgFlags = Message::Self;
412 tr("%1 has changed topic for %2 to: \"%3\"").arg(e->nick(), e->params().at(0), e->params().at(1)),
418 void EventStringifier::processIrcEventError(IrcEvent* e)
420 // Need an error reason
421 if (!checkParamCount(e, 1))
424 displayMsg(e, Message::Server, tr("Error from server: ") + e->params().join(""));
427 void EventStringifier::processIrcEventWallops(IrcEvent* e)
429 displayMsg(e, Message::Server, tr("[Operwall] %1: %2").arg(e->nick(), e->params().join(" ")));
433 void EventStringifier::processIrcEvent005(IrcEvent* e)
435 if (!e->params().last().contains(QRegExp("are supported (by|on) this server")))
436 displayMsg(e, Message::Error, tr("Received non-RFC-compliant RPL_ISUPPORT: this can lead to unexpected behavior!"), e->prefix());
437 displayMsg(e, Message::Server, e->params().join(" "), e->prefix());
440 /* RPL_AWAY - "<nick> :<away message>" */
441 void EventStringifier::processIrcEvent301(IrcEvent* e)
443 QString nick = e->params().at(0);
444 QString awayMsg = e->params().at(1);
448 // FIXME: proper redirection needed
450 msg = tr("[Whois] ");
454 IrcUser* ircuser = e->network()->ircUser(nick);
456 QDateTime now = QDateTime::currentDateTime();
457 now.setTimeSpec(Qt::UTC);
458 // Don't print "user is away" messages more often than this
459 // 1 hour = 60 min * 60 sec
460 const int silenceTime = 60 * 60;
461 // Check if away state has NOT changed and silence time hasn't yet elapsed
462 if (!ircuser->hasAwayChanged() && ircuser->lastAwayMessageTime().addSecs(silenceTime) >= now) {
463 // Away message hasn't changed and we're still within the period of silence; don't
464 // repeat the message
467 ircuser->setLastAwayMessageTime(now);
468 // Mark any changes in away as acknowledged
469 ircuser->acknowledgeAwayChanged();
473 displayMsg(e, Message::Server, msg + tr("%1 is away: \"%2\"").arg(nick, awayMsg), QString(), target);
476 /* RPL_UNAWAY - ":You are no longer marked as being away" */
477 void EventStringifier::processIrcEvent305(IrcEvent* e)
479 displayMsg(e, Message::Server, tr("You are no longer marked as being away"));
482 /* RPL_NOWAWAY - ":You have been marked as being away" */
483 void EventStringifier::processIrcEvent306(IrcEvent* e)
485 if (!e->network()->autoAwayActive())
486 displayMsg(e, Message::Server, tr("You have been marked as being away"));
491 Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
493 "<nick> :<away message>"
495 Replies 352 and 315 paired are used to answer a WHO message.
498 Replies 314 and 369 are responses to a WHOWAS message.
502 /* RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
503 void EventStringifier::processIrcEvent311(IrcEvent* e)
507 const QString whoisUserString = tr("[Whois] %1 is %2 (%3)");
509 IrcUser* ircuser = e->network()->ircUser(e->params().at(0));
511 displayMsg(e, Message::Server, whoisUserString.arg(ircuser->nick(), ircuser->hostmask(), ircuser->realName()));
513 QString host = QString("%1!%2@%3").arg(e->params().at(0), e->params().at(1), e->params().at(2));
514 displayMsg(e, Message::Server, whoisUserString.arg(e->params().at(0), host, e->params().last()));
518 /* RPL_WHOISSERVER - "<nick> <server> :<server info>" */
519 void EventStringifier::processIrcEvent312(IrcEvent* e)
522 displayMsg(e, Message::Server, tr("[Whois] %1 is online via %2 (%3)").arg(e->params().at(0), e->params().at(1), e->params().last()));
524 displayMsg(e, Message::Server, tr("[Whowas] %1 was online via %2 (%3)").arg(e->params().at(0), e->params().at(1), e->params().last()));
527 /* RPL_WHOWASUSER - "<nick> <user> <host> * :<real name>" */
528 void EventStringifier::processIrcEvent314(IrcEvent* e)
530 if (!checkParamCount(e, 3))
533 displayMsg(e, Message::Server, tr("[Whowas] %1 was %2@%3 (%4)").arg(e->params()[0], e->params()[1], e->params()[2], e->params().last()));
536 /* RPL_ENDOFWHO: "<name> :End of WHO list" */
537 void EventStringifier::processIrcEvent315(IrcEvent* e)
539 QStringList p = e->params();
540 p.takeLast(); // should be "End of WHO list"
541 displayMsg(e, Message::Server, tr("[Who] End of /WHO list for %1").arg(p.join(" ")));
544 /* RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
545 (real life: "<nick> <integer> <integer> :seconds idle, signon time) */
546 void EventStringifier::processIrcEvent317(IrcEvent* e)
548 int idleSecs = e->params()[1].toInt();
550 if (e->params().count() > 3) {
551 // if we have more then 3 params we have the above mentioned "real life" situation
552 // Time in IRC protocol is defined as seconds. Convert from seconds instead.
553 // See https://doc.qt.io/qt-5/qdatetime.html#fromSecsSinceEpoch
554 #if QT_VERSION >= 0x050800
555 QDateTime loginTime = QDateTime::fromSecsSinceEpoch(e->params()[2].toLongLong()).toUTC();
557 // fromSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for now.
558 // See https://doc.qt.io/qt-5/qdatetime.html#fromMSecsSinceEpoch
559 QDateTime loginTime = QDateTime::fromMSecsSinceEpoch((qint64)(e->params()[2].toLongLong() * 1000)).toUTC();
563 tr("[Whois] %1 is logged in since %2").arg(e->params()[0], loginTime.toString("yyyy-MM-dd hh:mm:ss UTC")));
565 QDateTime idlingSince = e->timestamp().toLocalTime().addSecs(-idleSecs).toUTC();
568 tr("[Whois] %1 is idling for %2 (since %3)")
569 .arg(e->params()[0], secondsToString(idleSecs), idlingSince.toString("yyyy-MM-dd hh:mm:ss UTC")));
572 /* RPL_ENDOFWHOIS - "<nick> :End of WHOIS list" */
573 void EventStringifier::processIrcEvent318(IrcEvent* e)
576 displayMsg(e, Message::Server, tr("[Whois] End of /WHOIS list"));
579 /* RPL_WHOISCHANNELS - "<nick> :*( ( "@" / "+" ) <channel> " " )" */
580 void EventStringifier::processIrcEvent319(IrcEvent* e)
582 if (!checkParamCount(e, 2))
585 QString nick = e->params().first();
589 for (QString channel : e->params().last().split(" ")) {
590 if (channel.startsWith("@"))
591 op.append(channel.remove(0, 1));
592 else if (channel.startsWith("+"))
593 voice.append(channel.remove(0, 1));
595 user.append(channel);
598 displayMsg(e, Message::Server, tr("[Whois] %1 is a user on channels: %2").arg(nick, user.join(" ")));
599 if (!voice.isEmpty())
600 displayMsg(e, Message::Server, tr("[Whois] %1 has voice on channels: %2").arg(nick, voice.join(" ")));
602 displayMsg(e, Message::Server, tr("[Whois] %1 is an operator on channels: %2").arg(nick, op.join(" ")));
605 /* RPL_LIST - "<channel> <# visible> :<topic>" */
606 void EventStringifier::processIrcEvent322(IrcEvent* e)
609 quint32 userCount = 0;
612 switch (e->params().count()) {
614 topic = e->params()[2];
617 userCount = e->params()[1].toUInt();
620 channelName = e->params()[0];
625 displayMsg(e, Message::Server, tr("Channel %1 has %2 users. Topic is: \"%3\"").arg(channelName).arg(userCount).arg(topic));
628 /* RPL_LISTEND ":End of LIST" */
629 void EventStringifier::processIrcEvent323(IrcEvent* e)
631 displayMsg(e, Message::Server, tr("End of channel list"));
634 /* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
635 void EventStringifier::processIrcEvent324(IrcEvent* e)
637 processIrcEventMode(e);
640 /* RPL_??? - "<channel> <homepage> */
641 void EventStringifier::processIrcEvent328(IrcEvent* e)
643 if (!checkParamCount(e, 2))
646 QString channel = e->params()[0];
647 displayMsg(e, Message::Topic, tr("Homepage for %1 is %2").arg(channel, e->params()[1]), QString(), channel);
650 /* RPL_??? - "<channel> <creation time (unix)>" */
651 void EventStringifier::processIrcEvent329(IrcEvent* e)
653 if (!checkParamCount(e, 2))
656 QString channel = e->params()[0];
657 // Allow for 64-bit time
658 qint64 unixtime = e->params()[1].toLongLong();
660 qWarning() << Q_FUNC_INFO << "received invalid timestamp:" << e->params()[1];
663 // Time in IRC protocol is defined as seconds. Convert from seconds instead.
664 // See https://doc.qt.io/qt-5/qdatetime.html#fromSecsSinceEpoch
665 #if QT_VERSION >= 0x050800
666 QDateTime time = QDateTime::fromSecsSinceEpoch(unixtime).toUTC();
668 // fromSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for now.
669 // See https://doc.qt.io/qt-5/qdatetime.html#fromMSecsSinceEpoch
670 QDateTime time = QDateTime::fromMSecsSinceEpoch((qint64)(unixtime * 1000)).toUTC();
672 displayMsg(e, Message::Topic, tr("Channel %1 created on %2").arg(channel, time.toString("yyyy-MM-dd hh:mm:ss UTC")), QString(), channel);
675 /* RPL_WHOISACCOUNT: "<nick> <account> :is authed as */
676 void EventStringifier::processIrcEvent330(IrcEvent* e)
678 if (e->params().count() < 3)
681 // check for whois or whowas
683 displayMsg(e, Message::Server, tr("[Whois] %1 is authed as %2").arg(e->params()[0], e->params()[1]));
686 displayMsg(e, Message::Server, tr("[Whowas] %1 was authed as %2").arg(e->params()[0], e->params()[1]));
691 void EventStringifier::processIrcEvent331(IrcEvent* e)
693 QString channel = e->params().first();
694 displayMsg(e, Message::Topic, tr("No topic is set for %1.").arg(channel), QString(), channel);
698 void EventStringifier::processIrcEvent332(IrcEvent* e)
700 QString channel = e->params().first();
701 displayMsg(e, Message::Topic, tr("Topic for %1 is \"%2\"").arg(channel, e->params()[1]), QString(), channel);
704 /* Topic set by... */
705 void EventStringifier::processIrcEvent333(IrcEvent* e)
707 if (!checkParamCount(e, 3))
710 QString channel = e->params().first();
711 // Time in IRC protocol is defined as seconds. Convert from seconds instead.
712 // See https://doc.qt.io/qt-5/qdatetime.html#fromSecsSinceEpoch
713 #if QT_VERSION >= 0x050800
714 QDateTime topicSetTime = QDateTime::fromSecsSinceEpoch(e->params()[2].toLongLong()).toUTC();
716 // fromSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for now.
717 // See https://doc.qt.io/qt-5/qdatetime.html#fromMSecsSinceEpoch
718 QDateTime topicSetTime = QDateTime::fromMSecsSinceEpoch((qint64)(e->params()[2].toLongLong() * 1000)).toUTC();
722 tr("Topic set by %1 on %2").arg(e->params()[1], topicSetTime.toString("yyyy-MM-dd hh:mm:ss UTC")),
727 /* RPL_INVITING - "<nick> <channel>*/
728 void EventStringifier::processIrcEvent341(IrcEvent* e)
730 if (!checkParamCount(e, 2))
733 QString channel = e->params()[1];
734 displayMsg(e, Message::Server, tr("%1 has been invited to %2").arg(e->params().first(), channel), QString(), channel);
737 /* RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
738 ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
739 void EventStringifier::processIrcEvent352(IrcEvent* e)
741 displayMsg(e, Message::Server, tr("[Who] %1").arg(e->params().join(" ")));
744 /* RPL_WHOSPCRPL: "<yournick> <num> #<channel> ~<ident> <host> <servname> <nick>
745 ("H"/ "G") <account> :<realname>"
746 Could be anything else, though. User-specified fields.
747 See http://faerion.sourceforge.net/doc/irc/whox.var */
748 void EventStringifier::processIrcEvent354(IrcEvent* e)
750 displayMsg(e, Message::Server, tr("[WhoX] %1").arg(e->params().join(" ")));
753 /* RPL_ENDOFWHOWAS - "<nick> :End of WHOWAS" */
754 void EventStringifier::processIrcEvent369(IrcEvent* e)
756 displayMsg(e, Message::Server, tr("End of /WHOWAS"));
759 /* ERR_ERRONEUSNICKNAME */
760 void EventStringifier::processIrcEvent432(IrcEvent* e)
762 if (!checkParamCount(e, 1))
765 displayMsg(e, Message::Error, tr("Nick %1 contains illegal characters").arg(e->params()[0]));
768 /* ERR_NICKNAMEINUSE */
769 void EventStringifier::processIrcEvent433(IrcEvent* e)
771 if (!checkParamCount(e, 1))
774 displayMsg(e, Message::Error, tr("Nick already in use: %1").arg(e->params()[0]));
777 /* ERR_UNAVAILRESOURCE */
778 void EventStringifier::processIrcEvent437(IrcEvent* e)
780 if (!checkParamCount(e, 1))
783 displayMsg(e, Message::Error, tr("Nick/channel is temporarily unavailable: %1").arg(e->params()[0]));
789 void EventStringifier::processIrcEvent(IrcEvent *e) {
795 /*******************************/
796 /******** CTCP HANDLING ********/
797 /*******************************/
799 void EventStringifier::processCtcpEvent(CtcpEvent* e)
801 if (e->type() != EventManager::CtcpEvent)
804 // Only stringify outgoing CTCP messages this way
805 if (e->testFlag(EventManager::Self) &&
806 // Only stringify CTCP queries this way
807 e->ctcpType() == CtcpEvent::CtcpType::Query &&
808 // Always handle ACTIONs as if they were sent from network, to properly handle echo-message
809 e->ctcpCmd() != "ACTION") {
812 tr("sending CTCP-%1 request to %2").arg(e->ctcpCmd(), e->target()),
813 e->network()->myNick(),
815 Message::Flag::Self);
819 handle(e->ctcpCmd(), Q_ARG(CtcpEvent*, e));
822 void EventStringifier::defaultHandler(const QString& ctcpCmd, CtcpEvent* e)
825 if (e->ctcpType() == CtcpEvent::Query) {
827 if (e->reply().isNull()) // all known core-side handlers (except for ACTION) set a reply!
828 //: Optional "unknown" in "Received unknown CTCP-FOO request by bar"
829 unknown = tr("unknown") + ' ';
830 displayMsg(e, Message::Server, tr("Received %1CTCP-%2 request by %3").arg(unknown, e->ctcpCmd(), e->prefix()));
832 // Ignore echo messages for our own answers
833 if (!e->testFlag(EventManager::Self)) {
834 displayMsg(e, Message::Server,
835 tr("Received CTCP-%1 answer from %2: %3").arg(e->ctcpCmd(), nickFromMask(e->prefix()),e->param()));
840 void EventStringifier::handleCtcpAction(CtcpEvent* e)
842 Message::Flag msgFlags = Message::Flag::None;
843 if (e->testFlag(EventManager::Self)) {
844 // Mark the message as Self
845 msgFlags = Message::Self;
848 displayMsg(e, Message::Action, e->param(), e->prefix(), e->target(), msgFlags);
851 void EventStringifier::handleCtcpPing(CtcpEvent* e)
853 if (e->ctcpType() == CtcpEvent::Query)
854 defaultHandler(e->ctcpCmd(), e);
858 tr("Received CTCP-PING answer from %1 with %2 milliseconds round trip time")
859 .arg(nickFromMask(e->prefix()))
860 .arg(QDateTime::fromMSecsSinceEpoch(e->param().toULongLong()).msecsTo(e->timestamp())));