diff --git a/README.md b/README.md index fce9387..0b2bb94 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ These are libraries that we're using in this project: - [Spdlog](https://github.com/gabime/spdlog) - version `1.10.0` (latest) Bot current version: -- BETA version - `0.1.2.378` (`Release`) +- BETA version - `0.1.2.386` (`Release`) - Stable version - `Unknown` ### 🚨 Generate and use diff --git a/Raiden Shogun.rc b/Raiden Shogun.rc index f6db57e..338561a 100644 --- a/Raiden Shogun.rc +++ b/Raiden Shogun.rc @@ -1,11 +1,11 @@ #include -#define FILEVERSION_STR "0.1.2.378" -#define PRODUCTVERSION_STR "0.1.2.378" +#define FILEVERSION_STR "0.1.2.386" +#define PRODUCTVERSION_STR "0.1.2.386" VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,1,2,378 - PRODUCTVERSION 0,1,2,378 + FILEVERSION 0,1,2,386 + PRODUCTVERSION 0,1,2,386 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK #ifdef _DEBUG FILEFLAGS VS_FF_DEBUG diff --git a/handler/builder.h b/handler/builder.h index 17378eb..4337d26 100644 --- a/handler/builder.h +++ b/handler/builder.h @@ -73,7 +73,7 @@ std::map commands void SlashCommandCreate(dpp::cluster& client) { - if (dpp::run_once()) + if (dpp::run_once()) { std::vector slashCmds; diff --git a/premake5.lua b/premake5.lua index 23788f0..8836956 100644 --- a/premake5.lua +++ b/premake5.lua @@ -46,4 +46,7 @@ project "Raiden Shogun" filter "configurations:Release" runtime "Release" optimize "on" + + filter("toolset:msc") + linkoptions("/FORCE:MULTIPLE") \ No newline at end of file diff --git a/src/ban.cpp b/src/ban.cpp index 7d80f8c..a0fe69a 100644 --- a/src/ban.cpp +++ b/src/ban.cpp @@ -2,9 +2,118 @@ #include #include "../handler/handler.h" +#include "../handler/btnHandler.h" #include "../commands/ban.h" void ban(dpp::cluster& client, const dpp::slashcommand_t& event) { - // Working in progress ... + auto usr = std::get(event.get_parameter("member")); + auto tgtReason = event.get_parameter("reason"); + + auto source = event.command.usr.id; + auto gFind = dpp::find_guild(event.command.guild_id); + auto tgtGuild = event.command.guild_id; + auto tgtChannel = event.command.channel_id; + + const auto tgtUser = gFind->members.find(usr); + + if (tgtUser == gFind->members.end()) + { + harshfeudal::SlashMessageReply( + event, "Member not found!", dpp::m_ephemeral, NO_MSG_TYPE + ); + + return; + } + + if (gFind == nullptr) + { + harshfeudal::SlashMessageReply( + event, "Guild not found!", dpp::m_ephemeral, NO_MSG_TYPE + ); + + return; + } + + if (!gFind->base_permissions(event.command.member).has(dpp::p_ban_members)) + { + harshfeudal::SlashMessageReply( + event, "You have lack of permission to ban", dpp::m_ephemeral, NO_MSG_TYPE + ); + + return; + } + + auto b_Component = dpp::component().set_label("Ban") + .set_type(dpp::cot_button) + .set_style(dpp::cos_danger) + .set_id("b_Id"); + + auto cnl_Component = dpp::component().set_label("Cancel") + .set_type(dpp::cot_button) + .set_style(dpp::cos_secondary) + .set_id("b_cnl_Id"); + + ButtonBind(b_Component, [&client, tgtGuild, tgtReason, usr, source](const dpp::button_click_t& event) + { + if (source != event.command.usr.id) + { + return false; + } + + std::string bContent = fmt::format("<@{}> has been banned!", usr); + + if (std::holds_alternative(tgtReason)) + { + std::string b_Reason = std::get(tgtReason); + client.set_audit_reason(b_Reason); + } + else + { + std::string b_Reason = "No reason provided"; + client.set_audit_reason(b_Reason); + } + + client.guild_ban_add(tgtGuild, usr); + + event.reply( + dpp::interaction_response_type::ir_update_message, + dpp::message().set_flags(dpp::m_ephemeral) + .set_content(bContent) + ); + + return true; + }); + + ButtonBind(cnl_Component, [source](const dpp::button_click_t& event) + { + std::string cnlContent = "Cancelled request!"; + + if (source != event.command.usr.id) + { + return false; + } + + event.reply( + dpp::interaction_response_type::ir_update_message, + dpp::message().set_flags(dpp::m_ephemeral) + .set_content(cnlContent) + ); + + return true; + }); + + dpp::message b_Confirm( + fmt::format("Do you want to ban <@{}>? Press the button below to confirm", usr) + ); + + b_Confirm.add_component( + dpp::component().add_component(b_Component) + .add_component(cnl_Component) + ); + + event.reply( + b_Confirm.set_flags(dpp::m_ephemeral) + .set_channel_id(tgtChannel) + ); } \ No newline at end of file diff --git a/src/kick.cpp b/src/kick.cpp index 90a14e3..ed4dfc8 100644 --- a/src/kick.cpp +++ b/src/kick.cpp @@ -6,12 +6,15 @@ #include "../commands/kick.h" void kick(dpp::cluster& client, const dpp::slashcommand_t& event) -{ - auto usr = std::get(event.get_parameter("member")); - auto tgtReason = event.get_parameter("reason"); - auto source = event.command.usr.id; - auto gFind = dpp::find_guild(event.command.guild_id); - auto tgtGuild = event.command.guild_id; +{ + auto usr = std::get(event.get_parameter("member")); + auto tgtReason = event.get_parameter("reason"); + + auto source = event.command.usr.id; + auto gFind = dpp::find_guild(event.command.guild_id); + auto tgtGuild = event.command.guild_id; + auto tgtChannel = event.command.channel_id; + const auto tgtUser = gFind->members.find(usr); if (tgtUser == gFind->members.end()) @@ -23,7 +26,7 @@ void kick(dpp::cluster& client, const dpp::slashcommand_t& event) return; } - if (gFind == nullptr) + if (gFind == nullptr) { harshfeudal::SlashMessageReply( event, "Guild not found!", dpp::m_ephemeral, NO_MSG_TYPE @@ -40,17 +43,16 @@ void kick(dpp::cluster& client, const dpp::slashcommand_t& event) return; } - - // Working in progress ... - auto k_Component = dpp::component().set_label("Kick") - .set_type(dpp::cot_button) - .set_style(dpp::cos_danger) - .set_id("k_Id"); + + auto k_Component = dpp::component().set_label("Kick") + .set_type(dpp::cot_button) + .set_style(dpp::cos_danger) + .set_id("k_Id"); auto cnl_Component = dpp::component().set_label("Cancel") .set_type(dpp::cot_button) .set_style(dpp::cos_secondary) - .set_id("cnl_Id"); + .set_id("k_cnl_Id"); ButtonBind(k_Component, [&client, tgtGuild, tgtReason, usr, source](const dpp::button_click_t& event) { @@ -60,27 +62,19 @@ void kick(dpp::cluster& client, const dpp::slashcommand_t& event) } std::string kContent = fmt::format("<@{}> has been kicked!", usr); - - if (!std::holds_alternative(tgtReason)) - { - std::string k_Reason = "No kick reason provided"; - } - - try + + if (std::holds_alternative(tgtReason)) { std::string k_Reason = std::get(tgtReason); - - client.set_audit_reason(k_Reason) - .guild_member_kick_sync(tgtGuild, usr); + client.set_audit_reason(k_Reason); } - catch (dpp::rest_exception& exception) + else { - event.reply( - dpp::interaction_response_type::ir_update_message, - dpp::message().set_flags(dpp::m_ephemeral) - .set_content("User not found!") - ); + std::string k_Reason = "No reason provided"; + client.set_audit_reason(k_Reason); } + + client.guild_member_kick(tgtGuild, usr); event.reply( dpp::interaction_response_type::ir_update_message, @@ -90,12 +84,12 @@ void kick(dpp::cluster& client, const dpp::slashcommand_t& event) return true; }); - - ButtonBind(cnl_Component, [source](const dpp::button_click_t& event) + + ButtonBind(cnl_Component, [source](const dpp::button_click_t& event) { std::string cnlContent = "Cancelled request!"; - if (source != event.command.usr.id) + if (source != event.command.usr.id) { return false; } @@ -120,6 +114,6 @@ void kick(dpp::cluster& client, const dpp::slashcommand_t& event) event.reply( k_Confirm.set_flags(dpp::m_ephemeral) - .set_channel_id(event.command.channel_id) + .set_channel_id(tgtChannel) ); -} +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index aba10a5..dc798d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,11 +34,11 @@ int main() client.on_ready([&client](const dpp::ready_t& event) { - SlashCommandCreate(client); - client.set_presence( dpp::presence(dpp::ps_dnd, dpp::at_game, "Genshin Impact") ); + + SlashCommandCreate(client); fmt::print("[{} - STARTED]: {} is online!\n", dpp::utility::current_date_time(), client.me.username); fmt::print("[{} - REGISTERED]: Successfully registered slash commands!\n", dpp::utility::current_date_time()); @@ -59,7 +59,7 @@ int main() { ButtonHandle(event); }); - + client.start(false); return 0; }