mirror of
https://gitlab.com/niansa/SomeBot.git
synced 2025-03-06 20:48:26 +01:00
More bindings and constructors
This commit is contained in:
parent
2f6f68ddba
commit
0d24095c73
1 changed files with 139 additions and 38 deletions
|
@ -51,16 +51,30 @@ public:
|
|||
.endClass()
|
||||
.beginClass<snowflake>("Snowflake")
|
||||
.addConstructor<void (const uint64_t&), void (const std::string&)>()
|
||||
.addProperty("id", &snowflake::operator unsigned long)
|
||||
.addProperty("integer", &snowflake::operator uint64_t)
|
||||
.addProperty("string", +[] (const snowflake *o) -> std::string { return std::to_string(*o); })
|
||||
.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")
|
||||
.addStaticFunction("new", [guild_id = baseContext.guild_id] () {
|
||||
dpp::message o;
|
||||
o.guild_id = guild_id;
|
||||
.addConstructor([guild_id = baseContext.guild_id] (void *vo) {
|
||||
auto o = reinterpret_cast<message*>(vo);
|
||||
o->guild_id = guild_id;
|
||||
return o;
|
||||
})
|
||||
.addConstructor([guild_id = baseContext.guild_id] (void *vo, snowflake channel_id) {
|
||||
auto o = reinterpret_cast<message*>(vo);
|
||||
o->guild_id = guild_id;
|
||||
o->channel_id = channel_id;
|
||||
return o;
|
||||
})
|
||||
.addConstructor([guild_id = baseContext.guild_id] (void *vo, snowflake channel_id, const std::string& content) {
|
||||
auto o = reinterpret_cast<message*>(vo);
|
||||
o->guild_id = guild_id;
|
||||
o->channel_id = channel_id;
|
||||
o->content = content;
|
||||
return o;
|
||||
})
|
||||
.addProperty("id", &message::id, false)
|
||||
|
@ -132,6 +146,12 @@ public:
|
|||
.addProperty("roles", &message::allowed_ref::roles, true)
|
||||
.endClass()
|
||||
.beginClass<embed>("Embed")
|
||||
.addConstructor(+[] (void *vo, const std::string& title, const std::string& description) {
|
||||
auto o = reinterpret_cast<embed*>(vo);
|
||||
o->title = title;
|
||||
o->description = description;
|
||||
return o;
|
||||
})
|
||||
.addProperty("title", &embed::title, true)
|
||||
.addProperty("type", &embed::type, true)
|
||||
.addProperty("description", &embed::description, true)
|
||||
|
@ -218,6 +238,24 @@ public:
|
|||
.addProperty("banner_asset_id", &sticker_pack::banner_asset_id, true)
|
||||
.endClass()
|
||||
.beginClass<channel>("Channel")
|
||||
.addConstructor([guild_id = baseContext.guild_id] (void *vo) {
|
||||
auto o = reinterpret_cast<channel*>(vo);
|
||||
o->guild_id = guild_id;
|
||||
return o;
|
||||
})
|
||||
.addConstructor([guild_id = baseContext.guild_id] (void *vo, const std::string& name) {
|
||||
auto o = reinterpret_cast<channel*>(vo);
|
||||
o->guild_id = guild_id;
|
||||
o->name = name;
|
||||
return o;
|
||||
})
|
||||
.addConstructor([guild_id = baseContext.guild_id] (void *vo, snowflake parent_id, const std::string& name) {
|
||||
auto o = reinterpret_cast<channel*>(vo);
|
||||
o->guild_id = guild_id;
|
||||
o->parent_id = parent_id;
|
||||
o->name = name;
|
||||
return o;
|
||||
})
|
||||
.addProperty("id", &channel::id, false)
|
||||
.addProperty("name", &channel::name, true)
|
||||
.addProperty("topic", &channel::topic, true)
|
||||
|
@ -226,6 +264,7 @@ public:
|
|||
.addProperty("permission_overwrites", &channel::permission_overwrites, true)
|
||||
.addProperty("available_tags", &channel::available_tags, true)
|
||||
.addProperty("icon", &channel::icon, true)
|
||||
.addProperty("icon_url", +[] (const channel *o) { return o->get_icon_url(); })
|
||||
.addProperty("owner_id", &channel::owner_id, true)
|
||||
.addProperty("parent_id", &channel::parent_id, true)
|
||||
.addProperty("guild_id", &channel::guild_id, false)
|
||||
|
@ -269,6 +308,7 @@ public:
|
|||
.addProperty("id", &user::id, false)
|
||||
.addProperty("username", &user::username, true)
|
||||
.addProperty("avatar", &user::avatar, true)
|
||||
.addProperty("avatar_url", +[] (const user *o) { return o->get_avatar_url(); })
|
||||
.addProperty("flags", &user::flags, true)
|
||||
.addProperty("discriminator", &user::discriminator, true)
|
||||
.addProperty("mention", &user::get_mention)
|
||||
|
@ -301,6 +341,7 @@ public:
|
|||
.addProperty("guild_id", &guild_member::guild_id, false)
|
||||
.addProperty("user_id", &guild_member::user_id, true)
|
||||
.addProperty("avatar", &guild_member::avatar, true)
|
||||
.addProperty("avatar_url", +[] (const guild_member *o) { return o->get_avatar_url(); })
|
||||
.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)
|
||||
|
@ -314,6 +355,96 @@ public:
|
|||
.addFunction("get_avatar_url", &guild_member::get_avatar_url)
|
||||
.addFunction("mention", &guild_member::get_mention)
|
||||
.endClass()
|
||||
.beginClass<guild>("Guild")
|
||||
.addProperty("id", &guild::id, false)
|
||||
.addProperty("name", &guild::name, true)
|
||||
.addProperty("vanity_url_code", &guild::vanity_url_code, true)
|
||||
.addProperty("roles", &guild::roles, false)
|
||||
.addProperty("channels", &guild::channels, false)
|
||||
.addProperty("threads", &guild::threads, false)
|
||||
.addProperty("emojis", &guild::emojis, false)
|
||||
.addProperty("voice_members", &guild::voice_members, false)
|
||||
.addProperty("members", &guild::members, false)
|
||||
.addProperty("welcome_screen", &guild::welcome_screen, true)
|
||||
.addProperty("icon", &guild::icon, true)
|
||||
.addProperty("splash", &guild::splash, true)
|
||||
.addProperty("discovery_splash", &guild::discovery_splash, true)
|
||||
.addProperty("banner", &guild::banner, true)
|
||||
.addProperty("owner_id", &guild::owner_id, true)
|
||||
.addProperty("afk_channel_id", &guild::afk_channel_id, true)
|
||||
.addProperty("application_id", &guild::application_id, true)
|
||||
.addProperty("system_channel_id", &guild::system_channel_id, true)
|
||||
.addProperty("rules_channel_id", &guild::rules_channel_id, true)
|
||||
.addProperty("public_updates_channel_id", &guild::public_updates_channel_id, true)
|
||||
.addProperty("widget_channel_id", &guild::widget_channel_id, true)
|
||||
.addProperty("member_count", &guild::member_count, false)
|
||||
.addProperty("flags", &guild::flags, false)
|
||||
.addProperty("max_presences", &guild::max_presences, false)
|
||||
.addProperty("max_members", &guild::max_members, false)
|
||||
.addProperty("shard_id", &guild::shard_id, false)
|
||||
.addProperty("premium_subscription_count", &guild::premium_subscription_count, false)
|
||||
.addProperty("afk_timeout", &guild::afk_timeout, true)
|
||||
.addProperty("max_video_channel_users", &guild::max_video_channel_users, false)
|
||||
.addProperty("default_message_notifications", &guild::default_message_notifications, true)
|
||||
.addProperty("premium_tier", &guild::premium_tier, false)
|
||||
.addProperty("verification_level", &guild::verification_level, false)
|
||||
.addProperty("explicit_content_filter", &guild::explicit_content_filter, true)
|
||||
.addProperty("mfa_level", &guild::mfa_level, true)
|
||||
.addProperty("nsfw_level", &guild::nsfw_level, true)
|
||||
.addProperty("flags_extra", &guild::flags_extra, false)
|
||||
.addProperty("discovery_splash_url", +[] (const guild *o) { return o->get_discovery_splash_url(); })
|
||||
.addProperty("icon_url", +[] (const guild *o) { return o->get_icon_url(); })
|
||||
.addProperty("splash_url", +[] (const guild *o) { return o->get_splash_url(); })
|
||||
.addProperty("banner_url", +[] (const guild *o) { return o->get_banner_url(); })
|
||||
.addProperty("is_large", &guild::is_large)
|
||||
.addProperty("is_unavailable", &guild::is_unavailable)
|
||||
.addProperty("is_widget_enabled", &guild::widget_enabled)
|
||||
.addProperty("has_invite_splash", &guild::has_invite_splash)
|
||||
.addProperty("has_vip_regions", &guild::has_vip_regions)
|
||||
.addProperty("has_vanity_url", &guild::has_vanity_url)
|
||||
.addProperty("is_verified", &guild::is_verified)
|
||||
.addProperty("is_partnered", &guild::is_partnered)
|
||||
.addProperty("is_community", &guild::is_community)
|
||||
.addProperty("has_commerce", &guild::has_commerce)
|
||||
.addProperty("has_news", &guild::has_news)
|
||||
.addProperty("is_discoverable", &guild::is_discoverable)
|
||||
.addProperty("is_featureable", &guild::is_featureable)
|
||||
.addProperty("has_animated_banner", &guild::has_animated_banner)
|
||||
.addProperty("has_auto_moderation", &guild::has_auto_moderation)
|
||||
.addProperty("has_support_server", &guild::has_support_server)
|
||||
.addProperty("has_animated_icon", &guild::has_animated_icon)
|
||||
.addProperty("has_banner", &guild::has_banner)
|
||||
.addProperty("is_welcome_screen_enabled", &guild::is_welcome_screen_enabled)
|
||||
.addProperty("has_member_verification_gate", &guild::has_member_verification_gate)
|
||||
.addProperty("is_preview_enabled", &guild::is_preview_enabled)
|
||||
.addProperty("has_animated_icon_hash", &guild::has_animated_icon_hash)
|
||||
.addProperty("has_animated_banner_hash", &guild::has_animated_banner_hash)
|
||||
.addProperty("has_monetization_enabled", &guild::has_monetization_enabled)
|
||||
.addProperty("has_more_stickers", &guild::has_more_stickers)
|
||||
.addProperty("has_private_threads", &guild::has_private_threads)
|
||||
.addProperty("has_role_icons", &guild::has_role_icons)
|
||||
.addProperty("has_seven_day_thread_archive", &guild::has_seven_day_thread_archive)
|
||||
.addProperty("has_three_day_thread_archive", &guild::has_three_day_thread_archive)
|
||||
.addProperty("has_ticketed_events", &guild::has_ticketed_events)
|
||||
.addProperty("has_channel_banners", &guild::has_channel_banners)
|
||||
.addProperty("has_premium_progress_bar_enabled", &guild::has_premium_progress_bar_enabled)
|
||||
.addProperty("has_invites_disabled", &guild::has_invites_disabled)
|
||||
.addFunction("get_base_user_permissions", luabridge::overload<const user*>(&guild::base_permissions))
|
||||
.addFunction("get_base_member_permissions", luabridge::overload<const guild_member &>(&guild::base_permissions))
|
||||
.addFunction("get_permission_overwrites", luabridge::overload<const guild_member &, const channel &>(&guild::permission_overwrites))
|
||||
.endClass()
|
||||
.beginClass<utility::iconhash>("IconHash")
|
||||
.addProperty("first", &utility::iconhash::first, true)
|
||||
.addProperty("second", &utility::iconhash::second, true)
|
||||
.addProperty("string", &utility::iconhash::to_string, &utility::iconhash::set)
|
||||
.endClass()
|
||||
.beginClass<permission>("Permission")
|
||||
.addProperty("integer", &permission::operator uint64_t)
|
||||
.addFunction("has", &permission::has<uint64_t>)
|
||||
.addFunction("add", &permission::add<uint64_t>)
|
||||
.addFunction("set", &permission::set<uint64_t>)
|
||||
.addFunction("remove", &permission::remove<uint64_t>)
|
||||
.endClass()
|
||||
.addFunction("fetch_guild", [guild_id = baseContext.guild_id, cluster = &baseContext.bot->cluster] () -> std::optional<dpp::guild> {
|
||||
try {
|
||||
return cluster->guild_get_sync(guild_id);
|
||||
|
@ -366,51 +497,24 @@ public:
|
|||
return error;
|
||||
}
|
||||
|
||||
// Create a new lua thread
|
||||
auto thread = lua_newthread(state);
|
||||
|
||||
// Prepare stack
|
||||
lua_pushvalue(state, -2);
|
||||
lua_remove(state, -3);
|
||||
lua_xmove(state, thread, 1);
|
||||
|
||||
// ... and start executing
|
||||
int status = lua_resume(thread, NULL, 0);
|
||||
int status = lua_resume(state, NULL, 0);
|
||||
|
||||
// Check status
|
||||
if (status == 0) {
|
||||
// No error
|
||||
int n = lua_gettop(thread);
|
||||
|
||||
// Check for result
|
||||
if (n) {
|
||||
// Print that result
|
||||
luaL_checkstack(thread, LUA_MINSTACK, "too many results to print");
|
||||
lua_getglobal(thread, "_PRETTYPRINT");
|
||||
// If _PRETTYPRINT is nil, then use the standard print function instead
|
||||
if (lua_isnil(thread, -1)) {
|
||||
lua_pop(thread, 1);
|
||||
lua_getglobal(thread, "print");
|
||||
}
|
||||
lua_insert(thread, 1);
|
||||
lua_pcall(thread, n, 0, 0);
|
||||
}
|
||||
|
||||
// Keep going
|
||||
} else {
|
||||
if (status != 0) {
|
||||
// Error!
|
||||
std::string error;
|
||||
|
||||
// Get error string
|
||||
if (status == LUA_YIELD) {
|
||||
error = "thread yielded unexpectedly";
|
||||
} else if (const char* str = lua_tostring(thread, -1)) {
|
||||
} else if (const char* str = lua_tostring(state, -1)) {
|
||||
error = str;
|
||||
}
|
||||
|
||||
// Append backtrace
|
||||
error += "\nstack backtrace:\n";
|
||||
error += lua_debugtrace(thread);
|
||||
error += lua_debugtrace(state);
|
||||
|
||||
// Clean up and return
|
||||
lua_pop(state, 1);
|
||||
|
@ -424,9 +528,6 @@ public:
|
|||
}
|
||||
luabridge::LuaResult result = on_call(Context{baseContext, msg});
|
||||
|
||||
// Remember to clean up!
|
||||
lua_pop(state, 1);
|
||||
|
||||
// Finally, we need to return the result
|
||||
return result.errorMessage();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue