diff options
| author | 2017-10-21 18:55:16 +0200 | |
|---|---|---|
| committer | 2017-10-21 18:55:16 +0200 | |
| commit | 17c8a3738b8367cef726fa4bbbd23671b1270559 (patch) | |
| tree | a9a8c464b7fdf3ac82ec66144b98d3c169411177 /irc | |
| parent | ca574161aac7f5e49fb239e20b0d2c1d3dfd148d (diff) | |
| download | OneRoll-17c8a3738b8367cef726fa4bbbd23671b1270559.tar.gz OneRoll-17c8a3738b8367cef726fa4bbbd23671b1270559.zip | |
-update way to use display result given new API.
Diffstat (limited to 'irc')
| -rw-r--r-- | irc/botircdiceparser.cpp | 227 | ||||
| -rw-r--r-- | irc/botircdiceparser.h | 2 |
2 files changed, 123 insertions, 106 deletions
diff --git a/irc/botircdiceparser.cpp b/irc/botircdiceparser.cpp index eb2e3c1..44a3224 100644 --- a/irc/botircdiceparser.cpp +++ b/irc/botircdiceparser.cpp @@ -44,7 +44,7 @@ BotIrcDiceParser::BotIrcDiceParser(QObject *parent) : BotIrcDiceParser::~BotIrcDiceParser() { - // delete ui; + // delete ui; } void BotIrcDiceParser::connectToServer() { @@ -53,7 +53,7 @@ void BotIrcDiceParser::connectToServer() } void BotIrcDiceParser::errorOccurs(QAbstractSocket::SocketError) { - qDebug() << "ERROR" << m_socket->errorString(); + qDebug() << "ERROR" << m_socket->errorString(); } void BotIrcDiceParser::readData() @@ -63,42 +63,42 @@ void BotIrcDiceParser::readData() QString readLine = m_socket->readLine(); if(readLine.startsWith("!")) - readLine = readLine.remove(0,1); + readLine = readLine.remove(0,1); if(readLine.contains("!")) { - // qDebug()<< "in /dice"; + // qDebug()<< "in /dice"; QString dice=".*PRIVMSG.*!(.*)"; QRegExp exp(dice); exp.indexIn(readLine); - QStringList list = exp.capturedTexts(); - qDebug()<<list; - if(list.size()==2) + QStringList list = exp.capturedTexts(); + qDebug()<<list; + if(list.size()==2) + { + QString cmd = list[1]; + if(!cmd.isEmpty()) { - QString cmd = list[1]; - if(!cmd.isEmpty()) - { - cmd = cmd.simplified(); - QString result = startDiceParsing(cmd,true); - if(!result.isEmpty()) - { - QString msg("PRIVMSG #RolisteamOfficial :%1 \r\n"); - m_socket->write(msg.arg(result).toLatin1()); - } + cmd = cmd.simplified(); + QString result = startDiceParsing(cmd,true); + if(!result.isEmpty()) + { + QString msg("PRIVMSG #RolisteamOfficial :%1 \r\n"); + m_socket->write(msg.arg(result).toLatin1()); } - - } - else - { - return; } -// + + } + else + { + return; + } + // } else if(readLine.contains("PING :")) @@ -142,85 +142,89 @@ void BotIrcDiceParser::disconnectFromServer() m_socket->disconnect(); // Now we can try it :-) } - void BotIrcDiceParser::authentificationProcess() - { - qDebug() << "authentification"; - m_socket->write(QLatin1String("NICK rolisteamDice \r\n").data()); - m_socket->write(QLatin1String("USER rolisteamDice rolisteamDice rolisteamDice :rolisteamDice BOT \r\n").data()); +void BotIrcDiceParser::authentificationProcess() +{ + qDebug() << "authentification"; + m_socket->write(QLatin1String("NICK rolisteamDice \r\n").data()); + m_socket->write(QLatin1String("USER rolisteamDice rolisteamDice rolisteamDice :rolisteamDice BOT \r\n").data()); - } +} void BotIrcDiceParser::joinChannel() { m_socket->write(QLatin1String("JOIN #RolisteamOfficial \r\n").data()); } -QString BotIrcDiceParser::diceToText(ExportedDiceResult& dice,bool highlight,bool homogeneous) +QString BotIrcDiceParser::diceToText(QList<ExportedDiceResult>& diceList,bool highlight,bool homogeneous) { - QStringList resultGlobal; - foreach(int face, dice.keys()) + QStringList global; + for(auto dice : diceList) + { + QStringList resultGlobal; + for(int face : dice.keys()) { - QStringList result; - ListDiceResult diceResult = dice.value(face); - //patternColor = patternColorarg(); - foreach (HighLightDice tmp, diceResult) - { - QStringList diceListStr; - QStringList diceListChildren; + QStringList result; + ListDiceResult diceResult = dice.value(face); + //patternColor = patternColorarg(); + foreach (HighLightDice tmp, diceResult) + { + QStringList diceListStr; + QStringList diceListChildren; + for(int i =0; i < tmp.getResult().size(); ++i) + { + qint64 dievalue = tmp.getResult()[i]; + QString prefix("%1"); - for(int i =0; i < tmp.getResult().size(); ++i) + if((tmp.isHighlighted())&&(highlight)) { - qint64 dievalue = tmp.getResult()[i]; - QString prefix("%1"); - - if((tmp.isHighlighted())&&(highlight)) + if(tmp.getColor().isEmpty()|| tmp.getColor()=="black") { - if(tmp.getColor().isEmpty()|| tmp.getColor()=="black") - { - prefix = "%1"; - } - if(tmp.getColor()=="white") - { - prefix = "%1"; - } - if(tmp.getColor()=="blue") - { - prefix = "%1"; - } - if(tmp.getColor()=="red") - { - prefix = "%1"; - } + prefix = "%1"; } - - if(i==0) + if(tmp.getColor()=="white") + { + prefix = "%1"; + } + if(tmp.getColor()=="blue") { - diceListStr << prefix.arg(QString::number(dievalue)); + prefix = "%1"; } - else + if(tmp.getColor()=="red") { - diceListChildren << prefix.arg(QString::number(dievalue)); + prefix = "%1"; } } - if(!diceListChildren.isEmpty()) + + if(i==0) + { + diceListStr << prefix.arg(QString::number(dievalue)); + } + else { - diceListStr << QString("[%1]").arg(diceListChildren.join(' ')); + diceListChildren << prefix.arg(QString::number(dievalue)); } + } + if(!diceListChildren.isEmpty()) + { + diceListStr << QString("[%1]").arg(diceListChildren.join(' ')); + } - result << diceListStr.join(' '); - // qDebug() << result << tmp.first << tmp.second; - } - - if(dice.keys().size()>1) - { - resultGlobal << QString(" d%2:(%1)").arg(result.join(',')).arg(face); - } - else - { - resultGlobal << result; - } + result << diceListStr.join(' '); + // qDebug() << result << tmp.first << tmp.second; + } + + if(dice.keys().size()>1) + { + resultGlobal << QString(" d%2:(%1)").arg(result.join(',')).arg(face); + } + else + { + resultGlobal << result; + } } - return resultGlobal.join(' '); + global << resultGlobal.join(' '); + } + return global.join(' '); } QString BotIrcDiceParser::startDiceParsing(QString& cmd,bool highlight) @@ -230,38 +234,51 @@ QString BotIrcDiceParser::startDiceParsing(QString& cmd,bool highlight) if(m_parser->parseLine(cmd)) { - m_parser->Start(); - if(!m_parser->getErrorMap().isEmpty()) - { - out << "Error" << m_parser->humanReadableError()<< "\n"; - return QString(); - } + m_parser->Start(); + if(!m_parser->getErrorMap().isEmpty()) + { + out << "Error" << m_parser->humanReadableError()<< "\n"; + return QString(); + } - ExportedDiceResult list; - bool homogeneous = true; - m_parser->getLastDiceResult(list,homogeneous); - QString diceText = diceToText(list,highlight,homogeneous); - QString scalarText; - QString str; + QList<ExportedDiceResult> list; + bool homogeneous = true; + m_parser->getLastDiceResult(list,homogeneous); + QString diceText = diceToText(list,highlight,homogeneous); + QString scalarText; + QString str; - if(m_parser->hasIntegerResultNotInFirst()) + if(m_parser->hasIntegerResultNotInFirst()) + { + auto values = m_parser->getLastIntegerResults(); + QStringList strLst; + for(auto val : values ) { - scalarText = QString("%1").arg(m_parser->getLastIntegerResult()); + strLst << QString::number(val); } - else if(!list.isEmpty()) + scalarText = QString("%1").arg(strLst.join(',')); + } + else if(!list.isEmpty()) + { + auto values = m_parser->getSumOfDiceResult(); + QStringList strLst; + for(auto val : values ) { - scalarText = QString("%1").arg(m_parser->getSumOfDiceResult()); + strLst << QString::number(val); } - if(highlight) - str = QString("Result: %1, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(m_parser->getDiceCommand()); - else - str = QString("Result: %1, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(m_parser->getDiceCommand()); + scalarText = QString("%1").arg(strLst.join(',')); + } + if(highlight) + str = QString("Result: %1, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(m_parser->getDiceCommand()); + else + str = QString("Result: %1, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(m_parser->getDiceCommand()); + + if(m_parser->hasStringResult()) + { + str = m_parser->getStringResult().join(","); + } + out << str << "\n"; - if(m_parser->hasStringResult()) - { - str = m_parser->getStringResult(); - } - out << str << "\n"; } else diff --git a/irc/botircdiceparser.h b/irc/botircdiceparser.h index 5933b12..2d42cfc 100644 --- a/irc/botircdiceparser.h +++ b/irc/botircdiceparser.h @@ -34,7 +34,7 @@ public: explicit BotIrcDiceParser(QObject *parent = 0); virtual ~BotIrcDiceParser(); - QString diceToText(ExportedDiceResult &dice, bool highlight, bool homogeneous); + QString diceToText(QList<ExportedDiceResult>& dice, bool highlight, bool homogeneous); QString startDiceParsing(QString &cmd, bool highlight); public slots: void errorOccurs(QAbstractSocket::SocketError); |