aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/irc/botircdiceparser.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2019-02-12 23:59:24 +0100
committerRenaud G <renaud@rolisteam.org>2019-02-12 23:59:24 +0100
commitf2051fb35b1ad49c4d940e6fbba2acc98b216e13 (patch)
tree03117f493191d35104ac37eba72e916d41c849f2 /irc/botircdiceparser.cpp
parent210a222b894caa3c8af38ccb6653db0fd8491f6e (diff)
downloadOneRoll-f2051fb35b1ad49c4d940e6fbba2acc98b216e13.tar.gz
OneRoll-f2051fb35b1ad49c4d940e6fbba2acc98b216e13.zip
clang format
Diffstat (limited to 'irc/botircdiceparser.cpp')
-rw-r--r--irc/botircdiceparser.cpp168
1 files changed, 77 insertions, 91 deletions
diff --git a/irc/botircdiceparser.cpp b/irc/botircdiceparser.cpp
index f1a61f5..44ac60a 100644
--- a/irc/botircdiceparser.cpp
+++ b/irc/botircdiceparser.cpp
@@ -1,45 +1,43 @@
/***************************************************************************
-* Copyright (C) 2014 by Renaud Guezennec *
-* http://www.rolisteam.org/contact *
-* *
-* This file is part of DiceParser *
-* *
-* DiceParser is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-* *
-* This program is distributed in the hope that it will be useful, *
-* but WITHOUT ANY WARRANTY; without even the implied warranty of *
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
-* GNU General Public License for more details. *
-* *
-* You should have received a copy of the GNU General Public License *
-* along with this program; if not, write to the *
-* Free Software Foundation, Inc., *
-* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
-***************************************************************************/
+ * Copyright (C) 2014 by Renaud Guezennec *
+ * http://www.rolisteam.org/contact *
+ * *
+ * This file is part of DiceParser *
+ * *
+ * DiceParser is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
#include "botircdiceparser.h"
-#include <math.h>
#include <QDebug>
#include <QString>
+#include <math.h>
-BotIrcDiceParser::BotIrcDiceParser(QObject *parent) :
- QObject(parent)
+BotIrcDiceParser::BotIrcDiceParser(QObject* parent) : QObject(parent)
{
-
// Create socket
- m_socket = new QTcpSocket(this);
+ m_socket= new QTcpSocket(this);
- m_parser = new DiceParser();
+ m_parser= new DiceParser();
// Connect signals and slots!
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readData()));
- connect(m_socket,SIGNAL(connected()),this,SLOT(authentificationProcess()));
- connect(m_socket,SIGNAL(disconnected()),this,SLOT(connectToServer()));
- connect(m_socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(errorOccurs(QAbstractSocket::SocketError)));
-
+ connect(m_socket, SIGNAL(connected()), this, SLOT(authentificationProcess()));
+ connect(m_socket, SIGNAL(disconnected()), this, SLOT(connectToServer()));
+ connect(
+ m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorOccurs(QAbstractSocket::SocketError)));
}
BotIrcDiceParser::~BotIrcDiceParser()
@@ -58,58 +56,50 @@ void BotIrcDiceParser::errorOccurs(QAbstractSocket::SocketError)
void BotIrcDiceParser::readData()
{
-
qDebug() << "Reply";
- QString readLine = m_socket->readLine();
+ QString readLine= m_socket->readLine();
if(readLine.startsWith("!"))
- readLine = readLine.remove(0,1);
-
+ readLine= readLine.remove(0, 1);
if(readLine.contains("!"))
{
-
// qDebug()<< "in /dice";
- QString dice=".*PRIVMSG.*!(.*)";
+ 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];
+ QString cmd= list[1];
if(!cmd.isEmpty())
{
-
- cmd = cmd.simplified();
- QString result = startDiceParsing(cmd,true);
+ 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 if(readLine.contains("PING :"))
{
- QString dice="PING :(.*)";
+ QString dice= "PING :(.*)";
QRegExp exp(dice);
exp.indexIn(readLine);
- QStringList list = exp.capturedTexts();
- if(list.size()==2)
+ QStringList list= exp.capturedTexts();
+ if(list.size() == 2)
{
- QString resp = "PONG :"+list[1];
+ QString resp= "PONG :" + list[1];
m_socket->write(resp.toLatin1());
}
@@ -123,10 +113,11 @@ void BotIrcDiceParser::readData()
setRegisterName();
}
// Add to ouput
- //ui->m_output->append(readLine.trimmed());
+ // ui->m_output->append(readLine.trimmed());
QMessageLogger().debug() << readLine.trimmed();
// Next data??
- if(m_socket->canReadLine()) readData();
+ if(m_socket->canReadLine())
+ readData();
}
void BotIrcDiceParser::setRegisterName()
{
@@ -140,21 +131,18 @@ void BotIrcDiceParser::disconnectFromServer()
m_socket->write("QUIT Good bye \r\n"); // Good bye is optional message
m_socket->flush();
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::joinChannel()
{
m_socket->write(QLatin1String("JOIN #RolisteamOfficial \r\n").data());
}
-QString BotIrcDiceParser::diceToText(QList<ExportedDiceResult>& diceList,bool highlight,bool homogeneous)
+QString BotIrcDiceParser::diceToText(QList<ExportedDiceResult>& diceList, bool highlight, bool homogeneous)
{
QStringList global;
for(auto dice : diceList)
@@ -163,39 +151,39 @@ QString BotIrcDiceParser::diceToText(QList<ExportedDiceResult>& diceList,bool hi
for(int face : dice.keys())
{
QStringList result;
- ListDiceResult diceResult = dice.value(face);
- //patternColor = patternColorarg();
- foreach (HighLightDice tmp, diceResult)
+ ListDiceResult diceResult= dice.value(face);
+ // patternColor = patternColorarg();
+ foreach(HighLightDice tmp, diceResult)
{
QStringList diceListStr;
QStringList diceListChildren;
- for(int i =0; i < tmp.getResult().size(); ++i)
+ for(int i= 0; i < tmp.getResult().size(); ++i)
{
- qint64 dievalue = tmp.getResult()[i];
+ qint64 dievalue= tmp.getResult()[i];
QString prefix("%1");
- if((tmp.isHighlighted())&&(highlight))
+ if((tmp.isHighlighted()) && (highlight))
{
- if(tmp.getColor().isEmpty()|| tmp.getColor()=="black")
+ if(tmp.getColor().isEmpty() || tmp.getColor() == "black")
{
- prefix = "%1";
+ prefix= "%1";
}
- if(tmp.getColor()=="white")
+ if(tmp.getColor() == "white")
{
- prefix = "%1";
+ prefix= "%1";
}
- if(tmp.getColor()=="blue")
+ if(tmp.getColor() == "blue")
{
- prefix = "%1";
+ prefix= "%1";
}
- if(tmp.getColor()=="red")
+ if(tmp.getColor() == "red")
{
- prefix = "%1";
+ prefix= "%1";
}
}
- if(i==0)
+ if(i == 0)
{
diceListStr << prefix.arg(QString::number(dievalue));
}
@@ -213,7 +201,7 @@ QString BotIrcDiceParser::diceToText(QList<ExportedDiceResult>& diceList,bool hi
// qDebug() << result << tmp.first << tmp.second;
}
- if(dice.keys().size()>1)
+ if(dice.keys().size() > 1)
{
resultGlobal << QString(" d%2:(%1)").arg(result.join(',')).arg(face);
}
@@ -227,63 +215,61 @@ QString BotIrcDiceParser::diceToText(QList<ExportedDiceResult>& diceList,bool hi
return global.join(' ');
}
-QString BotIrcDiceParser::startDiceParsing(QString& cmd,bool highlight)
+QString BotIrcDiceParser::startDiceParsing(QString& cmd, bool highlight)
{
QString result;
QTextStream out(&result);
if(m_parser->parseLine(cmd))
{
-
m_parser->start();
if(!m_parser->getErrorMap().isEmpty())
{
- out << "Error" << m_parser->humanReadableError()<< "\n";
+ out << "Error" << m_parser->humanReadableError() << "\n";
return QString();
}
QList<ExportedDiceResult> list;
- bool homogeneous = true;
- m_parser->getLastDiceResult(list,homogeneous);
- QString diceText = diceToText(list,highlight,homogeneous);
+ bool homogeneous= true;
+ m_parser->getLastDiceResult(list, homogeneous);
+ QString diceText= diceToText(list, highlight, homogeneous);
QString scalarText;
QString str;
if(m_parser->hasIntegerResultNotInFirst())
{
- auto values = m_parser->getLastIntegerResults();
+ auto values= m_parser->getLastIntegerResults();
QStringList strLst;
- for(auto val : values )
+ for(auto val : values)
{
strLst << QString::number(val);
}
- scalarText = QString("%1").arg(strLst.join(','));
+ scalarText= QString("%1").arg(strLst.join(','));
}
else if(!list.isEmpty())
{
- auto values = m_parser->getSumOfDiceResult();
+ auto values= m_parser->getSumOfDiceResult();
QStringList strLst;
- for(auto val : values )
+ for(auto val : values)
{
strLst << QString::number(val);
}
- scalarText = QString("%1").arg(strLst.join(','));
+ scalarText= QString("%1").arg(strLst.join(','));
}
if(highlight)
- str = QString("Result: %1, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(m_parser->getDiceCommand());
+ 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());
+ str= QString("Result: %1, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(m_parser->getDiceCommand());
if(m_parser->hasStringResult())
{
- str = m_parser->getStringResult().join(",");
+ str= m_parser->getStringResult().join(",");
}
out << str << "\n";
-
-
}
else
{
- out << m_parser->humanReadableError()<< "\n";;
+ out << m_parser->humanReadableError() << "\n";
+ ;
}
return result;