Skip to content

Commit

Permalink
major fix of broken vandal nw
Browse files Browse the repository at this point in the history
we weren't able to retrieve the message from other clients as libirc was
in fact considering Huggle's HAN message as CTCP (they are, sort of)
  • Loading branch information
benapetr committed Oct 14, 2017
1 parent d116587 commit dcf0a1b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 95 deletions.
2 changes: 1 addition & 1 deletion huggle/libs/libirc
2 changes: 1 addition & 1 deletion huggle/projectconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ bool ProjectConfiguration::ParseYAML(QString yaml_src, QString *reason, WikiSite
}
this->ReportSummary = HuggleParser::YAML2String("report-summary", yaml);
this->ReportAutoSummary = HuggleParser::YAML2String("report-auto-summary", yaml, "This user was automatically reported by Huggle due to reverted vandalism after four warnings, please verify their"\
" contributions carefully, it may be a false positive");
" contributions carefully, it may be a false positive");
this->SpeedyTemplates = Yaml_FetchSpeedyOptions(yaml);
// Parsing
this->TemplateAge = HuggleParser::YAML2Int("template-age", yaml, this->TemplateAge);
Expand Down
205 changes: 112 additions & 93 deletions huggle/vandalnw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ VandalNw::VandalNw(QWidget *parent) : QDockWidget(parent), ui(new Ui::VandalNw)
connect(this->Irc, SIGNAL(Event_MyInfo(libircclient::Parser*)), this, SLOT(OnIRCLoggedIn(libircclient::Parser*)));
connect(this->Irc, SIGNAL(Event_Part(libircclient::Parser*,libircclient::Channel*)), this, SLOT(OnIRCUserPart(libircclient::Parser*,libircclient::Channel*)));
connect(this->Irc, SIGNAL(Event_EndOfNames(libircclient::Parser*)), this, SLOT(OnIRCChannelNames(libircclient::Parser*)));
connect(this->Irc, SIGNAL(Event_CTCP(libircclient::Parser*,QString,QString)), this, SLOT(OnIRCChannelCTCP(libircclient::Parser*,QString,QString)));
this->Irc->SetDefaultUsername(Configuration::HuggleConfiguration->HuggleVersion);
this->Irc->SetDefaultIdent("huggle");
this->ui->tableWidget->setColumnCount(1);
Expand Down Expand Up @@ -409,6 +410,103 @@ void VandalNw::UpdateHeader()
}
}

void VandalNw::ProcessCommand(WikiSite *site, QString nick, QString message)
{
HAN::MessageType mt;
if (!nick.toLower().contains("bot"))
{
mt = HAN::MessageType_User;
} else
{
mt = HAN::MessageType_Bot;
}
QString Command = message.mid(2);
if (Command.contains(" "))
{
Command = Command.mid(0, Command.indexOf(" "));
QString revid = message.mid(message.indexOf(" ") + 1);
QString parameter = "";
if (revid.contains(" "))
{
parameter = revid.mid(revid.indexOf(" ") + 1);
revid = revid.mid(0, revid.indexOf(" "));
}
if (Command == "GOOD")
{
int RevID = revid.toInt();
WikiEdit *edit = MainWindow::HuggleMain->Queue1->GetWikiEditByRevID(RevID, site);
if (edit != nullptr)
{
this->ProcessGood(edit, nick);
} else
{
while (this->UnparsedGood.count() > Configuration::HuggleConfiguration->SystemConfig_CacheHAN)
{
this->UnparsedGood.removeAt(0);
}
this->UnparsedGood.append(HAN::GenericItem(site, RevID, nick));
}
}
if (Command == "ROLLBACK")
{
int RevID = revid.toInt();
WikiEdit *edit = MainWindow::HuggleMain->Queue1->GetWikiEditByRevID(RevID, site);
if (edit != nullptr)
{
this->ProcessRollback(edit, nick);
} else
{
while (this->UnparsedRoll.count() > Configuration::HuggleConfiguration->SystemConfig_CacheHAN)
{
this->UnparsedRoll.removeAt(0);
}
this->UnparsedRoll.append(HAN::GenericItem(site, RevID, nick));
}
}
if (Command == "SUSPICIOUS")
{
int RevID = revid.toInt();
WikiEdit *edit = MainWindow::HuggleMain->Queue1->GetWikiEditByRevID(RevID, site);
if (edit != nullptr)
{
this->ProcessSusp(edit, nick);
} else
{
while (this->UnparsedSusp.count() > Configuration::HuggleConfiguration->SystemConfig_CacheHAN)
{
this->UnparsedSusp.removeAt(0);
}
this->UnparsedSusp.append(HAN::GenericItem(site, RevID, nick));
}
}
if (Command == "SCORED")
{
revid_ht RevID = revid.toLongLong();
long Score = parameter.toLong();
if (Score != 0)
{
WikiEdit *edit = MainWindow::HuggleMain->Queue1->GetWikiEditByRevID(RevID, site);
if (edit != nullptr)
{
this->Insert("<font color=green>" + nick + " rescored edit <b>" + edit->Page->PageName + "</b> by <b>" + edit->User->Username +
"</b> (" + GenerateWikiDiffLink(revid, revid, edit->GetSite()) + ") by " + QString::number(Score) + "</font>", mt);
edit->Score += Score;
if (!edit->MetaLabels.contains("Bot score"))
edit->MetaLabels.insert("Bot score", QString::number(Score));
MainWindow::HuggleMain->Queue1->SortItemByEdit(edit);
} else
{
while (this->UnparsedScores.count() > Configuration::HuggleConfiguration->SystemConfig_CacheHAN)
{
this->UnparsedScores.removeAt(0);
}
this->UnparsedScores.append(HAN::RescoreItem(site, RevID, Score, nick));
}
}
}
}
}

