Toast/TriviaBot/bot/TriviaBot.cpp

58 lines
1.4 KiB
C++
Raw Normal View History

#include <curl/curl.h>
2016-08-03 22:04:05 +01:00
#include <include/libplatform/libplatform.h>
#include <include/v8.h>
#include "ClientConnection.hpp"
2016-08-04 17:39:48 +01:00
#include "Logger.hpp"
std::string bot_token;
int main(int argc, char *argv[]) {
curl_global_init(CURL_GLOBAL_DEFAULT);
2016-08-03 22:04:05 +01:00
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::V8::InitializeExternalStartupData(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
v8::V8::Initialize();
2016-08-04 17:39:48 +01:00
Logger::write("Initialised V8 and curl", Logger::LogLevel::Debug);
if (argc == 2) {
bot_token = argv[1];
}
else {
std::cout << "Please enter your bot token: " << std::endl;
std::cin >> bot_token;
}
// todo: get this using API
std::string uri = "wss://gateway.discord.gg/?v=5&encoding=json";
try {
ClientConnection conn;
conn.start(uri);
}
2016-08-04 17:39:48 +01:00
catch (const std::exception &e) {
Logger::write("std exception: " + std::string(e.what()), Logger::LogLevel::Severe);
}
catch (websocketpp::lib::error_code e) {
Logger::write("websocketpp exception: " + e.message(), Logger::LogLevel::Severe);
}
catch (...) {
Logger::write("other exception.", Logger::LogLevel::Severe);
}
2016-08-03 22:04:05 +01:00
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform;
curl_global_cleanup();
2016-08-04 17:39:48 +01:00
Logger::write("Cleaned up", Logger::LogLevel::Info);
std::cout << "Press enter to exit" << std::endl;
std::getchar();
return 0;
}