mirror of
https://gitlab.com/niansa/SomeBot.git
synced 2025-03-06 20:48:26 +01:00
Added embed creation features
This commit is contained in:
parent
1056f69fc7
commit
c229cb83da
2 changed files with 53 additions and 0 deletions
3
main.cpp
3
main.cpp
|
@ -264,6 +264,9 @@ int main(int argc, char **argv) {
|
|||
return -2;
|
||||
}
|
||||
|
||||
// Configure ASAN
|
||||
setenv("ASAN_OPTIONS", "new_delete_type_mismatch=0", true);
|
||||
|
||||
// Parse config file
|
||||
nlohmann::json config_json;
|
||||
std::ifstream config_file("config.json");
|
||||
|
|
50
modules/embedmaker.cpp
Normal file
50
modules/embedmaker.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "../bot.hpp"
|
||||
#include "../util.hpp"
|
||||
|
||||
|
||||
|
||||
class Embedmaker {
|
||||
Bot *bot;
|
||||
|
||||
static inline const std::string& strOrEmpty(const dpp::command_value& v) {
|
||||
if (v.index() == 1) {
|
||||
return std::get<std::string>(v);
|
||||
} else {
|
||||
static std::string empty;
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
Embedmaker(Bot *_bot) : bot(_bot) {
|
||||
bot->cluster.intents |= dpp::intents::i_guild_messages | dpp::intents::i_message_content;
|
||||
|
||||
bot->add_chatcommand(Bot::ChatCommand({"make_embed", "embed_erstellen"}, "Erstelle ein Embed", dpp::slashcommand()
|
||||
.add_option(dpp::command_option(dpp::command_option_type::co_string, "title", "Titel", true))
|
||||
.add_option(dpp::command_option(dpp::command_option_type::co_string, "description", "Beschreibung", true))
|
||||
.add_option(dpp::command_option(dpp::command_option_type::co_string, "image", "Bild", false))
|
||||
.add_option(dpp::command_option(dpp::command_option_type::co_string, "video", "Video", false))
|
||||
.add_option(dpp::command_option(dpp::command_option_type::co_string, "thumbnail", "Kleines Bild", false))
|
||||
.add_option(dpp::command_option(dpp::command_option_type::co_string, "color", "Farbe", false))
|
||||
.add_option(dpp::command_option(dpp::command_option_type::co_string, "footer_text", "Fußzeilen-Test", false))
|
||||
.add_option(dpp::command_option(dpp::command_option_type::co_string, "footer_image", "Fußzeilen-Bild", false))), [&](const dpp::slashcommand_t& event) {
|
||||
// Get color
|
||||
unsigned color = Util::str_to_color(strOrEmpty(event.get_parameter("color")));
|
||||
// Generate embed
|
||||
dpp::embed embed;
|
||||
embed.set_title(strOrEmpty(event.get_parameter("title")))
|
||||
.set_description(strOrEmpty(event.get_parameter("description")))
|
||||
.set_image(strOrEmpty(event.get_parameter("image")))
|
||||
.set_video(strOrEmpty(event.get_parameter("video")))
|
||||
.set_thumbnail(strOrEmpty(event.get_parameter("thumbnail")))
|
||||
.set_color(color!=-1?color:0xffffff)
|
||||
.set_footer(strOrEmpty(event.get_parameter("footer_text")), strOrEmpty(event.get_parameter("footer_image")));
|
||||
// Send embed
|
||||
bot->cluster.message_create(dpp::message().set_channel_id(event.command.channel_id).add_embed(embed));
|
||||
// Report success
|
||||
event.reply(dpp::message(std::string("Das Embed wurde erstellt!\n")
|
||||
+(color==-1?"**Achtung:** Die Angegebene Farbe wurde nicht erkannt! Versuche es mit einem Farbcode erneut.":"")).set_flags(dpp::message_flags::m_ephemeral));
|
||||
});
|
||||
}
|
||||
};
|
||||
BOT_ADD_MODULE(Embedmaker);
|
Loading…
Add table
Reference in a new issue