Skip to content

Commit

Permalink
Add option to allow non-owners to send commands over Discord.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Nov 14, 2023
1 parent c5c6080 commit f2727ae
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions SerialPrograms/Source/CommonFramework/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace PokemonAutomation{

const bool IS_BETA_VERSION = true;
const int PROGRAM_VERSION_MAJOR = 0;
const int PROGRAM_VERSION_MINOR = 42;
const int PROGRAM_VERSION_PATCH = 7;
const int PROGRAM_VERSION_MINOR = 43;
const int PROGRAM_VERSION_PATCH = 1;

const std::string PROGRAM_VERSION_BASE =
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ DiscordIntegrationSettingsOption::DiscordIntegrationSettingsOption()
LockMode::LOCK_WHILE_RUNNING,
"", "123456789012345678"
)
, allow_buttons_from_users(
"<b>Allow Buttons from Users:</b><br>Allow other users to issue button presses.",
LockMode::LOCK_WHILE_RUNNING,
false
)
{
PA_ADD_OPTION(run_on_start);
PA_ADD_OPTION(library0);
Expand All @@ -105,6 +110,7 @@ DiscordIntegrationSettingsOption::DiscordIntegrationSettingsOption()
PA_ADD_OPTION(hello_message);
PA_ADD_OPTION(sudo);
PA_ADD_OPTION(owner);
PA_ADD_OPTION(allow_buttons_from_users);
PA_ADD_OPTION(channels);

DiscordIntegrationSettingsOption::value_changed();
Expand Down Expand Up @@ -132,6 +138,7 @@ void DiscordIntegrationSettingsOption::value_changed(){
use_suffix.set_visibility(state);
sudo.set_visibility(state);
owner.set_visibility(state);
allow_buttons_from_users.set_visibility(ConfigOptionState::HIDDEN);
break;
}
#endif
Expand All @@ -145,6 +152,7 @@ void DiscordIntegrationSettingsOption::value_changed(){
token.set_visibility(state);
game_status.set_visibility(state);
hello_message.set_visibility(state);
allow_buttons_from_users.set_visibility(state);

command_prefix.set_visibility(state);
use_suffix.set_visibility(ConfigOptionState::HIDDEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DiscordIntegrationSettingsOption : public GroupOption, private ConfigOptio
StringOption hello_message;
StringOption sudo;
StringOption owner;
BooleanCheckBoxOption allow_buttons_from_users;
DiscordIntegrationTable channels;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void Handler::create_unified_commands(commandhandler& handler) {
},
[&handler, this](const std::string& command, const parameter_list_t& params, command_source src) {
log_dpp("Executing " + command + "...", "Unified Command Handler", ll_info);
if (src.issuer.id != owner.id) {
if (!GlobalSettings::instance().DISCORD.integration.allow_buttons_from_users && src.issuer.id != owner.id) {
handler.reply(message("You do not have permission to use this command."), src);
return;
}
Expand Down Expand Up @@ -258,7 +258,7 @@ void Handler::create_unified_commands(commandhandler& handler) {
},
[&handler, this](const std::string& command, const parameter_list_t& params, command_source src) {
log_dpp("Executing " + command + "...", "Unified Command Handler", ll_info);
if (src.issuer.id != owner.id) {
if (!GlobalSettings::instance().DISCORD.integration.allow_buttons_from_users && src.issuer.id != owner.id) {
handler.reply(message("You do not have permission to use this command."), src);
return;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ void Handler::create_unified_commands(commandhandler& handler) {
},
[&handler, this](const std::string& command, const parameter_list_t& params, command_source src) {
log_dpp("Executing " + command + "...", "Unified Command Handler", ll_info);
if (src.issuer.id != owner.id) {
if (!GlobalSettings::instance().DISCORD.integration.allow_buttons_from_users && src.issuer.id != owner.id) {
handler.reply(message("You do not have permission to use this command."), src);
return;
}
Expand Down Expand Up @@ -320,7 +320,7 @@ void Handler::create_unified_commands(commandhandler& handler) {
},
[&handler, this](const std::string& command, const parameter_list_t& params, command_source src) {
log_dpp("Executing " + command + "...", "Unified Command Handler", ll_info);
if (src.issuer.id != owner.id) {
if (!GlobalSettings::instance().DISCORD.integration.allow_buttons_from_users && src.issuer.id != owner.id) {
handler.reply(message("You do not have permission to use this command."), src);
return;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ void Handler::create_unified_commands(commandhandler& handler) {
},
[&handler, this](const std::string& command, const parameter_list_t& params, command_source src) {
log_dpp("Executing " + command + "...", "Unified Command Handler", ll_info);
if (src.issuer.id != owner.id) {
if (!GlobalSettings::instance().DISCORD.integration.allow_buttons_from_users && src.issuer.id != owner.id) {
handler.reply(message("You do not have permission to use this command."), src);
return;
}
Expand Down Expand Up @@ -447,7 +447,7 @@ void Handler::create_unified_commands(commandhandler& handler) {
},
[&handler, this](const std::string& command, const parameter_list_t& params, command_source src) {
log_dpp("Executing " + command + "...", "Unified Command Handler", ll_info);
if (src.issuer.id != owner.id) {
if (!GlobalSettings::instance().DISCORD.integration.allow_buttons_from_users && src.issuer.id != owner.id) {
handler.reply(message("You do not have permission to use this command."), src);
return;
}
Expand Down Expand Up @@ -511,7 +511,7 @@ void Handler::create_unified_commands(commandhandler& handler) {
},
[&handler, this](const std::string& command, const parameter_list_t& params, command_source src) {
log_dpp("Executing " + command + "...", "Unified Command Handler", ll_info);
if (src.issuer.id != owner.id) {
if (!GlobalSettings::instance().DISCORD.integration.allow_buttons_from_users && src.issuer.id != owner.id) {
handler.reply(message("You do not have permission to use this command."), src);
return;
}
Expand Down Expand Up @@ -569,7 +569,9 @@ void Handler::create_unified_commands(commandhandler& handler) {
for (auto& cmd : commands) {
std::string name = cmd.first;
log_dpp(name, "help command", ll_info);
if (src.issuer.id != owner.id && name != "hi" && name != "ping" && name != "about" && name != "status" && name != "help") {
if (!GlobalSettings::instance().DISCORD.integration.allow_buttons_from_users &&
src.issuer.id != owner.id && name != "hi" && name != "ping" && name != "about" && name != "status" && name != "help"
){
continue;
}

Expand Down

0 comments on commit f2727ae

Please sign in to comment.