Skip to content

Commit

Permalink
[0.1.2.386]: Fix done!
Browse files Browse the repository at this point in the history
- Finally free bug!
  • Loading branch information
harshfeudal committed Oct 25, 2022
1 parent 4835b81 commit cfccb76
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Raiden Shogun.rc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <Winver.h>

#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
Expand Down
2 changes: 1 addition & 1 deletion handler/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ std::map<std::string, commandDef> commands

void SlashCommandCreate(dpp::cluster& client)
{
if (dpp::run_once<struct bulk_register>())
if (dpp::run_once<struct register_commands>())
{
std::vector<dpp::slashcommand> slashCmds;

Expand Down
3 changes: 3 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ project "Raiden Shogun"
filter "configurations:Release"
runtime "Release"
optimize "on"

filter("toolset:msc")
linkoptions("/FORCE:MULTIPLE")

111 changes: 110 additions & 1 deletion src/ban.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,118 @@
#include <harshfeudal/shorten.h>

#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<dpp::snowflake>(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<std::string>(tgtReason))
{
std::string b_Reason = std::get<std::string>(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)
);
}
64 changes: 29 additions & 35 deletions src/kick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#include "../commands/kick.h"

void kick(dpp::cluster& client, const dpp::slashcommand_t& event)
{
auto usr = std::get<dpp::snowflake>(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<dpp::snowflake>(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())
Expand All @@ -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
Expand All @@ -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)
{
Expand All @@ -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<std::string>(tgtReason))
{
std::string k_Reason = "No kick reason provided";
}

try

if (std::holds_alternative<std::string>(tgtReason))
{
std::string k_Reason = std::get<std::string>(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,
Expand All @@ -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;
}
Expand All @@ -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)
);
}
}
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -59,7 +59,7 @@ int main()
{
ButtonHandle(event);
});

client.start(false);
return 0;
}

0 comments on commit cfccb76

Please sign in to comment.