Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gdm_add and gdm_remove #5

Merged
merged 2 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ class cluster {
/** Get a channel's pins */
void pins_get(snowflake channel_id, command_completion_event_t callback);

/** Adds a recipient to a Group DM using their access token */
void gdm_add(snowflake channel_id, snowflake user_id, const std::string &access_token, const std::string &nick, command_completion_event_t callback);

/** Removes a recipient from a Group DM */
void gdm_remove(snowflake channel_id, snowflake user_id, command_completion_event_t callback);

/** Get a guild */
void guild_get(snowflake g, command_completion_event_t callback);

Expand Down
25 changes: 22 additions & 3 deletions src/dpp/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,28 @@ void cluster::pins_get(snowflake channel_id, command_completion_event_t callback
for (auto & curr_message : j) {
pins_messages[SnowflakeNotNull(&curr_message, "id")] = message().fill_from_json(&curr_message);
}
if (callback) {
callback(confirmation_callback_t("message_map", pins_messages, http));
}
if (callback) {
callback(confirmation_callback_t("message_map", pins_messages, http));
}
});
}

void cluster::gdm_add(snowflake channel_id, snowflake user_id, const std::string &access_token, const std::string &nick, command_completion_event_t callback) {
json j;
j["access_token"] = access_token;
j["nick"] = nick;
this->post_rest("/api/channels", std::to_string(channel_id) + "/recipients/" + std::to_string(user_id), m_put, j.dump(), [callback](json &j, const http_request_completion_t& http) {
if (callback) {
callback(confirmation_callback_t("confirmation", confirmation(), http));
}
});
}

void cluster::gdm_remove(snowflake channel_id, snowflake user_id, command_completion_event_t callback) {
this->post_rest("/api/channels", std::to_string(channel_id) + "/recipients/" + std::to_string(user_id), m_delete, "", [callback](json &j, const http_request_completion_t& http) {
if (callback) {
callback(confirmation_callback_t("confirmation", confirmation(), http));
}
});
}

Expand Down