#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 APIHelper; using namespace v8; class V8Instance { public: V8Instance(std::string guild_id, std::map *guilds, std::map *channels, std::map *users, std::map *roles); ~V8Instance(); void reload(); void exec_js(std::string js, DiscordObjects::Channel *channel, DiscordObjects::GuildMember *sender, std::string args = ""); private: void clean_up(); void create(); Local create_context(); void initialise(Local context); /* server */ Global server_template; Local make_server_template(); Local wrap_server(DiscordObjects::Guild *guild); static void js_get_server(Local property, const PropertyCallbackInfo &info); /* user */ Global user_template; Local make_user_template(); Local wrap_user(DiscordObjects::GuildMember *member); static void js_get_user(Local property, const PropertyCallbackInfo &info); Global user_list_template; Local make_user_list_template(); Local wrap_user_list(std::vector *user_list); static void js_get_user_list(uint32_t index, const PropertyCallbackInfo &info); /* channel */ Global channel_template; Local make_channel_template(); Local wrap_channel(DiscordObjects::Channel *channel); static void js_get_channel(Local property, const PropertyCallbackInfo &info); Global channel_list_template; Local make_channel_list_template(); Local wrap_channel_list(std::vector *channel_list); static void js_get_channel_list(uint32_t index, const PropertyCallbackInfo &info); /* role */ Global role_template; Local make_role_template(); Local wrap_role(DiscordObjects::Role *role); static void js_get_role(Local property, const PropertyCallbackInfo &info); Global role_list_template; Local make_role_list_template(); Local wrap_role_list(std::vector *role_list); static void js_get_role_list(uint32_t index, const PropertyCallbackInfo &info); /* print function */ static void js_print(const FunctionCallbackInfo &args); /* randomness functions */ static void js_random(const FunctionCallbackInfo &args); static void js_shuffle(const FunctionCallbackInfo &args); std::map *guilds; std::map *channels; std::map *users; std::map *roles; std::string guild_id; Isolate *isolate; 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