Squash some bugs and fix some warnings. Update CMakeLists
This commit is contained in:
parent
7739404646
commit
8ebe6c2c4e
@ -7,6 +7,8 @@ project(TriviaBot)
|
|||||||
|
|
||||||
file(GLOB_RECURSE sources bot/*.cpp bot/*.hpp ../lib/sqlite3/sqlite3.c)
|
file(GLOB_RECURSE sources bot/*.cpp bot/*.hpp ../lib/sqlite3/sqlite3.c)
|
||||||
|
|
||||||
|
link_directories(../lib/v8/lib)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
## target definitions #########################################################
|
## target definitions #########################################################
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -29,8 +31,14 @@ target_link_libraries(TriviaBot PUBLIC
|
|||||||
${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
${OPENSSL_LIBRARIES}
|
${OPENSSL_LIBRARIES}
|
||||||
${CURL_LIBRARIES}
|
${CURL_LIBRARIES}
|
||||||
pthread
|
v8
|
||||||
|
v8_libplatform
|
||||||
|
v8_libbase
|
||||||
|
icui18n
|
||||||
|
icuuc
|
||||||
|
rt
|
||||||
dl
|
dl
|
||||||
|
pthread
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
@ -39,6 +47,7 @@ include_directories(
|
|||||||
${CURL_INCLUDE_DIR}
|
${CURL_INCLUDE_DIR}
|
||||||
../lib/websocketpp
|
../lib/websocketpp
|
||||||
../lib/sqlite3
|
../lib/sqlite3
|
||||||
|
../lib/v8
|
||||||
)
|
)
|
||||||
|
|
||||||
# don't know if necessary, too scared to remove
|
# don't know if necessary, too scared to remove
|
||||||
|
64
TriviaBot/bot/TriviaBot.cpp.save
Normal file
64
TriviaBot/bot/TriviaBot.cpp.save
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include <curl/curl.h>
|
||||||
|
#include <include/libplatform/libplatform.>
|
||||||
|
#include <include/v8.h>
|
||||||
|
|
||||||
|
#include "ClientConnection.hpp"
|
||||||
|
#include "Logger.hpp"
|
||||||
|
#include "DiscordAPI.hpp"
|
||||||
|
|
||||||
|
std::string bot_token;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
|
|
||||||
|
v8::V8::InitializeICUDefaultLocation(argv[0]);
|
||||||
|
v8::V8::InitializeExternalStartupData(argv[0]);
|
||||||
|
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
|
||||||
|
v8::V8::InitializePlatform(platform);
|
||||||
|
v8::V8::Initialize();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string args = "/?v=5&encoding=json";
|
||||||
|
std::string url = DiscordAPI::get_gateway().value("url", "wss://gateway.discord.gg");
|
||||||
|
|
||||||
|
bool retry = true;
|
||||||
|
while (retry) {
|
||||||
|
try {
|
||||||
|
ClientConnection conn;
|
||||||
|
conn.start(url + args);
|
||||||
|
}
|
||||||
|
catch (const std::exception &e) {
|
||||||
|
Logger::write("std exception: " + std::string(e.what()), Logger::LogLevel::Severe);
|
||||||
|
retry = false;
|
||||||
|
}
|
||||||
|
catch (websocketpp::lib::error_code e) {
|
||||||
|
Logger::write("websocketpp exception: " + e.message(), Logger::LogLevel::Severe);
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
Logger::write("other exception.", Logger::LogLevel::Severe);
|
||||||
|
retry = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
v8::V8::Dispose();
|
||||||
|
v8::V8::ShutdownPlatform();
|
||||||
|
delete platform;
|
||||||
|
|
||||||
|
curl_global_cleanup();
|
||||||
|
|
||||||
|
Logger::write("Cleaned up", Logger::LogLevel::Info);
|
||||||
|
|
||||||
|
std::cout << "Press enter to exit" << std::endl;
|
||||||
|
std::getchar();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef BOT_JS_COMMANDHELPER
|
#ifndef BOT_JS_COMMANDHELPER
|
||||||
#define BOT_JS_COMMANDHELPER
|
#define BOT_JS_COMMANDHELPER
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace CommandHelper {
|
namespace CommandHelper {
|
||||||
|
@ -48,12 +48,12 @@ void V8Instance::create() {
|
|||||||
void V8Instance::initialise(Local<Context> context) {
|
void V8Instance::initialise(Local<Context> context) {
|
||||||
HandleScope handle_scope(isolate);
|
HandleScope handle_scope(isolate);
|
||||||
|
|
||||||
Local<Object> opts_obj = wrap_server(&(*guilds)[guild_id]);
|
Local<Object> server_obj = wrap_server(&(*guilds)[guild_id]);
|
||||||
|
|
||||||
context->Global()->Set(
|
context->Global()->Set(
|
||||||
context,
|
context,
|
||||||
String::NewFromUtf8(isolate, "server", NewStringType::kNormal).ToLocalChecked(),
|
String::NewFromUtf8(isolate, "server", NewStringType::kNormal).ToLocalChecked(),
|
||||||
opts_obj
|
server_obj
|
||||||
).FromJust();
|
).FromJust();
|
||||||
|
|
||||||
Logger::write("[v8] Bound server template", Logger::LogLevel::Debug);
|
Logger::write("[v8] Bound server template", Logger::LogLevel::Debug);
|
||||||
@ -209,13 +209,6 @@ Local<Object> V8Instance::wrap_channel(DiscordObjects::Channel *channel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void V8Instance::js_get_channel(Local<Name> property, const PropertyCallbackInfo<Value> &info) {
|
void V8Instance::js_get_channel(Local<Name> property, const PropertyCallbackInfo<Value> &info) {
|
||||||
void *self_v = info.Data().As<External>()->Value();
|
|
||||||
if (!self_v) {
|
|
||||||
Logger::write("[v8] [js_get_channel] Class pointer empty", Logger::LogLevel::Warning);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
V8Instance *self = static_cast<V8Instance *>(self_v);
|
|
||||||
|
|
||||||
void *channel_v = info.Holder()->GetInternalField(0).As<External>()->Value();
|
void *channel_v = info.Holder()->GetInternalField(0).As<External>()->Value();
|
||||||
if (!channel_v) {
|
if (!channel_v) {
|
||||||
Logger::write("[v8] [js_get_channel] Channel pointer empty", Logger::LogLevel::Warning);
|
Logger::write("[v8] [js_get_channel] Channel pointer empty", Logger::LogLevel::Warning);
|
||||||
@ -694,10 +687,10 @@ void V8Instance::exec_js(std::string js, DiscordObjects::Channel *channel, Disco
|
|||||||
String::NewFromUtf8(isolate, "user", NewStringType::kNormal).ToLocalChecked(),
|
String::NewFromUtf8(isolate, "user", NewStringType::kNormal).ToLocalChecked(),
|
||||||
user_obj
|
user_obj
|
||||||
);
|
);
|
||||||
Local<Object> channel_obj = wrap_user(sender);
|
Local<Object> channel_obj = wrap_channel(channel);
|
||||||
context->Global()->Set(
|
context->Global()->Set(
|
||||||
String::NewFromUtf8(isolate, "user", NewStringType::kNormal).ToLocalChecked(),
|
String::NewFromUtf8(isolate, "channel", NewStringType::kNormal).ToLocalChecked(),
|
||||||
user_obj
|
channel_obj
|
||||||
);
|
);
|
||||||
// TODO: 'message' object here too, although it's fairly pointless
|
// TODO: 'message' object here too, although it's fairly pointless
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user