Skip to content

Commit 6efbe5f

Browse files
committed
add fields nsfw,integration_types, contexts, handler. remove deprecated dm_permission
1 parent 8719a93 commit 6efbe5f

File tree

3 files changed

+83
-14
lines changed

3 files changed

+83
-14
lines changed

Discord.C++/ApplicationCommand.cpp

+30-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@ DiscordCPP::ApplicationCommand::ApplicationCommand(const json& data, const std::
1313

1414
name = data.at("name").get<std::string>();
1515
description = data.at("description").get<std::string>();
16-
dm_permission = get_or_else<bool>(data, "dm_permission", true);
16+
nsfw = get_or_else<bool>(data, "nsfw", false);
1717
version = data.at("version").get<std::string>();
1818

19+
if (has_value(data, "integration_types")) {
20+
for (const json& integration_type : data.at("integration_types")) {
21+
integration_types.push_back(static_cast<DiscordCPP::ApplicationCommand::IntegrationType>(integration_type.get<int>()));
22+
}
23+
}
24+
25+
if (has_value(data, "contexts")) {
26+
for (const json& context : data.at("contexts")) {
27+
contexts.push_back(static_cast<DiscordCPP::ApplicationCommand::ContextType>(context.get<int>()));
28+
}
29+
}
30+
31+
if (has_value(data, "handler")) {
32+
handler = static_cast<DiscordCPP::ApplicationCommand::HandlerType>(data.at("handler").get<int>());
33+
}
34+
1935
if (has_value(data, "options")) {
2036
for (const json& option : data.at("options")) {
2137
options.push_back(DiscordCPP::ApplicationCommandOptionHelper::application_command_option_from_json(option));
@@ -28,7 +44,19 @@ json DiscordCPP::ApplicationCommand::to_json() {
2844
data["type"] = type;
2945
data["name"] = name;
3046
data["description"] = description;
31-
data["dm_permission"] = dm_permission;
47+
data["nsfw"] = nsfw;
48+
49+
for (auto& integration_type : integration_types) {
50+
data["integration_types"].push_back(integration_type);
51+
}
52+
53+
for (auto& context : contexts) {
54+
data["contexts"].push_back(context);
55+
}
56+
57+
if (handler.has_value()) {
58+
data["handler"] = handler.value();
59+
}
3260

3361
for (auto& option : options) {
3462
data["options"].push_back(std::visit([](auto v) { return v.to_json(); }, option));

Discord.C++/ApplicationCommand.h

+43-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,24 @@ class ApplicationCommand : public DiscordObject {
1414
enum Type {
1515
CHAT_INPUT = 1,
1616
USER = 2,
17-
MESSAGE = 3
17+
MESSAGE = 3,
18+
PRIMARY_ENTRY_POINT = 4
19+
};
20+
21+
enum IntegrationType {
22+
GUILD_INSTALL = 0,
23+
USER_INSTALL = 1
24+
};
25+
26+
enum ContextType {
27+
GUILD = 0,
28+
BOT_DM = 1,
29+
PRIVATE_CHANNEL = 2
30+
};
31+
32+
enum HandlerType {
33+
APP_HANDLER = 1,
34+
DISCORD_LAUNCH_ACTIVITY = 2
1835
};
1936

2037
private:
@@ -33,10 +50,16 @@ class ApplicationCommand : public DiscordObject {
3350
/// Parameters for the command, max of 25.
3451
std::vector<ApplicationCommandOptionVariant> options;
3552
// default_member_permissions
36-
/// Indicates wether the command is enabled in DMs. Defaults to true.
37-
bool dm_permission = true;
53+
/// Indicates whether the command is age-restricted, defaults to false.
54+
bool nsfw = false;
55+
/// Installation contexts where the command is available, only for globally-scoped commands. Defaults to your app's configured contexts.
56+
std::vector<IntegrationType> integration_types;
57+
/// Interaction context(s) where the command can be used, only for globally-scoped commands. Defaults to all.
58+
std::vector<ContextType> contexts;
3859
/// Autoincrementing version identifier updated during substantial record changes.
3960
std::string version;
61+
/// Determines whether the interaction is handled by the app's interactions handler or by Discord. Use when type is PRIMARY_ENTRY_POINT.
62+
std::optional<HandlerType> handler;
4063

4164
public:
4265
DLL_EXPORT ApplicationCommand() = default;
@@ -59,10 +82,16 @@ class ApplicationCommand : public DiscordObject {
5982
DLL_EXPORT Type get_type() { return type; }
6083
/// @return Parameters for the command, max of 25.
6184
DLL_EXPORT std::vector<ApplicationCommandOptionVariant> get_options() { return options; }
62-
/// @return Indicates wether the command is enabled in DMs. Defaults to true.
63-
DLL_EXPORT bool has_dm_permission() { return dm_permission; }
85+
/// @return Indicates whether the command is age-restricted, defaults to false.
86+
DLL_EXPORT bool is_nsfw() { return nsfw; }
87+
/// @return Installation contexts where the command is available.
88+
DLL_EXPORT std::vector<IntegrationType> get_integration_types() { return integration_types; }
89+
/// @return Interaction context(s) where the command can be used.
90+
DLL_EXPORT std::vector<ContextType> get_contexts() { return contexts; }
6491
/// @return Autoincrementing version identifier updated during substantial record changes.
6592
DLL_EXPORT std::string get_version() { return version; }
93+
/// @return The handler type for PRIMARY_ENTRY_POINT.
94+
DLL_EXPORT std::optional<HandlerType> get_handler() { return handler; }
6695

6796
/// Set the guild of the command.
6897
DLL_EXPORT void set_guild_id(std::string guild_id) { this->guild_id.emplace(guild_id); }
@@ -74,7 +103,13 @@ class ApplicationCommand : public DiscordObject {
74103
DLL_EXPORT void set_type(Type type) { this->type = type; }
75104
/// Add parameters for the command, max of 25.
76105
DLL_EXPORT void add_option(ApplicationCommandOptionVariant option) { options.push_back(option); }
77-
/// Set indicator wether the command is enabled in DMs.
78-
DLL_EXPORT void set_dm_permission(bool dm_permission) { this->dm_permission = dm_permission; }
106+
/// Set whether the command is age-restricted, defaults to false.
107+
DLL_EXPORT void set_nsfw(bool nsfw) { this->nsfw = nsfw; }
108+
/// Add installation context where the command is available.
109+
DLL_EXPORT void add_integration_types(IntegrationType integration_type) { integration_types.push_back(integration_type); }
110+
/// Add interaction context where the command can be used.
111+
DLL_EXPORT void add_contexts(ContextType context) { contexts.push_back(context); }
112+
/// Set the handler type for PRIMARY_ENTRY_POINT.
113+
DLL_EXPORT void get_handler(HandlerType handler) { this->handler.emplace(handler); }
79114
};
80-
} // namespace DiscordCPP
115+
} // namespace DiscordCPP

test_bot/main.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <thread>
33
#include <vector>
44

5+
#include "ApplicationCommand.h"
6+
57
#ifndef _WIN32
68
#include <cstdlib>
79
#endif
@@ -53,12 +55,18 @@ class Client : public Discord {
5355
ping.set_name("ping");
5456
ping.set_description("Ping the bot");
5557
ping.set_type(ApplicationCommand::Type::CHAT_INPUT);
58+
ping.add_integration_types(ApplicationCommand::IntegrationType::GUILD_INSTALL);
59+
ping.add_integration_types(ApplicationCommand::IntegrationType::USER_INSTALL);
60+
ping.add_contexts(ApplicationCommand::ContextType::BOT_DM);
61+
ping.add_contexts(ApplicationCommand::ContextType::PRIVATE_CHANNEL);
5662
create_application_command(ping);
5763

5864
ApplicationCommand update = ApplicationCommand();
5965
update.set_name("update");
6066
update.set_description("Responds with a message and updates it after 5 seconds");
6167
update.set_type(ApplicationCommand::Type::CHAT_INPUT);
68+
update.add_integration_types(ApplicationCommand::IntegrationType::GUILD_INSTALL);
69+
update.add_contexts(ApplicationCommand::ContextType::GUILD);
6270
create_application_command(update);
6371

6472
ApplicationCommand msg = ApplicationCommand();
@@ -103,13 +111,11 @@ class Client : public Discord {
103111
}
104112

105113
void on_user_ban(User user, Guild guild) override {
106-
log.info("User " + string(user) + " has been banned from Guild " +
107-
string(guild));
114+
log.info("User " + string(user) + " has been banned from Guild " + string(guild));
108115
}
109116

110117
void on_user_unban(User user, Guild guild) override {
111-
log.info("User " + string(user) + " has been unbanned from Guild " +
112-
string(guild));
118+
log.info("User " + string(user) + " has been unbanned from Guild " + string(guild));
113119
}
114120

115121
void on_user_join(Member member, Guild guild) override {

0 commit comments

Comments
 (0)