void VandalNw::Insert(QString text, HAN::MessageType type)
{
if ((type == HAN::MessageType_Bot && !Configuration::HuggleConfiguration->UserConfig->HAN_DisplayBots) ||
Expand Down Expand Up @@ -579,101 +677,9 @@ void VandalNw::OnIRCChannelMessage(libircclient::Parser *px)
}

WikiSite *site = this->Ch2Site[channel];
HAN::MessageType mt;
if (!nick.toLower().contains("bot"))
{
mt = HAN::MessageType_User;
} else
{
mt = HAN::MessageType_Bot;
}
if (message.startsWith(this->Prefix))
{
QString Command = message.mid(2);
if (Command.contains(" "))
{
Command = Command.mid(0, Command.indexOf(" "));
QString revid = message.mid(message.indexOf(" ") + 1);
QString parameter = "";
if (revid.contains(" "))
{
parameter = revid.mid(revid.indexOf(" ") + 1);
revid = revid.mid(0, revid.indexOf(" "));
}
if (Command == "GOOD")
{
int RevID = revid.toInt();
WikiEdit *edit = MainWindow::HuggleMain->Queue1->GetWikiEditByRevID(RevID, site);
if (edit != nullptr)
{
this->ProcessGood(edit, nick);
} else
{
while (this->UnparsedGood.count() > Configuration::HuggleConfiguration->SystemConfig_CacheHAN)
{
this->UnparsedGood.removeAt(0);
}
this->UnparsedGood.append(HAN::GenericItem(site, RevID, nick));
}
}
if (Command == "ROLLBACK")
{
int RevID = revid.toInt();
WikiEdit *edit = MainWindow::HuggleMain->Queue1->GetWikiEditByRevID(RevID, site);
if (edit != nullptr)
{
this->ProcessRollback(edit, nick);
} else
{
while (this->UnparsedRoll.count() > Configuration::HuggleConfiguration->SystemConfig_CacheHAN)
{
this->UnparsedRoll.removeAt(0);
}
this->UnparsedRoll.append(HAN::GenericItem(site, RevID, nick));
}
}
if (Command == "SUSPICIOUS")
{
int RevID = revid.toInt();
WikiEdit *edit = MainWindow::HuggleMain->Queue1->GetWikiEditByRevID(RevID, site);
if (edit != nullptr)
{
this->ProcessSusp(edit, nick);
} else
{
while (this->UnparsedSusp.count() > Configuration::HuggleConfiguration->SystemConfig_CacheHAN)
{
this->UnparsedSusp.removeAt(0);
}
this->UnparsedSusp.append(HAN::GenericItem(site, RevID, nick));
}
}
if (Command == "SCORED")
{
revid_ht RevID = revid.toLongLong();
long Score = parameter.toLong();
if (Score != 0)
{
WikiEdit *edit = MainWindow::HuggleMain->Queue1->GetWikiEditByRevID(RevID, site);
if (edit != nullptr)
{
this->Insert("<font color=green>" + nick + " rescored edit <b>" + edit->Page->PageName + "</b> by <b>" + edit->User->Username +
"</b> (" + GenerateWikiDiffLink(revid, revid, edit->GetSite()) + ") by " + QString::number(Score) + "</font>", mt);
edit->Score += Score;
if (!edit->MetaLabels.contains("Bot score"))
edit->MetaLabels.insert("Bot score", QString::number(Score));
MainWindow::HuggleMain->Queue1->SortItemByEdit(edit);
} else
{
while (this->UnparsedScores.count() > Configuration::HuggleConfiguration->SystemConfig_CacheHAN)
{
this->UnparsedScores.removeAt(0);
}
this->UnparsedScores.append(HAN::RescoreItem(site, RevID, Score, nick));
}
}
}
}
this->ProcessCommand(site, nick, message);
} else
{
QString message_ = message;
Expand All @@ -691,6 +697,19 @@ void VandalNw::OnIRCChannelMessage(libircclient::Parser *px)
}
}

void VandalNw::OnIRCChannelCTCP(libircclient::Parser *px, QString command, QString parameters)
{
(void)command;
(void)parameters;
if (!this->Ch2Site.contains(px->GetParameterLine()))
{
Syslog::HuggleLogs->DebugLog("Ignoring message to channel " + px->GetParameterLine() + " as we don't know which site it belongs to");
return;
}
WikiSite *site = this->Ch2Site[px->GetParameterLine()];
this->ProcessCommand(site, px->GetSourceUserInfo()->GetNick(), px->GetText());
}

void VandalNw::OnIRCChannelQuit(libircclient::Parser *px, libircclient::Channel *channel)
{
this->UpdateHeader();
Expand Down
2 changes: 2 additions & 0 deletions huggle/vandalnw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ namespace Huggle
void ProcessRollback(WikiEdit *edit, QString user);
void ProcessSusp(WikiEdit *edit, QString user);
void UpdateHeader();
void ProcessCommand(WikiSite *site, QString nick, QString message);
Ui::VandalNw *ui;
//! This is to track the changes to user list so that we don't need to update text in header
//! when there is no change (that is actually CPU expensive operation)
Expand All @@ -158,6 +159,7 @@ namespace Huggle
void OnIRCUserPart(libircclient::Parser *px, libircclient::Channel *channel);
void OnIRCSelfPart(libircclient::Parser *px, libircclient::Channel *channel);
void OnIRCChannelMessage(libircclient::Parser *px);
void OnIRCChannelCTCP(libircclient::Parser *px, QString command, QString parameters);
void OnIRCChannelQuit(libircclient::Parser *px, libircclient::Channel *channel);
void OnIRCLoggedIn(libircclient::Parser *px);
void OnConnected();
Expand Down

0 comments on commit dcf0a1b

Please sign in to comment.