mirror of
https://gitlab.com/niansa/SomeBot.git
synced 2025-03-06 20:48:26 +01:00
Fixed UB in custom constructors
This commit is contained in:
parent
0d24095c73
commit
a5eaf53f05
1 changed files with 25 additions and 7 deletions
|
@ -60,18 +60,18 @@ public:
|
|||
.endClass()
|
||||
.beginClass<message>("Message")
|
||||
.addConstructor([guild_id = baseContext.guild_id] (void *vo) {
|
||||
auto o = reinterpret_cast<message*>(vo);
|
||||
auto o = new (vo) message;
|
||||
o->guild_id = guild_id;
|
||||
return o;
|
||||
})
|
||||
.addConstructor([guild_id = baseContext.guild_id] (void *vo, snowflake channel_id) {
|
||||
auto o = reinterpret_cast<message*>(vo);
|
||||
auto o = new (vo) message;
|
||||
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);
|
||||
auto o = new (vo) message;
|
||||
o->guild_id = guild_id;
|
||||
o->channel_id = channel_id;
|
||||
o->content = content;
|
||||
|
@ -147,7 +147,7 @@ public:
|
|||
.endClass()
|
||||
.beginClass<embed>("Embed")
|
||||
.addConstructor(+[] (void *vo, const std::string& title, const std::string& description) {
|
||||
auto o = reinterpret_cast<embed*>(vo);
|
||||
auto o = new (vo) embed;
|
||||
o->title = title;
|
||||
o->description = description;
|
||||
return o;
|
||||
|
@ -239,18 +239,18 @@ public:
|
|||
.endClass()
|
||||
.beginClass<channel>("Channel")
|
||||
.addConstructor([guild_id = baseContext.guild_id] (void *vo) {
|
||||
auto o = reinterpret_cast<channel*>(vo);
|
||||
auto o = new (vo) channel;
|
||||
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);
|
||||
auto o = new (vo) channel;
|
||||
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);
|
||||
auto o = new (vo) channel;
|
||||
o->guild_id = guild_id;
|
||||
o->parent_id = parent_id;
|
||||
o->name = name;
|
||||
|
@ -303,6 +303,13 @@ public:
|
|||
.addFunction("get_icon_url", &channel::get_icon_url)
|
||||
.addFunction("get_members", &channel::get_members)
|
||||
.addFunction("get_voice_members", &channel::get_voice_members)
|
||||
.addFunction("create", [cluster = &baseContext.bot->cluster] (const channel *o) -> std::optional<dpp::channel> {
|
||||
try {
|
||||
return cluster->channel_create_sync(*o);
|
||||
} catch (...) {
|
||||
return {};
|
||||
}
|
||||
})
|
||||
.endClass()
|
||||
.beginClass<user>("User")
|
||||
.addProperty("id", &user::id, false)
|
||||
|
@ -476,6 +483,17 @@ public:
|
|||
} catch (...) {
|
||||
return {};
|
||||
}
|
||||
})
|
||||
.addFunction("fetch_message", [guild_id = baseContext.guild_id, cluster = &baseContext.bot->cluster] (const dpp::snowflake id, const dpp::snowflake channel_id) -> std::optional<dpp::message> {
|
||||
try {
|
||||
auto msg = cluster->message_get_sync(id, channel_id);
|
||||
if (msg.guild_id != guild_id) {
|
||||
return {};
|
||||
}
|
||||
return msg;
|
||||
} catch (...) {
|
||||
return {};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue