11#ifdef PA_DPP
22
33#include < format>
4+ #include < unordered_set>
45#include " Common/Cpp/Concurrency/ScheduledTaskRunner.h"
56#include " CommonFramework/Globals.h"
6- #include " CommonFramework/GlobalSettingsPanel.h"
77#include " CommonFramework/Notifications/MessageAttachment.h"
88#include " Integrations/IntegrationsAPI.h"
99#include " Integrations/DiscordSettingsOption.h"
@@ -37,7 +37,7 @@ void Handler::initialize(cluster& bot, commandhandler& handler){
3737 if (cmd_type == DiscordIntegrationSettingsOption::CommandType::MessageCommands && !prefix.empty ()){
3838 handler.add_prefix (prefix);
3939 }else {
40- handler.add_prefix (" /" ). add_prefix ( " _cmd " ) ;
40+ handler.add_prefix (" /" );
4141 }
4242
4343 bot.on_ready ([&bot, &handler, this ](const ready_t &){
@@ -53,6 +53,13 @@ void Handler::initialize(cluster& bot, commandhandler& handler){
5353 log_dpp (" Application Name: " + app.name , " Current App" , ll_info);
5454 log_dpp (" Application ID: " + std::to_string (app.id ), " Current App" , ll_info);
5555 owner = app.owner ;
56+ bot.set_presence (
57+ presence (
58+ presence_status::ps_online,
59+ activity_type::at_game,
60+ (std::string)GlobalSettings::instance ().DISCORD ->integration .game_status
61+ )
62+ );
5663 });
5764#else
5865 log_dpp (" Logged in as: " + bot.current_user_get_sync ().format_username () + " ." , " Ready" , ll_info);
@@ -76,48 +83,18 @@ void Handler::initialize(cluster& bot, commandhandler& handler){
7683 }
7784 });
7885
79- bot.on_guild_member_add ([this ](const guild_member_add_t & event){
80- #if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0)
81- std::string id = std::to_string (event.adding_guild .id );
82- if (!user_counts.empty () && user_counts.count (id)){
83- log_dpp (" New member joined " + event.adding_guild .name + " . Incrementing member count." , " Guild Member Add" , ll_info);
84- user_counts.at (id)++;
85- }
86- #else
87- std::string id = std::to_string (event.adding_guild ->id );
88- if (!user_counts.empty () && user_counts.count (id)){
89- log_dpp (" New member joined " + event.adding_guild ->name + " . Incrementing member count." , " Guild Member Add" , ll_info);
90- user_counts.at (id)++;
91- }
92- #endif
93- });
94-
95- bot.on_guild_member_remove ([this ](const guild_member_remove_t & event){
96- #if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0)
97- std::string id = std::to_string (event.removing_guild .id );
98- if (!user_counts.empty () && user_counts.count (id)){
99- log_dpp (" Member left " + event.removing_guild .name + " . Decrementing member count." , " Guild Member Remove" , ll_info);
100- user_counts.at (id)--;
101- }
102- #else
103- std::string id = std::to_string (event.removing_guild ->id );
104- if (!user_counts.empty () && user_counts.count (id)){
105- log_dpp (" Member left " + event.removing_guild ->name + " . Decrementing member count." , " Guild Member Remove" , ll_info);
106- user_counts.at (id)--;
107- }
108- #endif
109- });
110-
111- bot.on_message_create ([&handler](const message_create_t & event){
112- std::string content = event.msg .content ;
113- if (!event.msg .author .is_bot () && handler.string_has_prefix (content)){
114- auto channels = GlobalSettings::instance ().DISCORD ->integration .channels .command_channels ();
115- auto channel = std::find (channels.begin (), channels.end (), std::to_string (event.msg .channel_id ));
116- if (channel != channels.end ()){
117- handler.route (event);
86+ if (cmd_type == DiscordIntegrationSettingsOption::CommandType::MessageCommands){
87+ bot.on_message_create ([&handler](const message_create_t & event){
88+ std::string content = event.msg .content ;
89+ if (!event.msg .author .is_bot () && handler.string_has_prefix (content)){
90+ auto channels = GlobalSettings::instance ().DISCORD ->integration .channels .command_channels ();
91+ auto channel = std::find (channels.begin (), channels.end (), std::to_string (event.msg .channel_id ));
92+ if (channel != channels.end ()){
93+ handler.route (event);
94+ }
11895 }
119- }
120- });
96+ });
97+ }
12198
12299 bot.on_slashcommand ([&handler](const slashcommand_t & event){
123100 if (!event.command .usr .is_bot () && handler.slash_commands_enabled ){
@@ -611,65 +588,65 @@ void Handler::create_unified_commands(commandhandler& handler){
611588 embed embed;
612589 embed.set_color ((uint32_t )color).set_title (" Command List" );
613590
591+ static const std::unordered_set<std::string> base_commands{
592+ " hi" , " ping" , " about" , " status" , " help"
593+ };
594+ static const std::unordered_set<std::string> button_commands{
595+ " click" , " joystick"
596+ };
597+
598+ std::unordered_set<std::string> allowed = base_commands;
599+ if (GlobalSettings::instance ().DISCORD ->integration .allow_buttons_from_users ){
600+ allowed.insert (button_commands.begin (), button_commands.end ());
601+ }
602+
614603 auto & commands = handler.commands ;
615604 for (auto & cmd : commands){
616- std::string name = cmd.first ;
617- log_dpp (name, " help command" , ll_info);
618- if (!GlobalSettings::instance ().DISCORD ->integration .allow_buttons_from_users &&
619- src.issuer .id != owner.id && name != " hi" && name != " ping" && name != " about" && name != " status" && name != " help"
620- ){
605+ const std::string& cmd_name = cmd.first ;
606+ if (src.issuer .id != owner.id && allowed.find (cmd_name) == allowed.end ()){
621607 continue ;
622608 }
623609
624- std::string param_info;
625- for (auto & param : cmd.second .parameters ){
626- param_info += (" \n **- " + param.first + " ** - " + param.second .description );
610+ auto & params = cmd.second .parameters ;
611+ std::string signature;
612+ if (!params.empty ()){
613+ signature = cmd_name + " (" ;
614+ for (size_t i = 0 ; i < params.size (); ++i){
615+ signature += params[i].first ;
616+ if (i + 1 < params.size ()){
617+ signature += " , " ;
618+ }
619+ }
620+ signature += " )" ;
621+ }else {
622+ signature = cmd_name;
623+ }
624+
625+ std::string param_details;
626+ for (auto & param : params){
627+ param_details += (" \n -" + param.first + " : " + param.second .description );
627628 if (!param.second .choices .empty ()){
628- param_info += " (" ;
629- for (auto & choice : param.second .choices ){
630- param_info += (choice.second + " , " );
629+ std::string choices;
630+ for (auto & c : param.second .choices ){
631+ choices += c.second + " , " ;
632+ }
633+ if (!choices.empty ()){
634+ choices = choices.substr (0 , choices.size () - 2 );
631635 }
632- param_info = param_info.substr (0 , param_info.size () - 2 );
633- param_info += " )" ;
636+ param_details += " (" + choices + " )" ;
634637 }
635638 }
636- embed.add_field (name, param_info );
639+ embed.add_field (signature, param_details );
637640 }
638641 embed_footer footer;
639642 footer.set_text (" Commands are case-sensitive!" );
640643 embed.set_footer (footer);
641644 message.add_embed (embed);
642645 handler.reply (message, src);
643646 },
644- " View the command list." )
645-
646- .add_command (
647- " register" ,
648- {},
649- [&handler, this ](const std::string& command, const parameter_list_t &, command_source src){
650- log_dpp (" Executing " + command + " ..." , " Unified Command Handler" , ll_info);
651- if (src.issuer .id != owner.id ){
652- handler.reply (message (" You do not have permission to use this command." ), src);
653- return ;
654- }
655-
656- if (handler.slash_commands_enabled ){
657- handler.thinking (src);
658- log_dpp (" Registering commands." , " Command Registration" , ll_info);
659- handler.register_commands ();
660-
661- embed embed;
662- std::string desc = " Slash commands registered! Restart your Discord client or wait a few minutes for them to show up!" ;
663- embed.set_color ((uint32_t )color).set_description (desc).set_title (" Slash Command Registration" );
664- Handler::update_response (src, embed, " " , nullptr );
665- }else {
666- handler.reply (message (" Enable slash commands before registering them." ), src);
667- }
668- },
669- " Register global slash commands. For first-time slash command use and for updating commands." );
647+ " View the command list." );
670648}
671649
672-
673650}
674651}
675652}
0 commit comments