#ifndef BOT_JS_V8INSTANCE #define BOT_JS_V8INSTANCE #include #include #include #include #include #include "../data_structures/Guild.hpp" #include "../data_structures/Channel.hpp" #include "../data_structures/Role.hpp" #include "../data_structures/GuildMember.hpp" #include "../data_structures/User.hpp" class BotConfig; class V8Instance { public: V8Instance(BotConfig &c, std::string guild_id, std::map *guilds, std::map *channels, std::map *users, std::map *roles); void exec_js(std::string js, DiscordObjects::Channel *channel, DiscordObjects::GuildMember *sender, std::string args = ""); private: BotConfig &config; void create(); v8::Local create_context(); void initialise(v8::Local context); /* server */ v8::Global server_template; v8::Local make_server_template(); v8::Local wrap_server(DiscordObjects::Guild *guild); static void js_get_server(v8::Local property, const v8::PropertyCallbackInfo &info); /* user */ v8::Global user_template; v8::Local make_user_template(); v8::Local wrap_user(DiscordObjects::GuildMember *member); static void js_get_user(v8::Local property, const v8::PropertyCallbackInfo &info); v8::Global user_list_template; v8::Local make_user_list_template(); v8::Local wrap_user_list(std::vector *user_list); static void js_get_user_list(uint32_t index, const v8::PropertyCallbackInfo &info); /* channel */ v8::Global channel_template; v8::Local make_channel_template(); v8::Local wrap_channel(DiscordObjects::Channel *channel); static void js_get_channel(v8::Local property, const v8::PropertyCallbackInfo &info); v8::Global channel_list_template; v8::Local make_channel_list_template(); v8::Local wrap_channel_list(std::vector *channel_list); static void js_get_channel_list(uint32_t index, const v8::PropertyCallbackInfo &info); /* role */ v8::Global role_template; v8::Local make_role_template(); v8::Local wrap_role(DiscordObjects::Role *role); static void js_get_role(v8::Local property, const v8::PropertyCallbackInfo &info); v8::Global role_list_template; v8::Local make_role_list_template(); v8::Local wrap_role_list(std::vector *role_list); static void js_get_role_list(uint32_t index, const v8::PropertyCallbackInfo &info); /* print function */ static void js_print(const v8::FunctionCallbackInfo &args); /* randomness functions */ static void js_random(const v8::FunctionCallbackInfo &args); static void js_shuffle(const v8::FunctionCallbackInfo &args); std::map *guilds; std::map *channels; std::map *users; std::map *roles; std::string guild_id; v8::Isolate *isolate; v8::Global context_; /* random generating variables */ std::mt19937 rng; /* variables which change when a new command is executed */ std::string print_text; DiscordObjects::Channel *current_channel; DiscordObjects::GuildMember *current_sender; }; #endif