mirror of
https://gitlab.com/niansa/SomeBot.git
synced 2025-03-06 20:48:26 +01:00
Progress on bindings
This commit is contained in:
parent
a48bab7f77
commit
5cf9b7df36
1 changed files with 281 additions and 0 deletions
281
modules/custom.cpp
Normal file
281
modules/custom.cpp
Normal file
|
@ -0,0 +1,281 @@
|
|||
#include "../bot.hpp"
|
||||
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
#include <ctime>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <Luau/Compiler.h>
|
||||
#include <LuaBridge/LuaBridge.h>
|
||||
#include <LuaBridge/Vector.h>
|
||||
#include <LuaBridge/Map.h>
|
||||
|
||||
|
||||
|
||||
class LuaExecution {
|
||||
std::unique_ptr<lua_State, void (*)(lua_State*)> state;
|
||||
|
||||
static int assertionHandler(const char* expr, const char* file, int line, const char* function) {
|
||||
printf("%s<%s>(%d): ASSERTION FAILED: %s\n", file, function, line, expr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
public:
|
||||
LuaExecution() : state(luaL_newstate(), lua_close) {
|
||||
// Set assertion handler
|
||||
Luau::assertHandler() = assertionHandler;
|
||||
|
||||
// Get state
|
||||
auto state = this->state.get();
|
||||
|
||||
// Load initial libraries
|
||||
luaL_openlibs(state);
|
||||
|
||||
using namespace dpp;
|
||||
luabridge::getGlobalNamespace(state)
|
||||
.beginClass<snowflake>("Snowflake")
|
||||
.addConstructor<void (const uint64_t&), void (const std::string&)>()
|
||||
.addProperty("id", &snowflake::operator unsigned long)
|
||||
.addProperty("creation_time", &snowflake::get_creation_time)
|
||||
.addProperty("worker_id", &snowflake::get_worker_id)
|
||||
.addProperty("process_id", &snowflake::get_process_id)
|
||||
.addProperty("increment", &snowflake::get_increment)
|
||||
.endClass()
|
||||
.beginClass<message>("Message")
|
||||
.addProperty("id", &message::id, false)
|
||||
.addProperty("channel_id", &message::channel_id, true)
|
||||
.addProperty("guild_id", &message::guild_id, false)
|
||||
.addProperty("author", &message::author, true)
|
||||
.addProperty("member", &message::member, true)
|
||||
.addProperty("content", &message::content, true)
|
||||
.addProperty("components", &message::components, true)
|
||||
.addProperty("sent", &message::sent, true)
|
||||
.addProperty("edited", &message::edited, true)
|
||||
.addProperty("mentions", &message::mentions, true)
|
||||
.addProperty("mention_roles", &message::mention_roles, true)
|
||||
.addProperty("mention_channels", &message::mention_channels, true)
|
||||
.addProperty("attachments", &message::attachments, true)
|
||||
.addProperty("embeds", &message::embeds, true)
|
||||
.addProperty("reactions", &message::reactions, true)
|
||||
.addProperty("nonce", &message::nonce, true)
|
||||
.addProperty("webhook_id", &message::webhook_id, true)
|
||||
.addProperty("stickers", &message::stickers, true)
|
||||
.addProperty("file_name", &message::filename, true)
|
||||
.addProperty("file_content", &message::filecontent, true)
|
||||
.addProperty("reference", &message::message_reference, true)
|
||||
.addProperty("interaction", &message::interaction, true)
|
||||
.addProperty("allowed_mentions", &message::allowed_mentions, true)
|
||||
.addProperty("type", &message::type, true)
|
||||
.addProperty("flags", &message::flags, true)
|
||||
.addProperty("pinned", &message::pinned, true)
|
||||
.addProperty("tts", &message::tts, true)
|
||||
.addProperty("mention_everyone", &message::mention_everyone, true)
|
||||
.addProperty("is_crossposted", &message::is_crossposted)
|
||||
.addProperty("is_crosspost", &message::is_crosspost)
|
||||
.addProperty("suppress_embeds", &message::suppress_embeds)
|
||||
.addProperty("is_source_message_deleted", &message::is_source_message_deleted)
|
||||
.addProperty("is_urgent", &message::is_urgent)
|
||||
.addProperty("has_thread", &message::has_thread)
|
||||
.addProperty("is_ephemeral", &message::is_ephemeral)
|
||||
.addProperty("is_loading", &message::is_loading)
|
||||
.addProperty("is_thread_mention_failed", &message::is_thread_mention_failed)
|
||||
.addProperty("is_dm", &message::is_dm)
|
||||
.addFunction("add_component", &message::add_component)
|
||||
.addFunction("add_embed", &message::add_embed)
|
||||
.endClass()
|
||||
.beginClass<message::message_ref>("MessageRef")
|
||||
.addProperty("message_id", &message::message_ref::message_id, true)
|
||||
.addProperty("channel_id", &message::message_ref::channel_id, true)
|
||||
.addProperty("guild_id", &message::message_ref::guild_id, false)
|
||||
.addProperty("fail_if_not_exists", &message::message_ref::fail_if_not_exists, true)
|
||||
.endClass()
|
||||
.beginClass<message::message_interaction_struct>("MessageInteraction")
|
||||
.addProperty("id", &message::message_interaction_struct::id, false)
|
||||
.addProperty("type", &message::message_interaction_struct::type, true)
|
||||
.addProperty("name", &message::message_interaction_struct::name, true)
|
||||
.addProperty("usr", &message::message_interaction_struct::usr, true)
|
||||
.endClass()
|
||||
.beginClass<message::allowed_ref>("MessageAllowedRef")
|
||||
.addProperty("parse_users", &message::allowed_ref::parse_users, true)
|
||||
.addProperty("parse_everyone", &message::allowed_ref::parse_everyone, true)
|
||||
.addProperty("parse_roles", &message::allowed_ref::parse_roles, true)
|
||||
.addProperty("replied_user", &message::allowed_ref::replied_user, true)
|
||||
.addProperty("users", &message::allowed_ref::users, true)
|
||||
.addProperty("roles", &message::allowed_ref::roles, true)
|
||||
.endClass()
|
||||
.beginClass<embed>("Embed")
|
||||
.addProperty("title", &embed::title, true)
|
||||
.addProperty("type", &embed::type, true)
|
||||
.addProperty("description", &embed::description, true)
|
||||
.addProperty("url", &embed::url, true)
|
||||
.addProperty("timestamp", &embed::timestamp, true)
|
||||
.addProperty("color", &embed::color, true)
|
||||
.addProperty("footer", &embed::footer, true)
|
||||
.addProperty("image", &embed::image, true)
|
||||
.addProperty("thumbnail", &embed::thumbnail, true)
|
||||
.addProperty("video", &embed::video, true)
|
||||
.addProperty("provider", &embed::provider, true)
|
||||
.addProperty("author", &embed::author, true)
|
||||
.addProperty("fields", &embed::fields, true)
|
||||
.endClass()
|
||||
.beginClass<embed_footer>("EmbedFooter")
|
||||
.addProperty("text", &embed_footer::text, true)
|
||||
.addProperty("icon_url", &embed_footer::icon_url, true)
|
||||
.addProperty("proxy_url", &embed_footer::proxy_url, true)
|
||||
.endClass()
|
||||
.beginClass<embed_image>("EmbedImage")
|
||||
.addProperty("url", &embed_image::url, true)
|
||||
.addProperty("proxy_url", &embed_image::proxy_url, true)
|
||||
.addProperty("height", &embed_image::height, false)
|
||||
.addProperty("width", &embed_image::width, false)
|
||||
.endClass()
|
||||
.beginClass<embed_provider>("EmbedProvider")
|
||||
.addProperty("name", &embed_provider::name, true)
|
||||
.addProperty("url", &embed_provider::url, true)
|
||||
.endClass()
|
||||
.beginClass<embed_author>("EmbedAuthor")
|
||||
.addProperty("name", &embed_author::name, true)
|
||||
.addProperty("url", &embed_author::url, true)
|
||||
.addProperty("icon_url", &embed_author::icon_url, true)
|
||||
.addProperty("proxy_icon_url", &embed_author::proxy_icon_url, true)
|
||||
.endClass()
|
||||
.beginClass<embed_field>("EmbedField")
|
||||
.addProperty("name", &embed_field::name, true)
|
||||
.addProperty("value", &embed_field::value, true)
|
||||
.addProperty("is_inline", &embed_field::is_inline, true)
|
||||
.endClass()
|
||||
.beginClass<reaction>("Reaction")
|
||||
.addProperty("count", &reaction::count, false)
|
||||
.addProperty("me", &reaction::me, true)
|
||||
.addProperty("emoji_id", &reaction::emoji_id, true)
|
||||
.addProperty("emoji_name", &reaction::emoji_name, true)
|
||||
.endClass()
|
||||
.beginClass<attachment>("Attachment")
|
||||
.addProperty("id", &attachment::id, false)
|
||||
.addProperty("size", &attachment::size, false)
|
||||
.addProperty("filename", &attachment::filename, true)
|
||||
.addProperty("description", &attachment::description, true)
|
||||
.addProperty("url", &attachment::url, false)
|
||||
.addProperty("proxy_url", &attachment::proxy_url, false)
|
||||
.addProperty("width", &attachment::width, false)
|
||||
.addProperty("height", &attachment::height, false)
|
||||
.addProperty("content_type", &attachment::content_type, false)
|
||||
.addProperty("ephemeral", &attachment::ephemeral, true)
|
||||
.addProperty("owner", &attachment::owner, false)
|
||||
.endClass()
|
||||
.beginClass<channel>("Channel")
|
||||
.addProperty("id", &channel::id, false)
|
||||
.addProperty("name", &channel::name, true)
|
||||
.addProperty("topic", &channel::topic, true)
|
||||
.addProperty("rtc_region", &channel::rtc_region, true)
|
||||
.addProperty("recipients", &channel::recipients, true)
|
||||
.addProperty("permission_overwrites", &channel::permission_overwrites, true)
|
||||
.addProperty("available_tags", &channel::available_tags, true)
|
||||
.addProperty("icon", &channel::icon, true)
|
||||
.addProperty("owner_id", &channel::owner_id, true)
|
||||
.addProperty("parent_id", &channel::parent_id, true)
|
||||
.addProperty("guild_id", &channel::guild_id, false)
|
||||
.addProperty("last_message_id", &channel::last_message_id, true)
|
||||
.addProperty("last_pin_timestamp", &channel::last_pin_timestamp, true)
|
||||
.addProperty("permissions", &channel::permissions, true)
|
||||
.addProperty("position", &channel::position, true)
|
||||
.addProperty("bitrate", &channel::bitrate, true)
|
||||
.addProperty("rate_limit_per_user", &channel::rate_limit_per_user, true)
|
||||
.addProperty("default_thread_rate_limit_per_user", &channel::default_thread_rate_limit_per_user, true)
|
||||
.addProperty("default_auto_archive_duration", &channel::default_auto_archive_duration, true)
|
||||
.addProperty("default_sort_order", &channel::default_sort_order, true)
|
||||
.addProperty("flags", &channel::flags, true)
|
||||
.addProperty("type", +[] (const channel* o) { return o->get_type(); }, +[] (channel* o, channel_type v) { o->set_type(v); })
|
||||
.addProperty("is_nsfw", +[] (const channel* o) { return o->is_nsfw(); }, +[] (channel* o, channel_type v) { o->set_nsfw(v); })
|
||||
.addProperty("is_locked_permissions", +[] (const channel* o) { return o->is_locked_permissions(); }, +[] (channel* o, channel_type v) { o->set_lock_permissions(v); })
|
||||
.addProperty("is_text_channel", &channel::is_text_channel)
|
||||
.addProperty("is_dm", &channel::is_dm)
|
||||
.addProperty("is_voice_channel", &channel::is_voice_channel)
|
||||
.addProperty("is_group_dm", &channel::is_group_dm)
|
||||
.addProperty("is_category", &channel::is_category)
|
||||
.addProperty("is_forum", &channel::is_forum)
|
||||
.addProperty("is_news_channel", &channel::is_news_channel)
|
||||
.addProperty("is_store_channel", &channel::is_store_channel)
|
||||
.addProperty("is_stage_channel", &channel::is_stage_channel)
|
||||
.addProperty("is_video_auto", &channel::is_video_auto)
|
||||
.addProperty("is_video_720p", &channel::is_video_720p)
|
||||
.addProperty("is_pinned_thread", &channel::is_pinned_thread)
|
||||
.addProperty("is_tag_required", &channel::is_tag_required)
|
||||
.addProperty("mention", &channel::get_mention)
|
||||
.addFunction("add_flag", &channel::add_flag)
|
||||
.addFunction("remove_flag", &channel::remove_flag)
|
||||
.addFunction("add_permission_overwrite", &channel::add_permission_overwrite)
|
||||
.addFunction("get_user_permissions", luabridge::overload<const user*>(&channel::get_user_permissions))
|
||||
.addFunction("get_member_permissions", luabridge::overload<const guild_member&>(&channel::get_user_permissions))
|
||||
.addFunction("get_icon_url", &channel::get_icon_url)
|
||||
.addFunction("get_members", &channel::get_members)
|
||||
.addFunction("get_voice_members", &channel::get_voice_members)
|
||||
.endClass()
|
||||
.beginClass<user>("User")
|
||||
.addProperty("id", &user::id, false)
|
||||
.addProperty("username", &user::username, true)
|
||||
.addProperty("avatar", &user::avatar, true)
|
||||
.addProperty("flags", &user::flags, true)
|
||||
.addProperty("discriminator", &user::discriminator, true)
|
||||
.addProperty("mention", &user::get_mention)
|
||||
.addProperty("is_bot", &user::is_bot)
|
||||
.addProperty("is_mfa_enabled", &user::is_mfa_enabled)
|
||||
.addProperty("has_nitro_full", &user::has_nitro_full)
|
||||
.addProperty("has_nitro_classic", &user::has_nitro_classic)
|
||||
.addProperty("has_nitro_basic", &user::has_nitro_basic)
|
||||
.addProperty("is_discord_employee", &user::is_discord_employee)
|
||||
.addProperty("is_partnered_owner", &user::is_partnered_owner)
|
||||
.addProperty("has_hypesquad_events", &user::has_hypesquad_events)
|
||||
.addProperty("is_bughunter_1", &user::is_bughunter_1)
|
||||
.addProperty("is_house_bravery", &user::is_house_bravery)
|
||||
.addProperty("is_house_brilliance", &user::is_house_brilliance)
|
||||
.addProperty("is_house_balance", &user::is_house_balance)
|
||||
.addProperty("is_early_supporter", &user::is_early_supporter)
|
||||
.addProperty("is_team_user", &user::is_team_user)
|
||||
.addProperty("is_bughunter_2", &user::is_bughunter_2)
|
||||
.addProperty("is_verified_bot", &user::is_verified_bot)
|
||||
.addProperty("is_verified_bot_dev", &user::is_verified_bot_dev)
|
||||
.addProperty("is_certified_moderator", &user::is_certified_moderator)
|
||||
.addProperty("is_bot_http_interactions", &user::is_bot_http_interactions)
|
||||
.addProperty("has_animated_icon", &user::has_animated_icon)
|
||||
.addProperty("formatted_username", &user::format_username)
|
||||
.addFunction("get_avatar_url", &user::get_avatar_url)
|
||||
.endClass()
|
||||
.beginClass<guild_member>("Member")
|
||||
.addProperty("nickname", &guild_member::nickname, true)
|
||||
.addProperty("roles", &guild_member::roles, true)
|
||||
.addProperty("guild_id", &guild_member::guild_id, false)
|
||||
.addProperty("user_id", &guild_member::user_id, true)
|
||||
.addProperty("avatar", &guild_member::avatar, true)
|
||||
.addProperty("communication_disabled_until", &guild_member::communication_disabled_until, true)
|
||||
.addProperty("joined_at", &guild_member::joined_at, true)
|
||||
.addProperty("premium_since", &guild_member::premium_since, true)
|
||||
.addProperty("flags", &guild_member::flags, true)
|
||||
.addProperty("is_communication_disabled", &guild_member::is_communication_disabled)
|
||||
.addProperty("is_muted", +[] (const guild_member* o) { return o->is_muted(); }, +[] (guild_member* o, bool v) { o->set_mute(v); })
|
||||
.addProperty("is_deaf", +[] (const guild_member* o) { return o->is_deaf(); }, +[] (guild_member* o, bool v) { o->set_deaf(v); })
|
||||
.addProperty("is_pending", &guild_member::is_pending)
|
||||
.addProperty("has_animated_guild_avatar", &guild_member::has_animated_guild_avatar)
|
||||
.addProperty("user", &guild_member::get_user)
|
||||
.addFunction("get_avatar_url", &guild_member::get_avatar_url)
|
||||
.addFunction("mention", &guild_member::get_mention)
|
||||
.endClass();
|
||||
|
||||
// Our globals end here
|
||||
lua_pushvalue(state, LUA_GLOBALSINDEX);
|
||||
|
||||
// We can now enable sandboxing
|
||||
luaL_sandbox(state);
|
||||
}
|
||||
};
|
||||
|
||||
class Custom {
|
||||
Bot *bot;
|
||||
|
||||
public:
|
||||
Custom(Bot *_bot) : bot(_bot) {
|
||||
//...
|
||||
}
|
||||
};
|
||||
BOT_ADD_MODULE(Custom);
|
Loading…
Add table
Reference in a new issue