diff options
| author | 2019-02-12 23:59:24 +0100 | |
|---|---|---|
| committer | 2019-02-12 23:59:24 +0100 | |
| commit | f2051fb35b1ad49c4d940e6fbba2acc98b216e13 (patch) | |
| tree | 03117f493191d35104ac37eba72e916d41c849f2 /irc | |
| parent | 210a222b894caa3c8af38ccb6653db0fd8491f6e (diff) | |
| download | OneRoll-f2051fb35b1ad49c4d940e6fbba2acc98b216e13.tar.gz OneRoll-f2051fb35b1ad49c4d940e6fbba2acc98b216e13.zip | |
clang format
Diffstat (limited to 'irc')
| -rw-r--r-- | irc/botircdiceparser.cpp | 168 | ||||
| -rw-r--r-- | irc/botircdiceparser.h | 59 | ||||
| -rw-r--r-- | irc/build/ui_mainwindow.h | 57 | ||||
| -rw-r--r-- | irc/main.cpp | 56 |
4 files changed, 164 insertions, 176 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; diff --git a/irc/botircdiceparser.h b/irc/botircdiceparser.h index 2d42cfc..848c200 100644 --- a/irc/botircdiceparser.h +++ b/irc/botircdiceparser.h @@ -1,24 +1,24 @@ /*************************************************************************** -* 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. * + ***************************************************************************/ #ifndef MAINWINDOW_H #define MAINWINDOW_H @@ -31,25 +31,26 @@ class BotIrcDiceParser : public QObject Q_OBJECT public: - explicit BotIrcDiceParser(QObject *parent = 0); + explicit BotIrcDiceParser(QObject* parent= 0); virtual ~BotIrcDiceParser(); QString diceToText(QList<ExportedDiceResult>& dice, bool highlight, bool homogeneous); - QString startDiceParsing(QString &cmd, bool highlight); + QString startDiceParsing(QString& cmd, bool highlight); public slots: void errorOccurs(QAbstractSocket::SocketError); void connectToServer(); + private: - //Ui::BotIrcDiceParser *ui; - QTcpSocket * m_socket; + // Ui::BotIrcDiceParser *ui; + QTcpSocket* m_socket; DiceParser* m_parser; private slots: - void readData(); - void disconnectFromServer(); - void authentificationProcess(); - void joinChannel(); - void setRegisterName(); + void readData(); + void disconnectFromServer(); + void authentificationProcess(); + void joinChannel(); + void setRegisterName(); }; #endif // MAINWINDOW_H diff --git a/irc/build/ui_mainwindow.h b/irc/build/ui_mainwindow.h index 6249743..ecca604 100644 --- a/irc/build/ui_mainwindow.h +++ b/irc/build/ui_mainwindow.h @@ -29,60 +29,59 @@ QT_BEGIN_NAMESPACE class Ui_BotIrcDiceParser { public: - QWidget *centralwidget; - QVBoxLayout *verticalLayout; - QHBoxLayout *horizontalLayout; - QPushButton *m_connectButton; - QPushButton *m_joinButton; - QSpacerItem *horizontalSpacer; - QPushButton *m_disconnectButton; - QTextEdit *m_output; - QMenuBar *menubar; - QStatusBar *statusbar; - - void setupUi(QBotIrcDiceParser *BotIrcDiceParser) + QWidget* centralwidget; + QVBoxLayout* verticalLayout; + QHBoxLayout* horizontalLayout; + QPushButton* m_connectButton; + QPushButton* m_joinButton; + QSpacerItem* horizontalSpacer; + QPushButton* m_disconnectButton; + QTextEdit* m_output; + QMenuBar* menubar; + QStatusBar* statusbar; + + void setupUi(QBotIrcDiceParser* BotIrcDiceParser) { - if (BotIrcDiceParser->objectName().isEmpty()) + if(BotIrcDiceParser->objectName().isEmpty()) BotIrcDiceParser->setObjectName(QStringLiteral("BotIrcDiceParser")); BotIrcDiceParser->resize(604, 458); - centralwidget = new QWidget(BotIrcDiceParser); + centralwidget= new QWidget(BotIrcDiceParser); centralwidget->setObjectName(QStringLiteral("centralwidget")); - verticalLayout = new QVBoxLayout(centralwidget); + verticalLayout= new QVBoxLayout(centralwidget); verticalLayout->setObjectName(QStringLiteral("verticalLayout")); verticalLayout->setContentsMargins(0, 0, 0, 0); - horizontalLayout = new QHBoxLayout(); + horizontalLayout= new QHBoxLayout(); horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); - m_connectButton = new QPushButton(centralwidget); + m_connectButton= new QPushButton(centralwidget); m_connectButton->setObjectName(QStringLiteral("m_connectButton")); horizontalLayout->addWidget(m_connectButton); - m_joinButton = new QPushButton(centralwidget); + m_joinButton= new QPushButton(centralwidget); m_joinButton->setObjectName(QStringLiteral("m_joinButton")); horizontalLayout->addWidget(m_joinButton); - horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + horizontalSpacer= new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout->addItem(horizontalSpacer); - m_disconnectButton = new QPushButton(centralwidget); + m_disconnectButton= new QPushButton(centralwidget); m_disconnectButton->setObjectName(QStringLiteral("m_disconnectButton")); horizontalLayout->addWidget(m_disconnectButton); - verticalLayout->addLayout(horizontalLayout); - m_output = new QTextEdit(centralwidget); + m_output= new QTextEdit(centralwidget); m_output->setObjectName(QStringLiteral("m_output")); verticalLayout->addWidget(m_output); - menubar = new QMenuBar(BotIrcDiceParser); + menubar= new QMenuBar(BotIrcDiceParser); menubar->setObjectName(QStringLiteral("menubar")); menubar->setGeometry(QRect(0, 0, 604, 25)); - statusbar = new QStatusBar(BotIrcDiceParser); + statusbar= new QStatusBar(BotIrcDiceParser); statusbar->setObjectName(QStringLiteral("statusbar")); retranslateUi(BotIrcDiceParser); @@ -90,18 +89,20 @@ public: QMetaObject::connectSlotsByName(BotIrcDiceParser); } // setupUi - void retranslateUi(QBotIrcDiceParser *BotIrcDiceParser) + void retranslateUi(QBotIrcDiceParser* BotIrcDiceParser) { BotIrcDiceParser->setWindowTitle(QApplication::translate("BotIrcDiceParser", "BotIrcDiceParser", 0)); m_connectButton->setText(QApplication::translate("BotIrcDiceParser", "Connect", 0)); m_joinButton->setText(QApplication::translate("BotIrcDiceParser", "join", 0)); m_disconnectButton->setText(QApplication::translate("BotIrcDiceParser", "Disconnect", 0)); } // retranslateUi - }; -namespace Ui { - class BotIrcDiceParser: public Ui_BotIrcDiceParser {}; +namespace Ui +{ + class BotIrcDiceParser : public Ui_BotIrcDiceParser + { + }; } // namespace Ui QT_END_NAMESPACE diff --git a/irc/main.cpp b/irc/main.cpp index 23c9dbf..5989a94 100644 --- a/irc/main.cpp +++ b/irc/main.cpp @@ -1,27 +1,27 @@ /*************************************************************************** -* 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 <QCoreApplication> #include "botircdiceparser.h" +#include <QCoreApplication> /** * @page Dice * The cli for DiceParser the new dice system from rolisteam. @@ -34,15 +34,14 @@ * - make install * @return */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { - QCoreApplication app(argc,argv); + QCoreApplication app(argc, argv); BotIrcDiceParser bot; bot.connectToServer(); - return app.exec(); + return app.exec(); } - /*QTextStream out(stdout, QIODevice::WriteOnly); @@ -82,9 +81,10 @@ int main(int argc, char *argv[]) QCommandLineOption color(QStringList() << "c"<< "color-off", "Disable color to highlight result"); QCommandLineOption version(QStringList() << "v"<< "version", "Show the version and quit."); QCommandLineOption reset(QStringList() << "reset-settings", "Erase the settings and use the default parameters"); - QCommandLineOption dotFile(QStringList() << "d"<<"dot-file", "Instead of rolling dice, generate the execution tree and write it in <dotfile>","dotfile"); - QCommandLineOption translation(QStringList() << "t"<<"translation", "path to the translation file: <translationfile>","translationfile"); - QCommandLineOption help(QStringList() << "h"<<"help", "Display this help"); + QCommandLineOption dotFile(QStringList() << "d"<<"dot-file", "Instead of rolling dice, generate the execution tree +and write it in <dotfile>","dotfile"); QCommandLineOption translation(QStringList() << "t"<<"translation", "path to the +translation file: <translationfile>","translationfile"); QCommandLineOption help(QStringList() << "h"<<"help", "Display +this help"); if(!optionParser.addOption(color)) { |