main.cpp 3.5 KB

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