void Plugin::hookMessageWillCreated (LeechCraft::IHookProxy_ptr proxy, QObject*, QObject *entry, int, QString) { ICLEntry *other = qobject_cast<ICLEntry*> (entry); if (!other) { qWarning () << Q_FUNC_INFO << "unable to cast" << entry << "to ICLEntry"; return; } QString text = proxy->GetValue ("text").toString (); const int maxLines = XmlSettingsManager::Instance () .property ("LineCount").toInt (); if (text.split ('\n').size () < maxLines) return; QByteArray propName; switch (other->GetEntryType ()) { case ICLEntry::ETChat: propName = "EnableForNormalChats"; break; case ICLEntry::ETMUC: propName = "EnableForMUCChats"; break; case ICLEntry::ETPrivateChat: propName = "EnableForPrivateChats"; break; default: return; } if (!XmlSettingsManager::Instance ().property (propName).toBool ()) return; PasteDialog dia; dia.exec (); auto choice = dia.GetChoice (); switch (choice) { case PasteDialog::Cancel: proxy->CancelDefault (); case PasteDialog::No: return; case PasteDialog::Yes: { auto service = dia.GetCreator () (entry); service->Paste ({ Proxy_->GetNetworkAccessManager (), text, dia.GetHighlight () }); proxy->CancelDefault (); } } }
void Plugin::hookAcceptNavigationRequest (LeechCraft::IHookProxy_ptr proxy, QWebPage*, QWebFrame*, QNetworkRequest request, QWebPage::NavigationType) { if (!request.url ().path ().endsWith ("user.js", Qt::CaseInsensitive) || request.url ().scheme () == "file") return; UserScriptInstallerDialog installer (this, CoreProxy_->GetNetworkAccessManager (), request.url ()); switch (installer.exec ()) { case UserScriptInstallerDialog::Install: UserScripts_.append (UserScript (installer.TempScriptPath ())); UserScripts_.last ().Install (CoreProxy_->GetNetworkAccessManager ()); AddScriptToManager (UserScripts_.last ()); break; case UserScriptInstallerDialog::ShowSource: Proxy_->OpenInNewTab (QUrl::fromLocalFile (installer.TempScriptPath ())); break; case UserScriptInstallerDialog::Cancel: QFile::remove (installer.TempScriptPath ()); break; default: break; } proxy->CancelDefault (); }
void Plugin::hookMessageWillCreated (LeechCraft::IHookProxy_ptr proxy, QObject *chatTab, QObject *entry, int, QString) { ICLEntry *other = qobject_cast<ICLEntry*> (entry); if (!other) { qWarning () << Q_FUNC_INFO << "unable to cast" << entry << "to ICLEntry"; return; } QString text = proxy->GetValue ("text").toString (); const int maxLines = XmlSettingsManager::Instance () .property ("LineCount").toInt (); if (text.split ('\n').size () < maxLines) return; QByteArray propName; switch (other->GetEntryType ()) { case ICLEntry::ETChat: propName = "EnableForNormalChats"; break; case ICLEntry::ETMUC: propName = "EnableForMUCChats"; break; case ICLEntry::ETPrivateChat: propName = "EnableForPrivateChats"; break; default: return; } if (!XmlSettingsManager::Instance () .property (propName).toBool ()) return; const bool shouldConfirm = XmlSettingsManager::Instance () .property ("ConfirmPasting").toBool (); if (shouldConfirm && QMessageBox::question (qobject_cast<QWidget*> (chatTab), tr ("Confirm pasting"), tr ("This message is too long according to current " "settings. Would you like to paste it on a " "pastebin?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) return; Paste (text, entry); proxy->CancelDefault (); }
void FUA::hookUserAgentForUrlRequested (LeechCraft::IHookProxy_ptr proxy, const QUrl& url, const QWebPage*) { QString host = url.host (); for (int i = 0; i < Model_->rowCount (); ++i) { QStandardItem *item = Model_->item (i); QRegExp re (item->text (), Qt::CaseSensitive, QRegExp::Wildcard); if (re.exactMatch (host)) { proxy->CancelDefault (); proxy->SetReturnValue (Model_->item (i, 2)->text ()); return; } } }
void Plugin::hookGotMessage (LeechCraft::IHookProxy_ptr proxy, QObject *message) { if (!IsConfValid ()) return; if (OurMessages_.contains (message)) { OurMessages_.remove (message); proxy->CancelDefault (); return; } IMessage *msg = qobject_cast<IMessage*> (message); if (!msg) { qWarning () << Q_FUNC_INFO << message << "doesn't implement IMessage"; return; } if (msg->GetMessageType () != IMessage::MTChatMessage) return; QObject *entryObj = msg->OtherPart (); ICLEntry *entry = qobject_cast<ICLEntry*> (entryObj); if (IsEntryAllowed (entryObj)) return; if (!AskedEntries_.contains (entryObj)) { AskedEntries_ << entryObj; const QString& text = tr ("Please answer to the following " "question to verify you are not a bot and is welcome " "to communicate with me:\n%1") .arg (ConfWidget_->GetQuestion ()); QObject *msgObj = entry->CreateMessage (IMessage::MTChatMessage, QString (), text); OurMessages_ << msgObj; qobject_cast<IMessage*> (msgObj)->Send (); proxy->CancelDefault (); } else if (ConfWidget_->GetAnswers ().contains (msg->GetBody ().toLower ())) { AllowedEntries_ << entryObj; AskedEntries_.remove (entryObj); const QString& text = tr ("Nice, seems like you've answered " "correctly. Please write again now what you wanted " "to write."); QObject *msgObj = entry->CreateMessage (IMessage::MTChatMessage, QString (), text); OurMessages_ << msgObj; qobject_cast<IMessage*> (msgObj)->Send (); } else { const QString& text = tr ("Sorry, you are wrong. Try again."); QObject *msgObj = entry->CreateMessage (IMessage::MTChatMessage, QString (), text); OurMessages_ << msgObj; qobject_cast<IMessage*> (msgObj)->Send (); proxy->CancelDefault (); } }
void Plugin::hookMessageWillCreated (LeechCraft::IHookProxy_ptr proxy, QObject*, QObject *entry, int, QString) { ICLEntry *other = qobject_cast<ICLEntry*> (entry); if (!other) { qWarning () << Q_FUNC_INFO << "unable to cast" << entry << "to ICLEntry"; return; } QString text = proxy->GetValue ("text").toString (); const int maxLines = XmlSettingsManager::Instance () .property ("LineCount").toInt (); const int maxSymbols = XmlSettingsManager::Instance () .property ("SymbolCount").toInt (); if (text.size () < maxSymbols && text.count ('\n') + 1 < maxLines) return; QByteArray propName; switch (other->GetEntryType ()) { case ICLEntry::ETChat: propName = "EnableForNormalChats"; break; case ICLEntry::ETMUC: propName = "EnableForMUCChats"; break; case ICLEntry::ETPrivateChat: propName = "EnableForPrivateChats"; break; default: return; } if (!XmlSettingsManager::Instance ().property (propName).toBool ()) return; QSettings settings (QCoreApplication::organizationName (), QCoreApplication::applicationName () + "_Azoth_Autopaste"); settings.beginGroup ("SavedChoices"); settings.beginGroup (other->GetEntryID ()); auto guard = std::shared_ptr<void> (nullptr, [&settings] (void*) -> void { settings.endGroup (); settings.endGroup (); }); PasteDialog dia; dia.SetCreatorName (settings.value ("Service").toString ()); dia.SetHighlight (static_cast<Highlight> (settings.value ("Highlight").toInt ())); dia.exec (); switch (dia.GetChoice ()) { case PasteDialog::Cancel: proxy->CancelDefault (); case PasteDialog::No: return; case PasteDialog::Yes: { auto service = dia.GetCreator () (entry); service->Paste ({ Proxy_->GetNetworkAccessManager (), text, dia.GetHighlight () }); proxy->CancelDefault (); settings.setValue ("Service", dia.GetCreatorName ()); settings.setValue ("Highlight", static_cast<int> (dia.GetHighlight ())); } } }