main.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "applicationdata.h"
  2. #include "ircclientstarter.h"
  3. #include "ircclient.h"
  4. #include "httpserver.h"
  5. #include "global.h"
  6. #include "version.h"
  7. #include <QThread>
  8. #include <QCoreApplication>
  9. #include <QDebug>
  10. int main(int argc, char *argv[])
  11. {
  12. if (argc < 2) {
  13. qInfo().noquote() << "No parameters passed. Use -h or --help for usage information.";
  14. return 1;
  15. }
  16. QCoreApplication a(argc, argv);
  17. QString configFile;
  18. for (int i = 1; i < argc; i++) {
  19. QString param(argv[i]);
  20. if ((param == "--example" or param == "-e") and i+1 < argc) {
  21. ApplicationData::createConfigExample (QString{argv[i+1]});
  22. return 0;
  23. }
  24. else if (param == "--help" or param == "-h") {
  25. qInfo().noquote() << "Usage: Pass the configuration file via --config and let's go!\n"
  26. "Possible arguments:\n"
  27. "-e --example <output file> - create example config file\n"
  28. "-c --config <input file> - path to configuration file\n"
  29. "-v --version - print version";
  30. return 0;
  31. }
  32. else if ((param == "--config" or param == "-c") and i+1 < argc) {
  33. configFile = QString{argv[i+1]};
  34. }
  35. else if ((param == "--version" or param == "-v")) {
  36. qInfo().noquote() << "IRCaBot" << IRCABOT_VERSION;
  37. return 0;
  38. }
  39. }
  40. if (configFile.isEmpty()) {
  41. qInfo().noquote() << "Configuration file not passed. Use -h or --help for usage information.";
  42. return 1;
  43. }
  44. qInfo().noquote() <<
  45. " /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$ \n"
  46. "|_ $$_/| $$__ $$ /$$__ $$ | $$__ $$ | $$ \n"
  47. " | $$ | $$ \\ $$| $$ \\__/ /$$$$$$ | $$ \\ $$ /$$$$$$ /$$$$$$ \n"
  48. " | $$ | $$$$$$$/| $$ |____ $$| $$$$$$$ /$$__ $$|_ $$_/ \n"
  49. " | $$ | $$__ $$| $$ /$$$$$$$| $$__ $$| $$ \\ $$ | $$ \n"
  50. " | $$ | $$ \\ $$| $$ $$ /$$__ $$| $$ \\ $$| $$ | $$ | $$ /$$\n"
  51. " /$$$$$$| $$ | $$| $$$$$$/| $$$$$$$| $$$$$$$/| $$$$$$/ | $$$$/\n"
  52. "|______/|__/ |__/ \\______/ \\_______/|_______/ \\______/ \\___/";
  53. qInfo().noquote() << "IRCaBot" << IRCABOT_VERSION << "| Source code: https://notabug.org/acetone/ircabot";
  54. qInfo().noquote() << "GPLv3 (c) acetone," << COPYRIGHT_YEAR << "\n";
  55. ApplicationData configuration(configFile);
  56. auto webInterfaceAddress = configuration.getWebInterfaceAddress();
  57. HttpServer webInterface(webInterfaceAddress.first,
  58. webInterfaceAddress.second,
  59. configuration.getLogFolder(),
  60. configuration.getMainChannel(),
  61. configuration.getAjaxIsDisabled());
  62. auto serversData = configuration.getConnections();
  63. for (auto server: serversData) {
  64. if (not server.isOk()) continue;
  65. IrcClientStarter* wrapper = new IrcClientStarter(server, &webInterface);
  66. QThread* thread = new QThread;
  67. wrapper->moveToThread(thread);
  68. QObject::connect (thread, SIGNAL(started()), wrapper, SLOT(RunInit()));
  69. thread->start();
  70. }
  71. return a.exec();
  72. }