11 #include "hugglefeedproviderirc.hpp"
13 using namespace Huggle;
15 HuggleFeedProviderIRC::HuggleFeedProviderIRC()
18 this->Connected =
false;
19 this->TcpSocket = NULL;
23 HuggleFeedProviderIRC::~HuggleFeedProviderIRC()
25 while (Buffer.count() > 0)
27 Buffer.at(0)->UnregisterConsumer(HUGGLECONSUMER_PROVIDERIRC);
39 Core::DebugLog(
"Attempted to start connection which was already started");
43 qsrand(QTime::currentTime().msec());
45 if (!TcpSocket->waitForConnected())
54 Core::Log(
"IRC: Successfuly connected to irc rc feed");
56 + QString::number(qrand()) +
" 8 * :"
62 if (this->thread != NULL)
67 this->thread->p =
this;
68 this->thread->start();
69 this->Connected =
true;
75 return this->Connected;
84 if (this->TcpSocket == NULL)
86 throw new Exception(
"The pointer to TcpSocket was NULL during Stop() of irc provider");
88 this->thread->Running =
false;
89 this->TcpSocket->close();
90 delete this->TcpSocket;
91 this->TcpSocket = NULL;
92 if (this->thread == NULL)
94 throw new Exception(
"The pointer to thread was NULL during Stop() of irc provider");
96 this->thread->Running =
false;
97 this->Connected =
false;
100 Core::Log(
"Waiting for irc feed provider to stop");
101 Sleeper::usleep(200000);
103 this->Connected =
false;
106 void HuggleFeedProviderIRC::InsertEdit(
WikiEdit *edit)
110 throw new Exception(
"WikiEdit *edit must not be NULL",
"void HuggleFeedProviderIRC::InsertEdit(WikiEdit *edit)");
114 if (
Core::Main->Queue1->CurrentFilter->Matches(edit))
121 this->Buffer.at(0)->UnregisterConsumer(HUGGLECONSUMER_PROVIDERIRC);
122 this->Buffer.removeAt(0);
124 Core::Log(
"WARNING: insufficient space in irc cache, increase ProviderCache size, otherwise you will be loosing edits");
126 this->Buffer.append(edit);
134 void HuggleFeedProviderIRC::ParseEdit(QString line)
142 if (!line.contains(
" PRIVMSG "))
147 line = line.mid(line.indexOf(
" PRIVMSG ") + 9);
149 if (!line.contains(
":"))
155 line = line.mid(line.indexOf(
":") + 1);
157 if (!line.contains(QString(QChar(003)) +
"07"))
163 line = line.mid(line.indexOf(QString(QChar(003)) +
"07") + 3);
165 if (!line.contains(QString(QChar(003)) +
"14"))
172 edit->
Page =
new WikiPage(line.mid(0, line.indexOf(QString(QChar(003)) +
"14")));
176 if (!line.contains(QString(QChar(003)) +
"4 "))
183 line = line.mid(line.indexOf(QString(QChar(003)) +
"4 ") + 2);
184 QString flags = line.mid(0, line.indexOf(QChar(003)));
185 edit->
Bot = flags.contains(
"B");
186 edit->
NewPage = flags.contains(
"N");
187 edit->
Minor = flags.contains(
"M");
191 if (flags.contains(
"patrol"))
197 if (flags.contains(
"modify"))
203 if (flags.contains(
"reviewed"))
209 if (flags.contains(
"block"))
215 if (flags.contains(
"protect"))
221 if (flags.contains(
"reblock"))
227 if (flags.contains(
"unhelpful"))
233 if (flags.contains(
"helpful"))
239 if (flags.contains(
"approve"))
245 if (flags.contains(
"resolve"))
251 if (flags.contains(
"upload"))
257 if (flags.contains(
"feature"))
263 if (flags.contains(
"noaction"))
269 if (flags.contains(
"selfadd"))
275 if (flags.contains(
"overwrite"))
281 if (flags.contains(
"hit"))
288 if (flags.contains(
"create"))
294 if (flags.contains(
"delete"))
300 if (flags.contains(
"move"))
308 if (!line.contains(
"?diff="))
310 Core::DebugLog(
"Invalid line (flags: " + flags +
") (no diff):" + line);
315 line = line.mid(line.indexOf(
"?diff=") + 6);
317 if (!line.contains(
"&"))
324 edit->
Diff = line.mid(0, line.indexOf(
"&")).toInt();
325 edit->
RevID = line.mid(0, line.indexOf(
"&")).toInt();
328 if (!line.contains(
"oldid="))
335 line = line.mid(line.indexOf(
"oldid=") + 6);
337 if (!line.contains(QString(QChar(003))))
344 edit->
OldID = line.mid(0, line.indexOf(QString(QChar(003)))).toInt();
346 if (!line.contains(QString(QChar(003)) +
"03"))
353 line = line.mid(line.indexOf(QString(QChar(003)) +
"03") + 3);
355 if (!line.contains(QString(QChar(3))))
362 QString name = line.mid(0, line.indexOf(QString(QChar(3))));
372 if (line.contains(QString(QChar(3)) +
" ("))
374 line = line.mid(line.indexOf(QString(QChar(3)) +
" (") + 3);
375 if (line.contains(
")"))
377 QString xx = line.mid(0, line.indexOf(
")"));
379 if (xx.startsWith(
"+"))
384 }
else if (xx.startsWith(
"-"))
387 size = xx.toInt() * -1;
393 if (line.contains(QString(QChar(3)) +
"10"))
395 line = line.mid(line.indexOf(QString(QChar(3)) +
"10"));
396 if (line.contains(QString(QChar(3))))
398 edit->
Summary = line.mid(0, line.indexOf(QString(QChar(3))));
402 this->InsertEdit(edit);
411 if (this->thread != NULL)
413 if (this->thread->Running || !this->thread->IsFinished())
423 return (this->Buffer.size() != 0);
426 void HuggleFeedProviderIRC_t::run()
430 this->Stopped =
true;
431 throw new Exception(
"Pointer to parent IRC feed is NULL");
434 while (this->Running && this->s->isOpen())
441 QString text = QString::fromUtf8(this->s->readLine());
444 QThread::currentThread()->usleep(2000000);
450 QThread::usleep(200000);
453 Core::Log(
"IRC: Closed connection to irc feed");
456 p->Connected =
false;
458 this->Stopped =
true;
461 HuggleFeedProviderIRC_t::HuggleFeedProviderIRC_t(QTcpSocket *socket)
464 this->Stopped =
false;
469 HuggleFeedProviderIRC_t::~HuggleFeedProviderIRC_t()
474 bool HuggleFeedProviderIRC_t::IsFinished()
482 if (this->Buffer.size() == 0)
486 WikiEdit *edit = this->Buffer.at(0);
487 this->Buffer.removeAt(0);
494 bool HuggleFeedProviderIRC::IsConnected()
bool IsWorking()
Return true if this feed is operational or not.
static void Log(QString Message)
Write text to terminal as well as ring log.
bool NewPage
Edit is a new page.
bool IsStopped()
Returns true in case that a provider is stopped and can be safely deleted.
void Stop()
Stop the feed engine.
static QString UserName
User name.
bool Start()
Start the feed engine.
Thread which process the IRC feed.
static void PostProcessEdit(WikiEdit *_e)
void UnregisterConsumer(const int consumer)
This function will remove a string which prevent the object from being removed.
void RegisterConsumer(const int consumer)
Registers a consumer.
bool ContainsEdit()
Check if feed is containing some edits in buffer.
static double EditCounter
Number of edits made since you logged in.
static QString IRCIdent
Ident.
static QString IRCServer
Server.
QString Summary
Summary of edit.
static void PreProcessEdit(WikiEdit *_e)
static int ProviderCache
Size of feed.
WikiEdit * RetrieveEdit()
Return a last edit from cache or NULL.
static QString IRCNick
Nick.
Every exception raised by huggle is defined by this class.
bool Minor
Edit is a minor edit.
static quint16 IRCPort
Port.
static WikiSite Project
currently selected project
WikiUser * User
User who changed the page.
static void DebugLog(QString Message, unsigned int Verbosity=1)
This log is only shown if verbosity is same or larger than requested verbosity.
int Size
Size of change of edit.
static MainWindow * Main
Pointer to main.
bool Bot
Edit is a bot edit.
WikiPage * Page
Page that was changed by edit.