mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2026-12-01 08:07:08 +01:00
Update WIP discord and some vendors.
CPR has features disabled and PCRE is fully disabled until updated to new code.
This commit is contained in:
1 parent
e0761bf3b9
commit
9298065cef
1562 files changed
+55070
-76299
No files matched your search
Vendored
+6
-22
@@ -94,36 +94,20 @@ application& application::fill_from_json(nlohmann::json* j) {
|
||||
}
|
||||
|
||||
std::string application::get_cover_image_url(uint16_t size, const image_type format) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->cover_image.to_string().empty() && this->id) {
|
||||
return utility::cdn_host + "/app-icons/" + std::to_string(this->id) + "/" + this->cover_image.to_string() + "." + extensions.find(format)->second + utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp },
|
||||
"app-icons/" + std::to_string(this->id) + "/" + this->cover_image.to_string(),
|
||||
format, size);
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
std::string application::get_icon_url(uint16_t size, const image_type format) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->icon.to_string().empty() && this->id) {
|
||||
return utility::cdn_host + "/app-icons/" + std::to_string(this->id) + "/" + this->icon.to_string() + "." + extensions.find(format)->second + utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp },
|
||||
"app-icons/" + std::to_string(this->id) + "/" + this->icon.to_string(),
|
||||
format, size);
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Vendored
+43
-37
@@ -26,45 +26,51 @@ namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
audit_entry::audit_entry(): type(aut_guild_update) {
|
||||
}
|
||||
|
||||
audit_entry &audit_entry::fill_from_json(nlohmann::json *j) {
|
||||
this->id = snowflake_not_null(j, "id");
|
||||
this->type = (audit_type)int8_not_null(j, "action_type");
|
||||
this->user_id = snowflake_not_null(j, "user_id");
|
||||
this->target_id = snowflake_not_null(j, "target_id");
|
||||
this->reason = string_not_null(j, "reason");
|
||||
if (j->contains("changes")) {
|
||||
auto &c = (*j)["changes"];
|
||||
for (auto & change : c) {
|
||||
audit_change ac;
|
||||
ac.key = string_not_null(&change, "key");
|
||||
if (change.find("new_value") != change.end()) {
|
||||
ac.new_value = change["new_value"].dump();
|
||||
}
|
||||
if (change.find("old_value") != change.end()) {
|
||||
ac.old_value = change["old_value"].dump();
|
||||
}
|
||||
this->changes.push_back(ac);
|
||||
}
|
||||
}
|
||||
if (j->contains("options")) {
|
||||
auto &o = (*j)["options"];
|
||||
audit_extra opts;
|
||||
opts.automod_rule_name = string_not_null(&o, "auto_moderation_rule_name");
|
||||
opts.automod_rule_trigger_type = string_not_null(&o, "auto_moderation_rule_trigger_type");
|
||||
opts.channel_id = snowflake_not_null(&o, "channel_id");
|
||||
opts.count = string_not_null(&o, "count");
|
||||
opts.delete_member_days = string_not_null(&o, "delete_member_days");
|
||||
opts.id = snowflake_not_null(&o, "id");
|
||||
opts.members_removed = string_not_null(&o, "members_removed");
|
||||
opts.message_id = snowflake_not_null(&o, "message_id");
|
||||
opts.role_name = string_not_null(&o, "role_name");
|
||||
opts.type = string_not_null(&o, "type");
|
||||
opts.application_id = snowflake_not_null(&o, "application_id");
|
||||
this->extra = opts;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
auditlog& auditlog::fill_from_json(nlohmann::json* j) {
|
||||
for (auto &ai : (*j)["audit_log_entries"]) {
|
||||
audit_entry ae;
|
||||
ae.id = snowflake_not_null(&ai, "id");
|
||||
ae.type = (audit_type)int8_not_null(&ai, "action_type");
|
||||
ae.user_id = snowflake_not_null(&ai, "user_id");
|
||||
ae.target_id = snowflake_not_null(&ai, "target_id");
|
||||
ae.reason = string_not_null(&ai, "reason");
|
||||
if (ai.contains("changes")) {
|
||||
auto &c = ai["changes"];
|
||||
for (auto & change : c) {
|
||||
audit_change ac;
|
||||
ac.key = string_not_null(&change, "key");
|
||||
if (change.find("new_value") != change.end()) {
|
||||
ac.new_value = change["new_value"].dump();
|
||||
}
|
||||
if (change.find("old_value") != change.end()) {
|
||||
ac.old_value = change["old_value"].dump();
|
||||
}
|
||||
ae.changes.push_back(ac);
|
||||
}
|
||||
}
|
||||
if (ai.contains("options")) {
|
||||
auto &o = ai["options"];
|
||||
audit_extra opts;
|
||||
opts.automod_rule_name = string_not_null(&o, "auto_moderation_rule_name");
|
||||
opts.automod_rule_trigger_type = string_not_null(&o, "auto_moderation_rule_trigger_type");
|
||||
opts.channel_id = snowflake_not_null(&o, "channel_id");
|
||||
opts.count = string_not_null(&o, "count");
|
||||
opts.delete_member_days = string_not_null(&o, "delete_member_days");
|
||||
opts.id = snowflake_not_null(&o, "id");
|
||||
opts.members_removed = string_not_null(&o, "members_removed");
|
||||
opts.message_id = snowflake_not_null(&o, "message_id");
|
||||
opts.role_name = string_not_null(&o, "role_name");
|
||||
opts.type = string_not_null(&o, "type");
|
||||
opts.application_id = snowflake_not_null(&o, "application_id");
|
||||
ae.extra = opts;
|
||||
}
|
||||
this->entries.emplace_back(ae);
|
||||
this->entries.emplace_back(audit_entry().fill_from_json(&ai));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vendored
+3
-1
@@ -97,6 +97,7 @@ automod_metadata& automod_metadata::fill_from_json(nlohmann::json* j) {
|
||||
allow_list.push_back(k);
|
||||
}
|
||||
mention_total_limit = int8_not_null(j, "mention_total_limit");
|
||||
mention_raid_protection_enabled = bool_not_null(j, "mention_raid_protection_enabled");
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -119,6 +120,7 @@ std::string automod_metadata::build_json(bool with_id) const {
|
||||
j["allow_list"].push_back(v);
|
||||
}
|
||||
j["mention_total_limit"] = mention_total_limit;
|
||||
j["mention_raid_protection_enabled"] = mention_raid_protection_enabled;
|
||||
return j.dump();
|
||||
|
||||
}
|
||||
@@ -142,7 +144,7 @@ automod_rule& automod_rule::fill_from_json(nlohmann::json* j) {
|
||||
enabled = bool_not_null(j, "enabled");
|
||||
exempt_roles.clear();
|
||||
exempt_channels.clear();
|
||||
for (auto k : (*j)["automod_actions"]) {
|
||||
for (auto k : (*j)["actions"]) {
|
||||
actions.push_back(automod_action().fill_from_json(&k));
|
||||
}
|
||||
for (auto k : (*j)["exempt_roles"]) {
|
||||
|
||||
Vendored
+6
-12
@@ -27,10 +27,12 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
permission_overwrite::permission_overwrite() : id(0), allow(0), deny(0), type(0) {}
|
||||
|
||||
permission_overwrite::permission_overwrite(snowflake id, uint64_t allow, uint64_t deny, overwrite_type type) : id(id), allow(allow), deny(deny), type(type) {}
|
||||
@@ -587,18 +589,10 @@ std::map<snowflake, voicestate> channel::get_voice_members() {
|
||||
}
|
||||
|
||||
std::string channel::get_icon_url(uint16_t size, const image_type format) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (this->id && !this->icon.to_string().empty()) {
|
||||
return utility::cdn_host + "/channel-icons/" + std::to_string(this->id) + "/" + this->icon.to_string() + "." + extensions.find(format)->second + utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp },
|
||||
"channel-icons/" + std::to_string(this->id) + "/" + this->icon.to_string(),
|
||||
format, size);
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Vendored
+4
-4
@@ -295,7 +295,7 @@ json error_response(const std::string& message, http_request_completion_t& rv)
|
||||
return j;
|
||||
}
|
||||
|
||||
void cluster::post_rest(const std::string &endpoint, const std::string &major_parameters, const std::string ¶meters, http_method method, const std::string &postdata, json_encode_t callback, const std::string &filename, const std::string &filecontent) {
|
||||
void cluster::post_rest(const std::string &endpoint, const std::string &major_parameters, const std::string ¶meters, http_method method, const std::string &postdata, json_encode_t callback, const std::string &filename, const std::string &filecontent, const std::string &filemimetype) {
|
||||
/* NOTE: This is not a memory leak! The request_queue will free the http_request once it reaches the end of its lifecycle */
|
||||
rest->post_request(new http_request(endpoint + "/" + major_parameters, parameters, [endpoint, callback](http_request_completion_t rv) {
|
||||
json j;
|
||||
@@ -310,10 +310,10 @@ void cluster::post_rest(const std::string &endpoint, const std::string &major_pa
|
||||
if (callback) {
|
||||
callback(j, rv);
|
||||
}
|
||||
}, postdata, method, get_audit_reason(), filename, filecontent));
|
||||
}, postdata, method, get_audit_reason(), filename, filecontent, filemimetype));
|
||||
}
|
||||
|
||||
void cluster::post_rest_multipart(const std::string &endpoint, const std::string &major_parameters, const std::string ¶meters, http_method method, const std::string &postdata, json_encode_t callback, const std::vector<std::string> &filename, const std::vector<std::string> &filecontent) {
|
||||
void cluster::post_rest_multipart(const std::string &endpoint, const std::string &major_parameters, const std::string ¶meters, http_method method, const std::string &postdata, json_encode_t callback, const std::vector<std::string> &filename, const std::vector<std::string> &filecontent, const std::vector<std::string> &filemimetypes) {
|
||||
/* NOTE: This is not a memory leak! The request_queue will free the http_request once it reaches the end of its lifecycle */
|
||||
rest->post_request(new http_request(endpoint + "/" + major_parameters, parameters, [endpoint, callback](http_request_completion_t rv) {
|
||||
json j;
|
||||
@@ -328,7 +328,7 @@ void cluster::post_rest_multipart(const std::string &endpoint, const std::string
|
||||
if (callback) {
|
||||
callback(j, rv);
|
||||
}
|
||||
}, postdata, method, get_audit_reason(), filename, filecontent));
|
||||
}, postdata, method, get_audit_reason(), filename, filecontent, filemimetypes));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-5
@@ -132,7 +132,7 @@ void cluster::interaction_response_create(snowflake interaction_id, const std::s
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, confirmation(), http));
|
||||
}
|
||||
}, r.msg->filename, r.msg->filecontent);
|
||||
}, r.msg->filename, r.msg->filecontent, r.msg->filemimetype);
|
||||
}
|
||||
|
||||
void cluster::interaction_response_edit(const std::string &token, const message &m, command_completion_event_t callback) {
|
||||
@@ -140,7 +140,7 @@ void cluster::interaction_response_edit(const std::string &token, const message
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, confirmation(), http));
|
||||
}
|
||||
}, m.filename, m.filecontent);
|
||||
}, m.filename, m.filecontent, m.filemimetype);
|
||||
}
|
||||
|
||||
void cluster::interaction_followup_create(const std::string &token, const message &m, command_completion_event_t callback) {
|
||||
@@ -148,7 +148,7 @@ void cluster::interaction_followup_create(const std::string &token, const messag
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, confirmation(), http));
|
||||
}
|
||||
}, m.filename, m.filecontent);
|
||||
}, m.filename, m.filecontent, m.filemimetype);
|
||||
}
|
||||
|
||||
void cluster::interaction_followup_edit_original(const std::string &token, const message &m, command_completion_event_t callback) {
|
||||
@@ -156,7 +156,7 @@ void cluster::interaction_followup_edit_original(const std::string &token, const
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, confirmation(), http));
|
||||
}
|
||||
}, m.filename, m.filecontent);
|
||||
}, m.filename, m.filecontent, m.filemimetype);
|
||||
}
|
||||
|
||||
void cluster::interaction_followup_delete(const std::string &token, command_completion_event_t callback) {
|
||||
@@ -168,7 +168,7 @@ void cluster::interaction_followup_edit(const std::string &token, const message
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, confirmation(), http));
|
||||
}
|
||||
}, m.filename, m.filecontent);
|
||||
}, m.filename, m.filecontent, m.filemimetype);
|
||||
}
|
||||
|
||||
void cluster::interaction_followup_get(const std::string &token, snowflake message_id, command_completion_event_t callback) {
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ void cluster::channel_get(snowflake c, command_completion_event_t callback) {
|
||||
}
|
||||
|
||||
void cluster::channel_invite_create(const class channel &c, const class invite &i, command_completion_event_t callback) {
|
||||
rest_request<confirmation>(this, API_PATH "/channels", std::to_string(c.id), "invites", m_post, i.build_json(), callback);
|
||||
rest_request<invite>(this, API_PATH "/channels", std::to_string(c.id), "invites", m_post, i.build_json(), callback);
|
||||
}
|
||||
|
||||
void cluster::channel_invites_get(const class channel &c, command_completion_event_t callback) {
|
||||
|
||||
Vendored
+2
-1
@@ -46,6 +46,7 @@ void cluster::guild_ban_add(snowflake guild_id, snowflake user_id, uint32_t dele
|
||||
if (delete_message_seconds) {
|
||||
j["delete_message_seconds"] = delete_message_seconds > 604800 ? 604800 : delete_message_seconds;
|
||||
if (delete_message_seconds >= 1 && delete_message_seconds <= 7) {
|
||||
// this prints out a warning for backwards compatibility
|
||||
if (dpp::run_once<struct ban_add_seconds_not_days_t>()) {
|
||||
this->log(ll_warning, "It looks like you may have confused seconds and days in cluster::guild_ban_add - Please double check your parameters!");
|
||||
}
|
||||
@@ -95,7 +96,7 @@ void cluster::guild_get_bans(snowflake guild_id, snowflake before, snowflake aft
|
||||
{"after", after},
|
||||
{"limit", limit},
|
||||
});
|
||||
rest_request_list<ban>(this, API_PATH "/guilds", std::to_string(guild_id), "bans" + parameters, m_get, "", callback, "user_id");
|
||||
rest_request_list<ban>(this, API_PATH "/guilds", std::to_string(guild_id), "bans" + parameters, m_get, "", callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -31,8 +31,8 @@ void cluster::invite_delete(const std::string &invitecode, command_completion_ev
|
||||
}
|
||||
|
||||
|
||||
void cluster::invite_get(const std::string &invitecode, command_completion_event_t callback) {
|
||||
rest_request<invite>(this, API_PATH "/invites", utility::url_encode(invitecode) + "?with_counts=true&with_expiration=true", "", m_get, "", callback);
|
||||
void cluster::invite_get(const std::string &invite_code, command_completion_event_t callback) {
|
||||
rest_request<invite>(this, API_PATH "/invites", utility::url_encode(invite_code) + "?with_counts=true&with_expiration=true", "", m_get, "", callback);
|
||||
}
|
||||
|
||||
};
|
||||
+2
-2
@@ -40,7 +40,7 @@ void cluster::message_create(const message &m, command_completion_event_t callba
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, message(this).fill_from_json(&j), http));
|
||||
}
|
||||
}, m.filename, m.filecontent);
|
||||
}, m.filename, m.filecontent, m.filemimetype);
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ void cluster::message_edit(const message &m, command_completion_event_t callback
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, message(this).fill_from_json(&j), http));
|
||||
}
|
||||
}, m.filename, m.filecontent);
|
||||
}, m.filename, m.filecontent, m.filemimetype);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+14
-1
@@ -23,12 +23,25 @@
|
||||
|
||||
namespace dpp {
|
||||
|
||||
namespace {
|
||||
std::string get_sticker_mimetype(const sticker &s) {
|
||||
static const std::map<sticker_format, std::string> mime_types = {
|
||||
{ sticker_format::sf_png, "image/png" },
|
||||
{ sticker_format::sf_apng, "image/png" },
|
||||
{ sticker_format::sf_lottie, "application/json" },
|
||||
{ sticker_format::sf_gif, "image/gif" },
|
||||
};
|
||||
|
||||
return mime_types.find(s.format_type)->second;
|
||||
}
|
||||
}
|
||||
|
||||
void cluster::guild_sticker_create(sticker &s, command_completion_event_t callback) {
|
||||
this->post_rest(API_PATH "/guilds", std::to_string(s.guild_id), "stickers", m_post, s.build_json(false), [this, callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, sticker().fill_from_json(&j), http));
|
||||
}
|
||||
}, s.filename, s.filecontent);
|
||||
}, s.filename, s.filecontent, get_sticker_mimetype(s));
|
||||
}
|
||||
|
||||
void cluster::guild_sticker_delete(snowflake sticker_id, snowflake guild_id, command_completion_event_t callback) {
|
||||
|
||||
+22
-4
@@ -32,7 +32,25 @@ void cluster::current_user_leave_thread(snowflake thread_id, command_completion_
|
||||
}
|
||||
|
||||
void cluster::threads_get_active(snowflake guild_id, command_completion_event_t callback) {
|
||||
rest_request_list<thread>(this, API_PATH "/guilds", std::to_string(guild_id), "/threads/active", m_get, "", callback);
|
||||
this->post_rest(API_PATH "/guilds", std::to_string(guild_id), "/threads/active", m_get, "", [this, callback](json &j, const http_request_completion_t& http) {
|
||||
active_threads list;
|
||||
confirmation_callback_t e(this, confirmation(), http);
|
||||
if (!e.is_error()) {
|
||||
if (j.contains("threads")) {
|
||||
for (auto &curr_item: j["threads"]) {
|
||||
list.threads[snowflake_not_null(&curr_item, "id")] = thread().fill_from_json(&curr_item);
|
||||
}
|
||||
}
|
||||
if (j.contains("members")) {
|
||||
for (auto &curr_item: j["members"]) {
|
||||
list.thread_members[snowflake_not_null(&curr_item, "id")] = thread_member().fill_from_json(&curr_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, list, http));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void cluster::threads_get_joined_private_archived(snowflake channel_id, snowflake before_id, uint16_t limit, command_completion_event_t callback) {
|
||||
@@ -60,11 +78,11 @@ void cluster::threads_get_public_archived(snowflake channel_id, time_t before_ti
|
||||
}
|
||||
|
||||
void cluster::thread_member_get(const snowflake thread_id, const snowflake user_id, command_completion_event_t callback) {
|
||||
rest_request<thread_member>(this, API_PATH "/channels", std::to_string(thread_id), "/threads-members/" + std::to_string(user_id), m_get, "", callback);
|
||||
rest_request<thread_member>(this, API_PATH "/channels", std::to_string(thread_id), "/thread-members/" + std::to_string(user_id), m_get, "", callback);
|
||||
}
|
||||
|
||||
void cluster::thread_members_get(snowflake thread_id, command_completion_event_t callback) {
|
||||
rest_request_list<thread_member>(this, API_PATH "/channels", std::to_string(thread_id), "/threads-members", m_get, "", callback);
|
||||
rest_request_list<thread_member>(this, API_PATH "/channels", std::to_string(thread_id), "/thread-members", m_get, "", callback);
|
||||
}
|
||||
|
||||
void cluster::thread_create_in_forum(const std::string& thread_name, snowflake channel_id, const message& msg, auto_archive_duration_t auto_archive_duration, uint16_t rate_limit_per_user, std::vector<snowflake> applied_tags, command_completion_event_t callback)
|
||||
@@ -100,7 +118,7 @@ void cluster::thread_create_in_forum(const std::string& thread_name, snowflake c
|
||||
}
|
||||
callback(confirmation_callback_t(this, t, http));
|
||||
}
|
||||
}, msg.filename, msg.filecontent);
|
||||
}, msg.filename, msg.filecontent, msg.filemimetype);
|
||||
}
|
||||
|
||||
void cluster::thread_create(const std::string& thread_name, snowflake channel_id, uint16_t auto_archive_duration, channel_type thread_type, bool invitable, uint16_t rate_limit_per_user, command_completion_event_t callback)
|
||||
|
||||
Vendored
+2
-6
@@ -100,11 +100,7 @@ void cluster::user_get_cached(snowflake user_id, command_completion_event_t call
|
||||
* user_identified from a user, by calling a constructor that builds it from
|
||||
* the user object.
|
||||
*/
|
||||
confirmation_callback_t cb(
|
||||
this,
|
||||
user_identified(*u),
|
||||
http_request_completion_t()
|
||||
);
|
||||
confirmation_callback_t cb(this, user_identified(*u), http_request_completion_t());
|
||||
callback(cb);
|
||||
return;
|
||||
}
|
||||
@@ -112,4 +108,4 @@ void cluster::user_get_cached(snowflake user_id, command_completion_event_t call
|
||||
rest_request<user_identified>(this, API_PATH "/users", std::to_string(user_id), "", m_get, "", callback);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
+2
-2
@@ -59,7 +59,7 @@ void cluster::edit_webhook_message(const class webhook &wh, const struct message
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, message(this).fill_from_json(&j), http));
|
||||
}
|
||||
}, m.filename, m.filecontent);
|
||||
}, m.filename, m.filecontent, m.filemimetype);
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ void cluster::execute_webhook(const class webhook &wh, const struct message& m,
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(this, message(this).fill_from_json(&j), http));
|
||||
}
|
||||
}, m.filename, m.filecontent);
|
||||
}, m.filename, m.filecontent, m.filemimetype);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -541,8 +541,8 @@ confirmation cluster::current_user_leave_thread_sync(snowflake thread_id) {
|
||||
return dpp::sync<confirmation>(this, &cluster::current_user_leave_thread, thread_id);
|
||||
}
|
||||
|
||||
thread_map cluster::threads_get_active_sync(snowflake guild_id) {
|
||||
return dpp::sync<thread_map>(this, &cluster::threads_get_active, guild_id);
|
||||
active_threads cluster::threads_get_active_sync(snowflake guild_id) {
|
||||
return dpp::sync<active_threads>(this, &cluster::threads_get_active, guild_id);
|
||||
}
|
||||
|
||||
thread_map cluster::threads_get_joined_private_archived_sync(snowflake channel_id, snowflake before_id, uint16_t limit) {
|
||||
|
||||
Vendored
+2
-4
@@ -610,7 +610,7 @@ discord_client& discord_client::connect_voice(snowflake guild_id, snowflake chan
|
||||
#ifdef HAVE_VOICE
|
||||
std::unique_lock lock(voice_mutex);
|
||||
if (connecting_voice_channels.find(guild_id) == connecting_voice_channels.end()) {
|
||||
connecting_voice_channels[guild_id] = new voiceconn(this, channel_id);
|
||||
connecting_voice_channels[guild_id] = std::make_unique<voiceconn>(this, channel_id);
|
||||
/* Once sent, this expects two events (in any order) on the websocket:
|
||||
* VOICE_SERVER_UPDATE and VOICE_STATUS_UPDATE
|
||||
*/
|
||||
@@ -658,8 +658,6 @@ void discord_client::disconnect_voice_internal(snowflake guild_id, bool emit_jso
|
||||
}
|
||||
})), false);
|
||||
}
|
||||
delete v->second;
|
||||
v->second = nullptr;
|
||||
connecting_voice_channels.erase(v);
|
||||
}
|
||||
#endif
|
||||
@@ -675,7 +673,7 @@ voiceconn* discord_client::get_voice(snowflake guild_id) {
|
||||
std::shared_lock lock(voice_mutex);
|
||||
auto v = connecting_voice_channels.find(guild_id);
|
||||
if (v != connecting_voice_channels.end()) {
|
||||
return v->second;
|
||||
return v->second.get();
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
|
||||
Vendored
+1
-1
@@ -341,7 +341,7 @@ const std::map<std::string, dpp::events::event*> eventmap = {
|
||||
{ "AUTO_MODERATION_RULE_UPDATE", new dpp::events::automod_rule_update() },
|
||||
{ "AUTO_MODERATION_RULE_DELETE", new dpp::events::automod_rule_delete() },
|
||||
{ "AUTO_MODERATION_ACTION_EXECUTION", new dpp::events::automod_rule_execute() },
|
||||
{ "GUILD_AUDIT_LOG_ENTRY_CREATE", nullptr }, /* TODO: Implement this event */
|
||||
{ "GUILD_AUDIT_LOG_ENTRY_CREATE", new dpp::events::guild_audit_log_entry_create() },
|
||||
};
|
||||
|
||||
void discord_client::handle_event(const std::string &event, json &j, const std::string &raw)
|
||||
|
||||
+2
-6
@@ -398,12 +398,12 @@ int discord_voice_client::udp_send(const char* data, size_t length)
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons(this->port);
|
||||
servaddr.sin_addr.s_addr = inet_addr(this->ip.c_str());
|
||||
return sendto(this->fd, data, (int)length, 0, (const sockaddr*)&servaddr, (int)sizeof(sockaddr_in));
|
||||
return (int) sendto(this->fd, data, (int)length, 0, (const sockaddr*)&servaddr, (int)sizeof(sockaddr_in));
|
||||
}
|
||||
|
||||
int discord_voice_client::udp_recv(char* data, size_t max_length)
|
||||
{
|
||||
return recv(this->fd, data, (int)max_length, 0);
|
||||
return (int) recv(this->fd, data, (int)max_length, 0);
|
||||
}
|
||||
|
||||
bool discord_voice_client::handle_frame(const std::string &data)
|
||||
@@ -1021,10 +1021,6 @@ void discord_voice_client::one_second_timer()
|
||||
if (time(nullptr) > last_heartbeat + ((heartbeat_interval / 1000.0) * 0.75)) {
|
||||
queue_message(json({{"op", 3}, {"d", rand()}}).dump(), true);
|
||||
last_heartbeat = time(nullptr);
|
||||
/* If we're paused, send this to keep the UDP connection alive. */
|
||||
if (this->paused) {
|
||||
this->send_silence(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+27
-9
@@ -196,7 +196,7 @@ void interaction_create_t::edit_original_response(const message & m, command_com
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(creator, message().fill_from_json(&j), http));
|
||||
}
|
||||
}, m.filename, m.filecontent);
|
||||
}, m.filename, m.filecontent, m.filemimetype);
|
||||
}
|
||||
|
||||
void interaction_create_t::delete_original_response(command_completion_event_t callback) const
|
||||
@@ -208,17 +208,34 @@ void interaction_create_t::delete_original_response(command_completion_event_t c
|
||||
});
|
||||
}
|
||||
|
||||
const command_value& interaction_create_t::get_parameter(const std::string& name) const
|
||||
command_value interaction_create_t::get_parameter(const std::string& name) const
|
||||
{
|
||||
/* Dummy STATIC return value for unknown options so we aren't returning a value off the stack */
|
||||
static command_value dummy_value = {};
|
||||
const command_interaction& ci = std::get<command_interaction>(command.data);
|
||||
for (auto i = ci.options.begin(); i != ci.options.end(); ++i) {
|
||||
if (i->name == name) {
|
||||
return i->value;
|
||||
const command_interaction ci = command.get_command_interaction();
|
||||
|
||||
for (const auto &option : ci.options) {
|
||||
if (option.type != co_sub_command && option.type != co_sub_command_group && option.name == name) {
|
||||
return option.value;
|
||||
}
|
||||
}
|
||||
return dummy_value;
|
||||
/* if not found in the first level, go one level deeper */
|
||||
for (const auto &option : ci.options) { // command
|
||||
for (const auto &sub_option : option.options) { // subcommands
|
||||
if (sub_option.type != co_sub_command && sub_option.type != co_sub_command_group && sub_option.name == name) {
|
||||
return sub_option.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* if not found in the second level, search it in the third dimension */
|
||||
for (const auto &option : ci.options) { // command
|
||||
for (const auto &sub_group_option : option.options) { // subcommand groups
|
||||
for (const auto &sub_option : sub_group_option.options) { // subcommands
|
||||
if (sub_option.type != co_sub_command && sub_option.type != co_sub_command_group && sub_option.name == name) {
|
||||
return sub_option.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
voice_receive_t::voice_receive_t(class discord_client* client, const std::string &raw, class discord_voice_client* vc, snowflake _user_id, uint8_t* pcm, size_t length) : event_dispatch_t(client, raw), voice_client(vc), user_id(_user_id) {
|
||||
@@ -282,6 +299,7 @@ event_ctor(invite_create_t, event_dispatch_t);
|
||||
event_ctor(message_update_t, event_dispatch_t);
|
||||
event_ctor(user_update_t, event_dispatch_t);
|
||||
event_ctor(message_create_t, event_dispatch_t);
|
||||
event_ctor(guild_audit_log_entry_create_t, event_dispatch_t);
|
||||
event_ctor(guild_ban_add_t, event_dispatch_t);
|
||||
event_ctor(guild_ban_remove_t, event_dispatch_t);
|
||||
event_ctor(integration_create_t, event_dispatch_t);
|
||||
|
||||
Vendored
+3
-1
@@ -22,10 +22,12 @@
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
dtemplate::dtemplate() : code(""), name(""), description(""), usage_count(0), creator_id(0), source_guild_id(0)
|
||||
{
|
||||
}
|
||||
|
||||
Vendored
+10
@@ -117,6 +117,16 @@ std::string emoji::get_mention() const {
|
||||
return utility::emoji_mention(name,id,is_animated());
|
||||
}
|
||||
|
||||
std::string emoji::get_url(uint16_t size, const dpp::image_type format, bool prefer_animated) const {
|
||||
if (this->id) {
|
||||
return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp, i_gif },
|
||||
"emojis/" + std::to_string(this->id),
|
||||
format, size, prefer_animated, is_animated());
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
+2
-1
@@ -23,10 +23,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -23,10 +23,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-2
@@ -23,10 +23,9 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-2
@@ -23,10 +23,9 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-2
@@ -23,10 +23,9 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-2
@@ -24,11 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -24,10 +24,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/cluster.h>
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void guild_audit_log_entry_create::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
json& d = j["d"];
|
||||
if (!client->creator->on_guild_audit_log_entry_create.empty()) {
|
||||
dpp::guild_audit_log_entry_create_t ec(client, raw);
|
||||
ec.entry.fill_from_json(&d);
|
||||
client->creator->on_guild_audit_log_entry_create.call(ec);
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
||||
+1
-1
@@ -25,10 +25,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -25,10 +25,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -25,10 +25,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -25,10 +25,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -26,10 +26,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -25,10 +25,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -23,10 +23,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -25,10 +25,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -25,10 +25,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -25,10 +25,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
|
||||
+3
-2
@@ -25,10 +25,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+1
-1
@@ -23,10 +23,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+4
-3
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
@@ -45,10 +45,11 @@ void message_reaction_add::handle(discord_client* client, json &j, const std::st
|
||||
mra.reacting_guild = dpp::find_guild(guild_id);
|
||||
mra.reacting_user = dpp::user().fill_from_json(&(d["member"]["user"]));
|
||||
mra.reacting_member = dpp::guild_member().fill_from_json(&(d["member"]), guild_id, mra.reacting_user.id);
|
||||
mra.reacting_channel = dpp::find_channel(snowflake_not_null(&d, "channel_id"));
|
||||
mra.channel_id = snowflake_not_null(&d, "channel_id");
|
||||
mra.reacting_channel = dpp::find_channel(mra.channel_id);
|
||||
mra.message_id = snowflake_not_null(&d, "message_id");
|
||||
mra.reacting_emoji = dpp::emoji().fill_from_json(&(d["emoji"]));
|
||||
if (mra.reacting_channel && mra.message_id) {
|
||||
if (mra.channel_id && mra.message_id) {
|
||||
client->creator->on_message_reaction_add.call(mra);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
@@ -44,10 +44,11 @@ void message_reaction_remove::handle(discord_client* client, json &j, const std:
|
||||
dpp::snowflake guild_id = snowflake_not_null(&d, "guild_id");
|
||||
mrr.reacting_guild = dpp::find_guild(guild_id);
|
||||
mrr.reacting_user_id = snowflake_not_null(&d, "user_id");
|
||||
mrr.reacting_channel = dpp::find_channel(snowflake_not_null(&d, "channel_id"));
|
||||
mrr.channel_id = snowflake_not_null(&d, "channel_id");
|
||||
mrr.reacting_channel = dpp::find_channel(mrr.channel_id);
|
||||
mrr.message_id = snowflake_not_null(&d, "message_id");
|
||||
mrr.reacting_emoji = dpp::emoji().fill_from_json(&(d["emoji"]));
|
||||
if (mrr.reacting_channel && mrr.message_id) {
|
||||
if (mrr.channel_id && mrr.message_id) {
|
||||
client->creator->on_message_reaction_remove.call(mrr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
@@ -42,9 +42,10 @@ void message_reaction_remove_all::handle(discord_client* client, json &j, const
|
||||
json &d = j["d"];
|
||||
dpp::message_reaction_remove_all_t mrra(client, raw);
|
||||
mrra.reacting_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id"));
|
||||
mrra.reacting_channel = dpp::find_channel(snowflake_not_null(&d, "channel_id"));
|
||||
mrra.channel_id = snowflake_not_null(&d, "channel_id");
|
||||
mrra.reacting_channel = dpp::find_channel(mrra.channel_id);
|
||||
mrra.message_id = snowflake_not_null(&d, "message_id");
|
||||
if (mrra.reacting_channel && mrra.message_id) {
|
||||
if (mrra.channel_id && mrra.message_id) {
|
||||
client->creator->on_message_reaction_remove_all.call(mrra);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
@@ -42,10 +42,11 @@ void message_reaction_remove_emoji::handle(discord_client* client, json &j, cons
|
||||
json &d = j["d"];
|
||||
dpp::message_reaction_remove_emoji_t mrre(client, raw);
|
||||
mrre.reacting_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id"));
|
||||
mrre.reacting_channel = dpp::find_channel(snowflake_not_null(&d, "channel_id"));
|
||||
mrre.channel_id = snowflake_not_null(&d, "channel_id");
|
||||
mrre.reacting_channel = dpp::find_channel(mrre.channel_id);
|
||||
mrre.message_id = snowflake_not_null(&d, "message_id");
|
||||
mrre.reacting_emoji = dpp::emoji().fill_from_json(&(d["emoji"]));
|
||||
if (mrre.reacting_channel && mrre.message_id) {
|
||||
if (mrre.channel_id && mrre.message_id) {
|
||||
client->creator->on_message_reaction_remove_emoji.call(mrre);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -23,10 +23,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/dns.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
#ifndef _DOXYGEN_
|
||||
|
||||
+1
-1
@@ -23,10 +23,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,10 +24,10 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -24,11 +24,12 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
void thread_create::handle(discord_client* client, json& j, const std::string& raw) {
|
||||
json& d = j["d"];
|
||||
|
||||
|
||||
+2
-1
@@ -24,11 +24,12 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
void thread_delete::handle(discord_client* client, json& j, const std::string& raw) {
|
||||
json& d = j["d"];
|
||||
|
||||
|
||||
+4
-2
@@ -24,11 +24,13 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
void thread_list_sync::handle(discord_client* client, json& j, const std::string& raw) {
|
||||
json& d = j["d"];
|
||||
|
||||
|
||||
+2
-1
@@ -24,11 +24,12 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
void thread_member_update::handle(discord_client* client, json& j, const std::string& raw) {
|
||||
if (!client->creator->on_thread_member_update.empty()) {
|
||||
json& d = j["d"];
|
||||
|
||||
+2
-1
@@ -24,11 +24,12 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
void thread_members_update::handle(discord_client* client, json& j, const std::string& raw) {
|
||||
json& d = j["d"];
|
||||
|
||||
|
||||
+4
-2
@@ -24,11 +24,13 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
void thread_update::handle(discord_client* client, json& j, const std::string& raw) {
|
||||
json& d = j["d"];
|
||||
|
||||
|
||||
+3
-2
@@ -23,10 +23,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -25,10 +25,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -25,10 +25,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -26,10 +26,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -24,10 +24,11 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+75
-89
@@ -27,8 +27,18 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
/* A mapping of discord's flag values to our bitmap (they're different bit positions to fit other stuff in) */
|
||||
std::map<uint16_t , dpp::guild_member_flags> membermap = {
|
||||
{ 1 << 0, dpp::gm_did_rejoin },
|
||||
{ 1 << 1, dpp::gm_completed_onboarding },
|
||||
{ 1 << 2, dpp::gm_bypasses_verification },
|
||||
{ 1 << 3, dpp::gm_started_onboarding },
|
||||
};
|
||||
|
||||
const std::map<std::string, std::variant<dpp::guild_flags, dpp::guild_flags_extra>> featuremap = {
|
||||
{"ANIMATED_BANNER", dpp::g_animated_banner },
|
||||
{"ANIMATED_ICON", dpp::g_animated_icon },
|
||||
@@ -47,6 +57,7 @@ const std::map<std::string, std::variant<dpp::guild_flags, dpp::guild_flags_extr
|
||||
{"NEWS", dpp::g_news },
|
||||
{"PARTNERED", dpp::g_partnered },
|
||||
{"PREVIEW_ENABLED", dpp::g_preview_enabled },
|
||||
{"RAID_ALERTS_DISABLED", dpp::g_raid_alerts_disabled },
|
||||
{"ROLE_ICONS", dpp::g_role_icons },
|
||||
{"ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE", dpp::g_role_subscriptions_available_for_purchase },
|
||||
{"ROLE_SUBSCRIPTIONS_ENABLED", dpp::g_role_subscription_enabled },
|
||||
@@ -57,8 +68,6 @@ const std::map<std::string, std::variant<dpp::guild_flags, dpp::guild_flags_extr
|
||||
{"WELCOME_SCREEN_ENABLED", dpp::g_welcome_screen_enabled },
|
||||
};
|
||||
|
||||
namespace dpp {
|
||||
|
||||
guild::guild() :
|
||||
managed(),
|
||||
owner_id(0),
|
||||
@@ -72,6 +81,7 @@ guild::guild() :
|
||||
flags(0),
|
||||
max_presences(0),
|
||||
max_members(0),
|
||||
flags_extra(0),
|
||||
shard_id(0),
|
||||
premium_subscription_count(0),
|
||||
afk_timeout(afk_off),
|
||||
@@ -81,8 +91,7 @@ guild::guild() :
|
||||
verification_level(ver_none),
|
||||
explicit_content_filter(expl_disabled),
|
||||
mfa_level(mfa_none),
|
||||
nsfw_level(nsfw_default),
|
||||
flags_extra(0)
|
||||
nsfw_level(nsfw_default)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -106,6 +115,11 @@ guild_member& guild_member::set_nickname(const std::string& nick) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
guild_member& guild_member::set_bypasses_verification(const bool is_bypassing_verification) {
|
||||
this->flags = (is_bypassing_verification) ? flags | gm_bypasses_verification : flags & ~gm_bypasses_verification;
|
||||
return *this;
|
||||
}
|
||||
|
||||
guild_member& guild_member::set_mute(const bool is_muted) {
|
||||
this->flags = (is_muted) ? flags | gm_mute : flags & ~gm_mute;
|
||||
this->flags |= gm_voice_action;
|
||||
@@ -147,6 +161,13 @@ void from_json(const nlohmann::json& j, guild_member& gm) {
|
||||
set_ts_not_null(&j, "premium_since", gm.premium_since);
|
||||
set_ts_not_null(&j, "communication_disabled_until", gm.communication_disabled_until);
|
||||
|
||||
uint16_t flags = int16_not_null(&j, "flags");
|
||||
for (auto & flag : membermap) {
|
||||
if (flags & flag.first) {
|
||||
gm.flags |= flag.second;
|
||||
}
|
||||
}
|
||||
|
||||
gm.roles.clear();
|
||||
if (j.contains("roles") && !j.at("roles").is_null()) {
|
||||
gm.roles.reserve(j.at("roles").size());
|
||||
@@ -169,26 +190,10 @@ void from_json(const nlohmann::json& j, guild_member& gm) {
|
||||
}
|
||||
|
||||
std::string guild_member::get_avatar_url(uint16_t size, const image_type format, bool prefer_animated) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_gif, "gif" },
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (this->guild_id && this->user_id && !this->avatar.to_string().empty()) {
|
||||
return utility::cdn_host + "/guilds/" +
|
||||
std::to_string(this->guild_id) +
|
||||
"/" +
|
||||
std::to_string(this->user_id) +
|
||||
(has_animated_guild_avatar() ? "/a_" : "/") +
|
||||
this->avatar.to_string() + "." +
|
||||
(has_animated_guild_avatar() && prefer_animated ? "gif" : extensions.find(format)->second) +
|
||||
utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url_hash({ i_jpg, i_png, i_webp, i_gif },
|
||||
"guilds/" + std::to_string(this->guild_id) + "/" + std::to_string(this->user_id), this->avatar.to_string(),
|
||||
format, size, prefer_animated, has_animated_guild_avatar());
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
@@ -212,16 +217,24 @@ std::string guild_member::build_json(bool with_id) const {
|
||||
j["nick"] = this->nickname;
|
||||
if (!this->roles.empty()) {
|
||||
j["roles"] = {};
|
||||
for (auto & role : roles) {
|
||||
for (auto & role : this->roles) {
|
||||
j["roles"].push_back(std::to_string(role));
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & gm_voice_action) {
|
||||
if (this->flags & gm_voice_action) {
|
||||
j["mute"] = is_muted();
|
||||
j["deaf"] = is_deaf();
|
||||
}
|
||||
|
||||
uint32_t out_flags = 0;
|
||||
for (auto & flag : membermap) {
|
||||
if (flags & flag.second) {
|
||||
out_flags |= flag.first;
|
||||
}
|
||||
}
|
||||
j["flags"] = out_flags;
|
||||
|
||||
return j.dump();
|
||||
}
|
||||
|
||||
@@ -246,6 +259,22 @@ bool guild_member::is_pending() const {
|
||||
return flags & dpp::gm_pending;
|
||||
}
|
||||
|
||||
bool guild_member::has_rejoined() const {
|
||||
return flags & dpp::gm_did_rejoin;
|
||||
}
|
||||
|
||||
bool guild_member::has_completed_onboarding() const {
|
||||
return flags & dpp::gm_completed_onboarding;
|
||||
}
|
||||
|
||||
bool guild_member::has_started_onboarding() const {
|
||||
return flags & dpp::gm_started_onboarding;
|
||||
}
|
||||
|
||||
bool guild_member::has_bypasses_verification() const {
|
||||
return flags & dpp::gm_bypasses_verification;
|
||||
}
|
||||
|
||||
bool guild::is_large() const {
|
||||
return this->flags & g_large;
|
||||
}
|
||||
@@ -326,6 +355,10 @@ bool guild::has_role_subscriptions_available_for_purchase() const {
|
||||
return this->flags_extra & g_role_subscriptions_available_for_purchase;
|
||||
}
|
||||
|
||||
bool guild::has_raid_alerts_disabled() const {
|
||||
return this->flags_extra & g_raid_alerts_disabled;
|
||||
}
|
||||
|
||||
bool guild::has_animated_icon() const {
|
||||
return this->flags & g_animated_icon;
|
||||
}
|
||||
@@ -426,6 +459,9 @@ std::string guild::build_json(bool with_id) const {
|
||||
if (!description.empty()) {
|
||||
j["description"] = description;
|
||||
}
|
||||
if (!safety_alerts_channel_id.empty()) {
|
||||
j["safety_alerts_channel_id"] = safety_alerts_channel_id;
|
||||
}
|
||||
return j.dump();
|
||||
}
|
||||
|
||||
@@ -572,6 +608,8 @@ guild& guild::fill_from_json(discord_client* shard, nlohmann::json* d) {
|
||||
welcome_screen.welcome_channels.emplace_back(wchan);
|
||||
}
|
||||
}
|
||||
|
||||
set_snowflake_not_null(d, "safety_alerts_channel_id", this->safety_alerts_channel_id);
|
||||
|
||||
} else {
|
||||
this->flags |= dpp::g_unavailable;
|
||||
@@ -766,92 +804,40 @@ bool guild::connect_member_voice(snowflake user_id, bool self_mute, bool self_de
|
||||
}
|
||||
|
||||
std::string guild::get_banner_url(uint16_t size, const image_type format, bool prefer_animated) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_gif, "gif" },
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->banner.to_string().empty() && this->id) {
|
||||
return utility::cdn_host + "/banners/" +
|
||||
std::to_string(this->id) +
|
||||
(has_animated_banner_hash() ? "/a_" : "/") +
|
||||
this->banner.to_string() + "." +
|
||||
(has_animated_banner_hash() && prefer_animated ? "gif" : extensions.find(format)->second) +
|
||||
utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url_hash({ i_jpg, i_png, i_webp, i_gif },
|
||||
"banners/" + std::to_string(this->id), this->banner.to_string(),
|
||||
format, size, prefer_animated, has_animated_banner_hash());
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
std::string guild::get_discovery_splash_url(uint16_t size, const image_type format) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->discovery_splash.to_string().empty() && this->id) {
|
||||
return utility::cdn_host + "/discovery-splashes/" +
|
||||
std::to_string(this->id) + "/" +
|
||||
this->discovery_splash.to_string() +
|
||||
"." + extensions.find(format)->second +
|
||||
utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp },
|
||||
"discovery-splashes/" + std::to_string(this->id) + "/" + this->discovery_splash.to_string(),
|
||||
format, size);
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
std::string guild::get_icon_url(uint16_t size, const image_type format, bool prefer_animated) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_gif, "gif" },
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->icon.to_string().empty() && this->id) {
|
||||
return utility::cdn_host + "/icons/" +
|
||||
std::to_string(this->id) +
|
||||
(has_animated_icon_hash() ? "/a_" : "/") +
|
||||
this->icon.to_string() + "." +
|
||||
(has_animated_icon_hash() && prefer_animated ? "gif" : extensions.find(format)->second) +
|
||||
utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url_hash({ i_jpg, i_png, i_webp, i_gif },
|
||||
"icons/" + std::to_string(this->id), this->icon.to_string(),
|
||||
format, size, prefer_animated, has_animated_icon_hash());
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
std::string guild::get_splash_url(uint16_t size, const image_type format) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->splash.to_string().empty() && this->id) {
|
||||
return utility::cdn_host + "/splashes/" +
|
||||
std::to_string(this->id) + "/" +
|
||||
this->splash.to_string() +
|
||||
"." + extensions.find(format)->second +
|
||||
utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp, i_gif },
|
||||
"splashes/" + std::to_string(this->id) + "/" + this->splash.to_string(),
|
||||
format, size);
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Vendored
+40
-11
@@ -71,7 +71,7 @@ void https_client::connect()
|
||||
}
|
||||
}
|
||||
|
||||
multipart_content https_client::build_multipart(const std::string &json, const std::vector<std::string>& filenames, const std::vector<std::string>& contents) {
|
||||
multipart_content https_client::build_multipart(const std::string &json, const std::vector<std::string>& filenames, const std::vector<std::string>& contents, const std::vector<std::string>& mimetypes) {
|
||||
if (filenames.empty() && contents.empty()) {
|
||||
if (!json.empty()) {
|
||||
return { json, "application/json" };
|
||||
@@ -84,7 +84,9 @@ multipart_content https_client::build_multipart(const std::string &json, const s
|
||||
time_t dummy2 = time(nullptr) * time(nullptr);
|
||||
const std::string two_cr("\r\n\r\n");
|
||||
const std::string boundary("-------------" + to_hex(dummy1) + to_hex(dummy2));
|
||||
const std::string mime_part_start("--" + boundary + "\r\nContent-Type: application/octet-stream\r\nContent-Disposition: form-data; ");
|
||||
const std::string part_start("--" + boundary + "\r\nContent-Disposition: form-data; ");
|
||||
const std::string mime_type_start("\r\nContent-Type: ");
|
||||
const std::string default_mime_type("application/octet-stream");
|
||||
|
||||
std::string content("--" + boundary);
|
||||
|
||||
@@ -92,12 +94,14 @@ multipart_content https_client::build_multipart(const std::string &json, const s
|
||||
content += "\r\nContent-Type: application/json\r\nContent-Disposition: form-data; name=\"payload_json\"" + two_cr;
|
||||
content += json + "\r\n";
|
||||
if (filenames.size() == 1 && contents.size() == 1) {
|
||||
content += mime_part_start + "name=\"file\"; filename=\"" + filenames[0] + "\"" + two_cr;
|
||||
content += part_start + "name=\"file\"; filename=\"" + filenames[0] + "\"";
|
||||
content += mime_type_start + (mimetypes.empty() || mimetypes[0].empty() ? default_mime_type : mimetypes[0]) + two_cr;
|
||||
content += contents[0];
|
||||
} else {
|
||||
/* Multiple files */
|
||||
for (size_t i = 0; i < filenames.size(); ++i) {
|
||||
content += mime_part_start + "name=\"files[" + std::to_string(i) + "]\"; filename=\"" + filenames[i] + "\"" + two_cr;
|
||||
content += part_start + "name=\"files[" + std::to_string(i) + "]\"; filename=\"" + filenames[i] + "\"";
|
||||
content += "\r\nContent-Type: " + (mimetypes.size() < i || mimetypes[i].empty() ? default_mime_type : mimetypes[i]) + two_cr;
|
||||
content += contents[i];
|
||||
content += "\r\n";
|
||||
}
|
||||
@@ -118,7 +122,29 @@ const std::string https_client::get_header(std::string header_name) const {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::map<std::string, std::string> https_client::get_headers() const {
|
||||
size_t https_client::get_header_count(std::string header_name) const {
|
||||
std::transform(header_name.begin(), header_name.end(), header_name.begin(), [](unsigned char c){
|
||||
return std::tolower(c);
|
||||
});
|
||||
return response_headers.count(header_name);
|
||||
}
|
||||
|
||||
const std::list<std::string> https_client::get_header_list(std::string header_name) const {
|
||||
std::transform(header_name.begin(), header_name.end(), header_name.begin(), [](unsigned char c){
|
||||
return std::tolower(c);
|
||||
});
|
||||
auto hdrs = response_headers.equal_range(header_name);
|
||||
if (hdrs.first != response_headers.end()) {
|
||||
std::list<std::string> data;
|
||||
for ( auto i = hdrs.first; i != hdrs.second; ++i ) {
|
||||
data.emplace_back(i->second);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
return std::list<std::string>();
|
||||
}
|
||||
|
||||
const std::multimap<std::string, std::string> https_client::get_headers() const {
|
||||
return response_headers;
|
||||
}
|
||||
|
||||
@@ -159,20 +185,23 @@ bool https_client::handle_buffer(std::string &buffer)
|
||||
std::transform(key.begin(), key.end(), key.begin(), [](unsigned char c){
|
||||
return std::tolower(c);
|
||||
});
|
||||
response_headers[key] = value;
|
||||
response_headers.emplace(key, value);
|
||||
}
|
||||
}
|
||||
if (response_headers.find("content-length") != response_headers.end()) {
|
||||
content_length = std::stoull(response_headers["content-length"]);
|
||||
auto it_cl = response_headers.find("content-length");
|
||||
if ( it_cl != response_headers.end()) {
|
||||
content_length = std::stoull(it_cl->second);
|
||||
} else {
|
||||
content_length = ULLONG_MAX;
|
||||
}
|
||||
if (response_headers["connection"] == "close") {
|
||||
auto it_conn = response_headers.find("connection");
|
||||
if (it_conn != response_headers.end() && it_conn->second == "close") {
|
||||
keepalive = false;
|
||||
}
|
||||
chunked = false;
|
||||
if (response_headers.find("transfer-encoding") != response_headers.end()) {
|
||||
if (response_headers["transfer-encoding"].find("chunked") != std::string::npos) {
|
||||
auto it_txenc = response_headers.find("transfer-encoding");
|
||||
if (it_txenc != response_headers.end()) {
|
||||
if (it_txenc->second.find("chunked") != std::string::npos) {
|
||||
chunked = true;
|
||||
chunk_size = 0;
|
||||
chunk_receive = 0;
|
||||
|
||||
Vendored
+5
-2
@@ -24,10 +24,12 @@
|
||||
#include <dpp/json.h>
|
||||
#include <dpp/cache.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
integration::integration() :
|
||||
managed(),
|
||||
type(i_twitch),
|
||||
@@ -52,7 +54,8 @@ integration& integration::fill_from_json(nlohmann::json* j)
|
||||
{ "", i_discord },
|
||||
{ "youtube", i_youtube },
|
||||
{ "twitch", i_twitch },
|
||||
{ "discord", i_discord }
|
||||
{ "discord", i_discord },
|
||||
{ "guild_subscription", i_guild_subscription }
|
||||
};
|
||||
this->id = snowflake_not_null(j, "id");
|
||||
this->name = string_not_null(j, "name");
|
||||
|
||||
Vendored
+20
-11
@@ -22,22 +22,33 @@
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp {
|
||||
|
||||
invite::invite() : expires_at(0), guild_id(0), channel_id(0), inviter_id(0), target_user_id(0), target_user_type(1), approximate_presence_count(0), approximate_member_count(0), uses(0)
|
||||
using json = nlohmann::json;
|
||||
|
||||
invite::invite() : expires_at(0), guild_id(0), channel_id(0), inviter_id(0), target_user_id(0), target_type(0), approximate_presence_count(0), approximate_member_count(0), max_age(86400), max_uses(0), temporary(false), unique(false), uses(0), created_at(0)
|
||||
{
|
||||
}
|
||||
|
||||
invite& invite::fill_from_json(nlohmann::json* j) {
|
||||
code = string_not_null(j, "code");
|
||||
expires_at = (j->contains("expires_at")) ? ts_not_null(j, "expires_at") : 0;
|
||||
guild_id = (j->contains("guild")) ? snowflake_not_null(&((*j)["guild"]), "id") : 0;
|
||||
channel_id = (j->contains("channel")) ? snowflake_not_null(&((*j)["channel"]), "id") : 0;
|
||||
created_at = (j->contains("created_at")) ? ts_not_null(j, "created_at") : 0;
|
||||
if (j->contains("guild") && !j->at("guild").is_null()) {
|
||||
guild_id = snowflake_not_null(&((*j)["guild"]), "id");
|
||||
} else if (j->contains("guild_id")) { // check ID for the invite create event
|
||||
guild_id = snowflake_not_null(j, "guild_id");
|
||||
}
|
||||
if (j->contains("channel") && !j->at("channel").is_null()) {
|
||||
channel_id = snowflake_not_null(&((*j)["channel"]), "id");
|
||||
} else if (j->contains("channel_id")) { // check ID for the invite create event
|
||||
channel_id = snowflake_not_null(j, "channel_id");
|
||||
}
|
||||
inviter_id = (j->contains("inviter")) ? snowflake_not_null(&((*j)["inviter"]), "id") : 0;
|
||||
target_user_id = (j->contains("target_user")) ? snowflake_not_null(&((*j)["target_user"]), "id") : 0;
|
||||
target_user_type = int8_not_null(j, "target_user_type");
|
||||
target_type = int8_not_null(j, "target_type");
|
||||
approximate_presence_count = int32_not_null(j, "approximate_presence_count");
|
||||
approximate_member_count = int32_not_null(j, "approximate_member_count");
|
||||
max_age = int32_not_null(j, "max_age");
|
||||
@@ -53,14 +64,12 @@ invite& invite::fill_from_json(nlohmann::json* j) {
|
||||
|
||||
std::string invite::build_json(bool with_id) const {
|
||||
json j;
|
||||
if (max_age > 0)
|
||||
j["max_age"] = max_age;
|
||||
if (max_uses > 0)
|
||||
j["max_uses"] = max_uses;
|
||||
j["max_age"] = max_age;
|
||||
j["max_uses"] = max_uses;
|
||||
if (target_user_id > 0)
|
||||
j["target_user"] = target_user_id;
|
||||
if (target_user_type > 0)
|
||||
j["target_user_type"] = target_user_type;
|
||||
if (target_type > 0)
|
||||
j["target_type"] = target_type;
|
||||
if (temporary)
|
||||
j["temporary"] = temporary;
|
||||
if (unique)
|
||||
|
||||
Vendored
+13
-15
@@ -29,10 +29,12 @@
|
||||
#include <dpp/exception.h>
|
||||
#include <dpp/cluster.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
component::component() :
|
||||
type(cot_action_row), label(""), style(cos_primary), custom_id(""),
|
||||
min_values(-1), max_values(-1), min_length(0), max_length(0), disabled(false), required(false)
|
||||
@@ -532,9 +534,10 @@ message& message::set_file_content(const std::string &fc)
|
||||
return *this;
|
||||
}
|
||||
|
||||
message& message::add_file(const std::string &fn, const std::string &fc) {
|
||||
filecontent.push_back(fc);
|
||||
message& message::add_file(const std::string &fn, const std::string &fc, const std::string &fm) {
|
||||
filename.push_back(fn);
|
||||
filecontent.push_back(fc);
|
||||
filemimetype.push_back(fm);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -770,6 +773,8 @@ attachment::attachment(struct message* o, json *j) : attachment(o) {
|
||||
this->height = int32_not_null(j, "height");
|
||||
this->content_type = string_not_null(j, "content_type");
|
||||
this->ephemeral = bool_not_null(j, "ephemeral");
|
||||
this->duration_secs = double_not_null(j, "duration_secs");
|
||||
this->waveform = string_not_null(j, "waveform");
|
||||
}
|
||||
|
||||
void attachment::download(http_completion_event callback) const {
|
||||
@@ -953,6 +958,10 @@ bool message::suppress_notifications() const {
|
||||
return flags & m_suppress_notifications;
|
||||
}
|
||||
|
||||
bool message::is_voice_message() const {
|
||||
return flags & m_is_voice_message;
|
||||
}
|
||||
|
||||
message::~message() = default;
|
||||
|
||||
|
||||
@@ -1189,18 +1198,7 @@ std::string sticker_pack::build_json(bool with_id) const {
|
||||
}
|
||||
|
||||
std::string sticker::get_url() const {
|
||||
if (this->id) {
|
||||
static const std::map<sticker_format, std::string> extensions = {
|
||||
{ sticker_format::sf_png, "png" },
|
||||
{ sticker_format::sf_apng, "png" },
|
||||
{ sticker_format::sf_lottie, "json" },
|
||||
{ sticker_format::sf_gif, "gif" },
|
||||
};
|
||||
|
||||
return utility::cdn_host + "/stickers/" + std::to_string(this->id) + "." + extensions.find(this->format_type)->second;
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
return utility::cdn_endpoint_url_sticker(this->id, this->format_type);
|
||||
}
|
||||
|
||||
sticker& sticker::set_filename(const std::string &fn) {
|
||||
|
||||
Vendored
-12
@@ -23,18 +23,6 @@
|
||||
|
||||
namespace dpp {
|
||||
|
||||
permission::permission(const uint64_t &value) : value(value) {}
|
||||
|
||||
permission::permission() : permission(0) {}
|
||||
|
||||
permission::operator uint64_t() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
permission::operator uint64_t &() {
|
||||
return value;
|
||||
}
|
||||
|
||||
permission::operator nlohmann::json() const {
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
Vendored
+10
-23
@@ -24,43 +24,29 @@
|
||||
#include <dpp/emoji.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
std::string activity::get_large_asset_url(uint16_t size, const image_type format) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_jpg, "jpeg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->assets.large_image.empty() && this->application_id &&
|
||||
this->assets.large_image.find(':') == std::string::npos) { // make sure it's not a prefixed proxy image
|
||||
return utility::cdn_host + "/app-assets/" + std::to_string(this->application_id) + "/" + this->assets.large_image + "." + extensions.find(format)->second + utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp },
|
||||
"app-assets/" + std::to_string(this->application_id) + "/" + this->assets.large_image,
|
||||
format, size);
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
std::string activity::get_small_asset_url(uint16_t size, const image_type format) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_jpg, "jpeg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->assets.small_image.empty() && this->application_id &&
|
||||
this->assets.small_image.find(':') == std::string::npos) { // make sure it's not a prefixed proxy image
|
||||
return utility::cdn_host + "/app-assets/" + std::to_string(this->application_id) + "/" + this->assets.small_image + "." + extensions.find(format)->second + utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp },
|
||||
"app-assets/" + std::to_string(this->application_id) + "/" + this->assets.small_image,
|
||||
format, size);
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
@@ -246,6 +232,7 @@ std::string presence::build_json(bool with_id) const {
|
||||
{ps_online, "online"},
|
||||
{ps_offline, "offline"},
|
||||
{ps_idle, "idle"},
|
||||
{ps_invisible, "invisible"},
|
||||
{ps_dnd, "dnd"}
|
||||
};
|
||||
json j({
|
||||
|
||||
Vendored
+12
-11
@@ -35,17 +35,19 @@ namespace dpp {
|
||||
static std::string http_version = "DiscordBot (https://github.com/brainboxdotcc/DPP, " + std::to_string(DPP_VERSION_MAJOR) + "." + std::to_string(DPP_VERSION_MINOR) + "." + std::to_string(DPP_VERSION_PATCH) + ")";
|
||||
static const char* DISCORD_HOST = "https://discord.com";
|
||||
|
||||
http_request::http_request(const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata, http_method _method, const std::string &audit_reason, const std::string &filename, const std::string &filecontent)
|
||||
http_request::http_request(const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata, http_method _method, const std::string &audit_reason, const std::string &filename, const std::string &filecontent, const std::string &filemimetype)
|
||||
: complete_handler(completion), completed(false), non_discord(false), endpoint(_endpoint), parameters(_parameters), postdata(_postdata), method(_method), reason(audit_reason), mimetype("application/json"), waiting(false)
|
||||
{
|
||||
if (!filename.empty())
|
||||
file_name.push_back(filename);
|
||||
if (!filecontent.empty())
|
||||
file_content.push_back(filecontent);
|
||||
if (!filemimetype.empty())
|
||||
file_mimetypes.push_back(filemimetype);
|
||||
}
|
||||
|
||||
http_request::http_request(const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata, http_method method, const std::string &audit_reason, const std::vector<std::string> &filename, const std::vector<std::string> &filecontent)
|
||||
: complete_handler(completion), completed(false), non_discord(false), endpoint(_endpoint), parameters(_parameters), postdata(_postdata), method(method), reason(audit_reason), file_name(filename), file_content(filecontent), mimetype("application/json"), waiting(false)
|
||||
http_request::http_request(const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata, http_method method, const std::string &audit_reason, const std::vector<std::string> &filename, const std::vector<std::string> &filecontent, const std::vector<std::string> &filemimetypes)
|
||||
: complete_handler(completion), completed(false), non_discord(false), endpoint(_endpoint), parameters(_parameters), postdata(_postdata), method(method), reason(audit_reason), file_name(filename), file_content(filecontent), file_mimetypes(filemimetypes), mimetype("application/json"), waiting(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -68,7 +70,7 @@ void populate_result(const std::string &url, cluster* owner, http_request_comple
|
||||
rv.status = res.get_status();
|
||||
rv.body = res.get_content();
|
||||
for (auto &v : res.get_headers()) {
|
||||
rv.headers[v.first] = v.second;
|
||||
rv.headers.emplace(v.first, v.second);
|
||||
}
|
||||
|
||||
/* This will be ignored for non-discord requests without rate limit headers */
|
||||
@@ -78,7 +80,7 @@ void populate_result(const std::string &url, cluster* owner, http_request_comple
|
||||
rv.ratelimit_reset_after = from_string<uint64_t>(res.get_header("x-ratelimit-reset-after"));
|
||||
rv.ratelimit_bucket = res.get_header("x-ratelimit-bucket");
|
||||
rv.ratelimit_global = (res.get_header("x-ratelimit-global") == "true");
|
||||
owner->rest_ping = rv.latency;
|
||||
owner->rest_ping = rv.latency;
|
||||
if (res.get_header("x-ratelimit-retry-after") != "") {
|
||||
rv.ratelimit_retry_after = from_string<uint64_t>(res.get_header("x-ratelimit-retry-after"));
|
||||
}
|
||||
@@ -164,13 +166,12 @@ http_request_completion_t http_request::run(cluster* owner) {
|
||||
|
||||
multipart_content multipart;
|
||||
if (non_discord) {
|
||||
multipart = { postdata, "" };
|
||||
multipart = { postdata, mimetype };
|
||||
} else {
|
||||
|
||||
multipart = https_client::build_multipart(postdata, file_name, file_content);
|
||||
if (!multipart.mimetype.empty()) {
|
||||
headers.emplace("Content-Type", multipart.mimetype);
|
||||
}
|
||||
multipart = https_client::build_multipart(postdata, file_name, file_content, file_mimetypes);
|
||||
}
|
||||
if (!multipart.mimetype.empty()) {
|
||||
headers.emplace("Content-Type", multipart.mimetype);
|
||||
}
|
||||
http_connect_info hci = https_client::get_host_info(_host);
|
||||
try {
|
||||
|
||||
Vendored
+38
-12
@@ -26,10 +26,12 @@
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
role::role() :
|
||||
managed(),
|
||||
guild_id(0),
|
||||
@@ -39,6 +41,7 @@ role::role() :
|
||||
flags(0),
|
||||
integration_id(0),
|
||||
bot_id(0),
|
||||
subscription_listing_id(0),
|
||||
image_data(nullptr)
|
||||
{
|
||||
}
|
||||
@@ -80,8 +83,15 @@ role& role::fill_from_json(snowflake _guild_id, nlohmann::json* j)
|
||||
if (t.find("premium_subscriber") != t.end()) {
|
||||
this->flags |= dpp::r_premium_subscriber;
|
||||
}
|
||||
if (t.find("available_for_purchase") != t.end()) {
|
||||
this->flags |= dpp::r_available_for_purchase;
|
||||
}
|
||||
if (t.find("guild_connections") != t.end()) {
|
||||
this->flags |= dpp::r_guild_connections;
|
||||
}
|
||||
this->bot_id = snowflake_not_null(&t, "bot_id");
|
||||
this->integration_id = snowflake_not_null(&t, "integration_id");
|
||||
this->subscription_listing_id = snowflake_not_null(&t, "subscription_listing_id");
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -145,6 +155,18 @@ bool role::is_managed() const {
|
||||
return this->flags & dpp::r_managed;
|
||||
}
|
||||
|
||||
bool role::is_premium_subscriber() const {
|
||||
return this->flags & dpp::r_premium_subscriber;
|
||||
}
|
||||
|
||||
bool role::is_available_for_purchase() const {
|
||||
return this->flags & dpp::r_available_for_purchase;
|
||||
}
|
||||
|
||||
bool role::is_linked() const {
|
||||
return this->flags & dpp::r_guild_connections;
|
||||
}
|
||||
|
||||
bool role::has_create_instant_invite() const {
|
||||
return has_administrator() || permissions.has(p_create_instant_invite);
|
||||
}
|
||||
@@ -309,6 +331,18 @@ bool role::has_moderate_members() const {
|
||||
return has_administrator() || permissions.has(p_moderate_members);
|
||||
}
|
||||
|
||||
bool role::has_view_creator_monetization_analytics() const {
|
||||
return has_administrator() || permissions.has(p_view_creator_monetization_analytics);
|
||||
}
|
||||
|
||||
bool role::has_use_soundboard() const {
|
||||
return has_administrator() || permissions.has(p_use_soundboard);
|
||||
}
|
||||
|
||||
bool role::has_send_voice_messages() const {
|
||||
return has_administrator() || permissions.has(p_send_voice_messages);
|
||||
}
|
||||
|
||||
role& role::set_name(const std::string& n) {
|
||||
name = utility::validate(n, 1, 100, "Role name too short");
|
||||
return *this;
|
||||
@@ -363,18 +397,10 @@ members_container role::get_members() const {
|
||||
}
|
||||
|
||||
std::string role::get_icon_url(uint16_t size, const image_type format) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->icon.to_string().empty() && this->id) {
|
||||
return utility::cdn_host + "/role-icons/" + std::to_string(this->id) + "/" + this->icon.to_string() + "." + extensions.find(format)->second + utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp },
|
||||
"role-icons/" + std::to_string(this->id) + "/" + this->icon.to_string(),
|
||||
format, size);
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Vendored
+43
-36
@@ -141,19 +141,26 @@ void to_json(json& j, const command_option& opt) {
|
||||
}
|
||||
|
||||
/* Check for minimum and maximum values */
|
||||
if (opt.type == dpp::co_number || opt.type == dpp::co_integer || opt.type == dpp::co_string) {
|
||||
std::string key = (opt.type == dpp::co_string) ? "_length" : "_value";
|
||||
/* Min */
|
||||
if (std::holds_alternative<double>(opt.min_value)) {
|
||||
j["min" + key] = std::get<double>(opt.min_value);
|
||||
} else if (std::holds_alternative<int64_t>(opt.min_value)) {
|
||||
j["min" + key] = std::get<int64_t>(opt.min_value);
|
||||
if (opt.type == dpp::co_string) {
|
||||
if (std::holds_alternative<int64_t>(opt.min_value)) {
|
||||
j["min_length"] = std::get<int64_t>(opt.min_value);
|
||||
}
|
||||
if (std::holds_alternative<int64_t>(opt.max_value)) {
|
||||
j["max_length"] = std::get<int64_t>(opt.max_value);
|
||||
}
|
||||
} else if (opt.type == dpp::co_integer) {
|
||||
if (std::holds_alternative<int64_t>(opt.min_value)) {
|
||||
j["min_value"] = std::get<int64_t>(opt.min_value);
|
||||
}
|
||||
if (std::holds_alternative<int64_t>(opt.max_value)) {
|
||||
j["max_value"] = std::get<int64_t>(opt.max_value);
|
||||
}
|
||||
} else if (opt.type == dpp::co_number) {
|
||||
if (std::holds_alternative<double>(opt.min_value)) {
|
||||
j["min_value"] = std::get<double>(opt.min_value);
|
||||
}
|
||||
/* Max */
|
||||
if (std::holds_alternative<double>(opt.max_value)) {
|
||||
j["max" + key] = std::to_string(std::get<double>(opt.max_value));
|
||||
} else if (std::holds_alternative<int64_t>(opt.max_value)) {
|
||||
j["max" + key] = std::get<int64_t>(opt.max_value);
|
||||
j["max_value"] = std::get<double>(opt.max_value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,14 +226,15 @@ void to_json(json& j, const slashcommand& p) {
|
||||
j["name_localizations"][loc.first] = loc.second;
|
||||
}
|
||||
}
|
||||
if (p.description_localizations.size()) {
|
||||
j["description_localizations"] = json::object();
|
||||
for(auto& loc : p.description_localizations) {
|
||||
j["description_localizations"][loc.first] = loc.second;
|
||||
}
|
||||
}
|
||||
|
||||
if (p.type != ctxm_user && p.type != ctxm_message) {
|
||||
if (p.description_localizations.size()) {
|
||||
j["description_localizations"] = json::object();
|
||||
for(auto& loc : p.description_localizations) {
|
||||
j["description_localizations"][loc.first] = loc.second;
|
||||
}
|
||||
}
|
||||
|
||||
if (p.options.size()) {
|
||||
j["options"] = json();
|
||||
|
||||
@@ -360,11 +368,10 @@ command_option& command_option::set_auto_complete(bool autocomp)
|
||||
}
|
||||
|
||||
command_option &command_option::fill_from_json(nlohmann::json *j) {
|
||||
uint8_t i = 3; // maximum amount of nested options
|
||||
/*
|
||||
* Command options contains command options. Therefor the object is filled with recursion.
|
||||
*/
|
||||
std::function<void(nlohmann::json *, command_option &)> fill = [&i, &fill](nlohmann::json *j, command_option &o) {
|
||||
std::function<void(nlohmann::json *, command_option &, uint8_t)> fill = [&fill](nlohmann::json *j, command_option &o, uint8_t depth) {
|
||||
o.type = (command_option_type)int8_not_null(j, "type");
|
||||
o.name = string_not_null(j, "name");
|
||||
o.description = string_not_null(j, "description");
|
||||
@@ -386,11 +393,10 @@ command_option &command_option::fill_from_json(nlohmann::json *j) {
|
||||
}
|
||||
}
|
||||
|
||||
if (j->contains("options") && i > 0) {
|
||||
i--; // prevent infinite recursion call with a counter
|
||||
if (j->contains("options") && depth < 3) { // maximum amount of nested options. fixed to 3 levels: subcommand group -> subcommand -> its options
|
||||
for (auto &joption : (*j)["options"]) {
|
||||
command_option p;
|
||||
fill(&joption, p);
|
||||
fill(&joption, p, depth + 1);
|
||||
o.options.push_back(p);
|
||||
}
|
||||
}
|
||||
@@ -415,23 +421,15 @@ command_option &command_option::fill_from_json(nlohmann::json *j) {
|
||||
}
|
||||
}
|
||||
if (j->contains("min_length")) {
|
||||
if ((*j)["min_length"].is_number_integer()) {
|
||||
o.min_value.emplace<int64_t>(int64_not_null(j, "min_length"));
|
||||
} else if ((*j)["min_length"].is_number()) {
|
||||
o.min_value.emplace<double>(double_not_null(j, "min_length"));
|
||||
}
|
||||
o.min_value.emplace<int64_t>(int32_not_null(j, "min_length"));
|
||||
}
|
||||
if (j->contains("max_length")) {
|
||||
if ((*j)["max_length"].is_number_integer()) {
|
||||
o.max_value.emplace<int64_t>(int64_not_null(j, "max_length"));
|
||||
} else if ((*j)["max_length"].is_number()) {
|
||||
o.max_value.emplace<double>(double_not_null(j, "max_length"));
|
||||
}
|
||||
o.max_value.emplace<int64_t>(int32_not_null(j, "max_length"));
|
||||
}
|
||||
o.autocomplete = bool_not_null(j, "autocomplete");
|
||||
};
|
||||
|
||||
fill(j, *this);
|
||||
fill(j, *this, 0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -491,7 +489,9 @@ std::string interaction::build_json(bool with_id) const {
|
||||
|
||||
slashcommand& slashcommand::add_localization(const std::string& language, const std::string& _name, const std::string& _description) {
|
||||
name_localizations[language] = _name;
|
||||
description_localizations[language] = _description;
|
||||
if (! _description.empty()) {
|
||||
description_localizations[language] = _description;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -502,7 +502,9 @@ command_option_choice& command_option_choice::add_localization(const std::string
|
||||
|
||||
command_option& command_option::add_localization(const std::string& language, const std::string& _name, const std::string& _description) {
|
||||
name_localizations[language] = _name;
|
||||
description_localizations[language] = _description;
|
||||
if (! _description.empty()) {
|
||||
description_localizations[language] = _description;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -592,6 +594,11 @@ void from_json(const nlohmann::json& j, interaction& i) {
|
||||
i.guild_id = snowflake_not_null(&j, "guild_id");
|
||||
i.app_permissions = snowflake_not_null(&j, "app_permissions");
|
||||
|
||||
if (j.contains("channel") && !j.at("channel").is_null()) {
|
||||
const json& c = j["channel"];
|
||||
i.channel = channel().fill_from_json((json*)&c);
|
||||
}
|
||||
|
||||
if (j.contains("message") && !j.at("message").is_null()) {
|
||||
const json& m = j["message"];
|
||||
i.msg = message().fill_from_json((json*)&m, i.cache_policy);
|
||||
@@ -888,7 +895,7 @@ const dpp::role& interaction::get_resolved_role(snowflake id) const {
|
||||
}
|
||||
|
||||
const dpp::channel& interaction::get_resolved_channel(snowflake id) const {
|
||||
return get_resolved<channel, std::map<snowflake, channel>>(id, resolved.channels);
|
||||
return get_resolved<dpp::channel, std::map<snowflake, dpp::channel>>(id, resolved.channels);
|
||||
}
|
||||
|
||||
const dpp::guild_member& interaction::get_resolved_member(snowflake id) const {
|
||||
|
||||
Vendored
+2
-2
@@ -480,7 +480,7 @@ void ssl_client::read_loop()
|
||||
if (plaintext) {
|
||||
read_blocked_on_write = false;
|
||||
read_blocked = false;
|
||||
r = ::recv(sfd, server_to_client_buffer, DPP_BUFSIZE, 0);
|
||||
r = (int) ::recv(sfd, server_to_client_buffer, DPP_BUFSIZE, 0);
|
||||
if (r <= 0) {
|
||||
/* error or EOF */
|
||||
return;
|
||||
@@ -551,7 +551,7 @@ void ssl_client::read_loop()
|
||||
/* Try to write */
|
||||
|
||||
if (plaintext) {
|
||||
r = ::send(sfd, client_to_server_buffer + client_to_server_offset, (int)client_to_server_length, 0);
|
||||
r = (int) ::send(sfd, client_to_server_buffer + client_to_server_offset, (int)client_to_server_length, 0);
|
||||
|
||||
if (r < 0) {
|
||||
/* Write error */
|
||||
|
||||
Vendored
+12
-39
@@ -22,9 +22,10 @@
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/json.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include "user.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
namespace dpp {
|
||||
using json = nlohmann::
|
||||
json;
|
||||
|
||||
/* A mapping of discord's flag values to our bitmap (they're different bit positions to fit other stuff in) */
|
||||
std::map<uint32_t, dpp::user_flags> usermap = {
|
||||
@@ -45,8 +46,6 @@ std::map<uint32_t, dpp::user_flags> usermap = {
|
||||
{ 1 << 22, dpp::u_active_developer},
|
||||
};
|
||||
|
||||
namespace dpp {
|
||||
|
||||
user::user() :
|
||||
managed(),
|
||||
flags(0),
|
||||
@@ -101,26 +100,12 @@ user_identified::~user_identified() {
|
||||
}
|
||||
|
||||
std::string user::get_avatar_url(uint16_t size, const image_type format, bool prefer_animated) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_gif, "gif" },
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (this->avatar.to_string().empty()) {
|
||||
return get_default_avatar_url();
|
||||
} else if (this->id) {
|
||||
return utility::cdn_host + "/avatars/" +
|
||||
std::to_string(this->id) +
|
||||
(has_animated_icon() ? "/a_" : "/") +
|
||||
this->avatar.to_string() + "." +
|
||||
(has_animated_icon() && prefer_animated ? "gif" : extensions.find(format)->second) +
|
||||
utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url_hash({ i_jpg, i_png, i_webp, i_gif },
|
||||
"avatars/" + std::to_string(this->id), this->avatar.to_string(),
|
||||
format, size, prefer_animated, has_animated_icon());
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
@@ -128,7 +113,9 @@ std::string user::get_avatar_url(uint16_t size, const image_type format, bool pr
|
||||
|
||||
std::string user::get_default_avatar_url() const {
|
||||
if (this->discriminator) {
|
||||
return utility::cdn_host + "/embed/avatars/" + std::to_string(this->discriminator % 5) + ".png";
|
||||
return utility::cdn_endpoint_url({ i_png },
|
||||
"embed/avatars/" + std::to_string(this->discriminator % 5),
|
||||
i_png, 0);
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
@@ -249,24 +236,10 @@ bool user_identified::has_animated_banner() const {
|
||||
}
|
||||
|
||||
std::string user_identified::get_banner_url(uint16_t size, const image_type format, bool prefer_animated) const {
|
||||
static const std::map<image_type, std::string> extensions = {
|
||||
{ i_gif, "gif" },
|
||||
{ i_jpg, "jpg" },
|
||||
{ i_png, "png" },
|
||||
{ i_webp, "webp" },
|
||||
};
|
||||
|
||||
if (extensions.find(format) == extensions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (!this->banner.to_string().empty() && this->id) {
|
||||
return utility::cdn_host + "/banners/" +
|
||||
std::to_string(this->id) +
|
||||
(has_animated_banner() ? "/a_" : "/") +
|
||||
this->banner.to_string() + "." +
|
||||
(has_animated_banner() && prefer_animated ? "gif" : extensions.find(format)->second) +
|
||||
utility::avatar_size(size);
|
||||
return utility::cdn_endpoint_url_hash({ i_jpg, i_png, i_webp, i_gif },
|
||||
"banners/" + std::to_string(this->id), this->banner.to_string(),
|
||||
format, size, prefer_animated, has_animated_banner());
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Vendored
+47
@@ -53,6 +53,53 @@ namespace dpp {
|
||||
|
||||
namespace utility {
|
||||
|
||||
std::string cdn_endpoint_url(const std::vector<image_type> &allowed_formats, const std::string &path_without_extension, const dpp::image_type format, uint16_t size, bool prefer_animated, bool is_animated) {
|
||||
return cdn_endpoint_url_hash(allowed_formats, path_without_extension, "", format, size, prefer_animated, is_animated);
|
||||
}
|
||||
|
||||
std::string cdn_endpoint_url_hash(const std::vector<image_type> &allowed_formats, const std::string &path_without_extension, const std::string &hash, const dpp::image_type format, uint16_t size, bool prefer_animated, bool is_animated) {
|
||||
|
||||
if (std::find(allowed_formats.begin(), allowed_formats.end(), format) == allowed_formats.end()) {
|
||||
return std::string(); // if the given format is not allowed for this endpoint
|
||||
}
|
||||
|
||||
std::string extension;
|
||||
if (is_animated && (prefer_animated || format == i_gif)) {
|
||||
extension = ".gif";
|
||||
} else if (format == i_png) {
|
||||
extension = ".png";
|
||||
} else if (format == i_jpg) {
|
||||
extension = ".jpg";
|
||||
} else if (format == i_webp) {
|
||||
extension = ".webp";
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string suffix = (hash.empty() ? "" : (is_animated ? "/a_" : "/") + hash); // > In the case of endpoints that support GIFs, the hash will begin with a_ if it is available in GIF format.
|
||||
|
||||
return cdn_host + '/' + path_without_extension + suffix + extension + utility::avatar_size(size);
|
||||
}
|
||||
|
||||
std::string cdn_endpoint_url_sticker(snowflake sticker_id, sticker_format format) {
|
||||
if (!sticker_id) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string extension;
|
||||
if (format == sf_png || format == sf_apng) {
|
||||
extension = ".png";
|
||||
} else if (format == sf_lottie) {
|
||||
extension = ".json";
|
||||
} else if (format == sf_gif) {
|
||||
extension = ".gif";
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return utility::cdn_host + "/stickers/" + std::to_string(sticker_id) + extension;
|
||||
}
|
||||
|
||||
double time_f()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
|
||||
Vendored
+2
-2
@@ -22,10 +22,10 @@
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
voicestate::voicestate() : shard(nullptr), guild_id(0), channel_id(0), user_id(0), request_to_speak(0)
|
||||
{
|
||||
}
|
||||
|
||||
Vendored
+7
-2
@@ -35,9 +35,14 @@ webhook::webhook() : managed(), type(w_incoming), guild_id(0), channel_id(0), us
|
||||
|
||||
webhook::webhook(const std::string& webhook_url) : webhook()
|
||||
{
|
||||
token = webhook_url.substr(webhook_url.find_last_of("/") + 1);
|
||||
auto pos = webhook_url.find_last_of('/');
|
||||
if (pos == std::string::npos) { // throw when the url doesn't contain a slash at all
|
||||
throw dpp::logic_exception(std::string("Failed to parse webhook URL: No '/' found in the webhook url"));
|
||||
}
|
||||
try {
|
||||
id = std::stoull(webhook_url.substr(strlen("https://discord.com/api/webhooks/"), webhook_url.find_last_of("/")));
|
||||
token = webhook_url.substr(pos + 1);
|
||||
std::string endpoint = "https://discord.com/api/webhooks/";
|
||||
id = std::stoull(webhook_url.substr(endpoint.size(), pos));
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw dpp::logic_exception(std::string("Failed to parse webhook URL: ") + e.what());
|
||||
|
||||
Vendored
+695
-140
@@ -23,6 +23,7 @@
|
||||
#include <dpp/restrequest.h>
|
||||
#include <dpp/json.h>
|
||||
|
||||
|
||||
/* Unit tests go here */
|
||||
int main()
|
||||
{
|
||||
@@ -105,7 +106,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
set_test("HTTPS", false);
|
||||
if (!offline) {
|
||||
dpp::multipart_content multipart = dpp::https_client::build_multipart(
|
||||
"{\"content\":\"test\"}", {"test.txt", "blob.blob"}, {"ABCDEFGHI", "BLOB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"}
|
||||
"{\"content\":\"test\"}", {"test.txt", "blob.blob"}, {"ABCDEFGHI", "BLOB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"}, {"text/plain", "application/octet-stream"}
|
||||
);
|
||||
try {
|
||||
dpp::https_client c("discord.com", 443, "/api/channels/" + std::to_string(TEST_TEXT_CHANNEL_ID) + "/messages", "POST", multipart.body,
|
||||
@@ -136,6 +137,19 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
set_test("HTTP", false);
|
||||
}
|
||||
|
||||
set_test("MULTIHEADER", false);
|
||||
try {
|
||||
dpp::https_client c2("www.google.com", 80, "/", "GET", "", {}, true);
|
||||
size_t count = c2.get_header_count("set-cookie");
|
||||
size_t count_list = c2.get_header_list("set-cookie").size();
|
||||
// Google sets a bunch of cookies when we start accessing it.
|
||||
set_test("MULTIHEADER", c2.get_status() == 200 && count > 1 && count == count_list);
|
||||
}
|
||||
catch (const dpp::exception& e) {
|
||||
std::cout << e.what() << "\n";
|
||||
set_test("MULTIHEADER", false);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> testaudio = load_test_audio();
|
||||
|
||||
set_test("READFILE", false);
|
||||
@@ -168,6 +182,66 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
set_test("WEBHOOK", false);
|
||||
}
|
||||
|
||||
{ // test interaction_create_t::get_parameter
|
||||
// create a fake interaction
|
||||
dpp::cluster cluster("");
|
||||
dpp::discord_client client(&cluster, 1, 1, "");
|
||||
dpp::interaction_create_t interaction(&client, "");
|
||||
|
||||
/* Check the method with subcommands */
|
||||
set_test("GET_PARAMETER_WITH_SUBCOMMANDS", false);
|
||||
|
||||
dpp::command_interaction cmd_data; // command
|
||||
cmd_data.type = dpp::ctxm_chat_input;
|
||||
cmd_data.name = "command";
|
||||
|
||||
dpp::command_data_option subcommandgroup; // subcommand group
|
||||
subcommandgroup.name = "group";
|
||||
subcommandgroup.type = dpp::co_sub_command_group;
|
||||
|
||||
dpp::command_data_option subcommand; // subcommand
|
||||
subcommand.name = "add";
|
||||
subcommand.type = dpp::co_sub_command;
|
||||
|
||||
dpp::command_data_option option1; // slashcommand option
|
||||
option1.name = "user";
|
||||
option1.type = dpp::co_user;
|
||||
option1.value = dpp::snowflake(189759562910400512);
|
||||
|
||||
dpp::command_data_option option2; // slashcommand option
|
||||
option2.name = "checked";
|
||||
option2.type = dpp::co_boolean;
|
||||
option2.value = true;
|
||||
|
||||
// add them
|
||||
subcommand.options.push_back(option1);
|
||||
subcommand.options.push_back(option2);
|
||||
subcommandgroup.options.push_back(subcommand);
|
||||
cmd_data.options.push_back(subcommandgroup);
|
||||
interaction.command.data = cmd_data;
|
||||
|
||||
dpp::snowflake value1 = std::get<dpp::snowflake>(interaction.get_parameter("user"));
|
||||
set_test("GET_PARAMETER_WITH_SUBCOMMANDS", value1 == dpp::snowflake(189759562910400512));
|
||||
|
||||
/* Check the method without subcommands */
|
||||
set_test("GET_PARAMETER_WITHOUT_SUBCOMMANDS", false);
|
||||
|
||||
dpp::command_interaction cmd_data2; // command
|
||||
cmd_data2.type = dpp::ctxm_chat_input;
|
||||
cmd_data2.name = "command";
|
||||
|
||||
dpp::command_data_option option3; // slashcommand option
|
||||
option3.name = "number";
|
||||
option3.type = dpp::co_integer;
|
||||
option3.value = int64_t(123456);
|
||||
|
||||
cmd_data2.options.push_back(option3);
|
||||
interaction.command.data = cmd_data2;
|
||||
|
||||
int64_t value2 = std::get<int64_t>(interaction.get_parameter("number"));
|
||||
set_test("GET_PARAMETER_WITHOUT_SUBCOMMANDS", value2 == 123456);
|
||||
}
|
||||
|
||||
{ // test dpp::command_option_choice::fill_from_json
|
||||
set_test("OPTCHOICE_DOUBLE", false);
|
||||
set_test("OPTCHOICE_INT", false);
|
||||
@@ -219,15 +293,25 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
#ifndef _WIN32
|
||||
success = dpp::snowflake_not_null(&j, "value") == 5120 && success;
|
||||
#endif
|
||||
p.set(dpp::p_administrator, dpp::p_ban_members);
|
||||
success = p.has(dpp::p_administrator) && success;
|
||||
success = p.has(dpp::p_administrator) && p.has(dpp::p_ban_members) && success;
|
||||
success = p.has(dpp::p_administrator, dpp::p_ban_members) && success;
|
||||
success = p.has(dpp::p_administrator | dpp::p_ban_members) && success;
|
||||
p.set(0).add(~uint64_t{0}).remove(dpp::p_speak).set(dpp::p_administrator);
|
||||
success = !p.has(dpp::p_administrator, dpp::p_ban_members) && success; // must return false because they're not both set
|
||||
success = !p.has(dpp::p_administrator | dpp::p_ban_members) && success;
|
||||
|
||||
p.set(dpp::p_administrator);
|
||||
success = ! p.has(dpp::p_administrator, dpp::p_ban_members) && success; // must return false because they're not both set
|
||||
success = ! p.has(dpp::p_administrator | dpp::p_ban_members) && success;
|
||||
constexpr auto permission_test = [](dpp::permission p) constexpr noexcept {
|
||||
bool success{true};
|
||||
|
||||
p.set(0).add(~uint64_t{0}).remove(dpp::p_speak).set(dpp::p_connect);
|
||||
p.set(dpp::p_administrator, dpp::p_ban_members);
|
||||
success = p.has(dpp::p_administrator) && success;
|
||||
success = p.has(dpp::p_administrator) && p.has(dpp::p_ban_members) && success;
|
||||
success = p.has(dpp::p_administrator, dpp::p_ban_members) && success;
|
||||
success = p.has(dpp::p_administrator | dpp::p_ban_members) && success;
|
||||
success = p.add(dpp::p_speak).has(dpp::p_administrator, dpp::p_speak) && success;
|
||||
success = !p.remove(dpp::p_speak).has(dpp::p_administrator, dpp::p_speak) && success;
|
||||
return success;
|
||||
};
|
||||
constexpr auto constexpr_success = permission_test({~uint64_t{0}}); // test in constant evaluated
|
||||
success = permission_test({~uint64_t{0}}) && constexpr_success && success; // test at runtime
|
||||
set_test("PERMISSION_CLASS", success);
|
||||
}
|
||||
|
||||
@@ -247,6 +331,47 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
set_test("USER.GET_CREATION_TIME", (uint64_t)user1.get_creation_time() == 1465312605);
|
||||
}
|
||||
|
||||
{ // avatar size function
|
||||
set_test("UTILITY.AVATAR_SIZE", false);
|
||||
bool success = false;
|
||||
success = dpp::utility::avatar_size(0).empty();
|
||||
success = dpp::utility::avatar_size(16) == "?size=16" && success;
|
||||
success = dpp::utility::avatar_size(256) == "?size=256" && success;
|
||||
success = dpp::utility::avatar_size(4096) == "?size=4096" && success;
|
||||
success = dpp::utility::avatar_size(8192).empty() && success;
|
||||
success = dpp::utility::avatar_size(3000).empty() && success;
|
||||
set_test("UTILITY.AVATAR_SIZE", success);
|
||||
}
|
||||
|
||||
{ // cdn endpoint url getter
|
||||
set_test("UTILITY.CDN_ENDPOINT_URL_HASH", false);
|
||||
bool success = false;
|
||||
success = dpp::utility::cdn_endpoint_url_hash({ dpp::i_png }, "foobar/test", "", dpp::i_jpg, 0).empty();
|
||||
success = dpp::utility::cdn_endpoint_url_hash({ dpp::i_png }, "foobar/test", "", dpp::i_png, 0) == "https://cdn.discordapp.com/foobar/test.png" && success;
|
||||
success = dpp::utility::cdn_endpoint_url_hash({ dpp::i_png }, "foobar/test", "", dpp::i_png, 128) == "https://cdn.discordapp.com/foobar/test.png?size=128" && success;
|
||||
success = dpp::utility::cdn_endpoint_url_hash({ dpp::i_png, dpp::i_gif }, "foobar/test", "12345", dpp::i_gif, 0, false, true) == "https://cdn.discordapp.com/foobar/test/a_12345.gif" && success;
|
||||
success = dpp::utility::cdn_endpoint_url_hash({ dpp::i_png, dpp::i_gif }, "foobar/test", "12345", dpp::i_png, 0, false, true) == "https://cdn.discordapp.com/foobar/test/a_12345.png" && success;
|
||||
success = dpp::utility::cdn_endpoint_url_hash({ dpp::i_png, dpp::i_gif }, "foobar/test", "12345", dpp::i_png, 0, false, false) == "https://cdn.discordapp.com/foobar/test/12345.png" && success;
|
||||
success = dpp::utility::cdn_endpoint_url_hash({ dpp::i_png, dpp::i_gif }, "foobar/test", "12345", dpp::i_png, 0, true, true) == "https://cdn.discordapp.com/foobar/test/a_12345.gif" && success;
|
||||
success = dpp::utility::cdn_endpoint_url_hash({ dpp::i_png, dpp::i_gif }, "foobar/test", "", dpp::i_png, 0, true, true) == "https://cdn.discordapp.com/foobar/test.gif" && success;
|
||||
success = dpp::utility::cdn_endpoint_url_hash({ dpp::i_png, dpp::i_gif }, "foobar/test", "", dpp::i_gif, 0, false, false).empty() && success;
|
||||
set_test("UTILITY.CDN_ENDPOINT_URL_HASH", success);
|
||||
}
|
||||
|
||||
{ // sticker url getter
|
||||
set_test("STICKER.GET_URL", false);
|
||||
dpp::sticker s;
|
||||
s.format_type = dpp::sf_png;
|
||||
bool success = s.get_url().empty();
|
||||
s.id = 12345;
|
||||
success = s.get_url() == "https://cdn.discordapp.com/stickers/12345.png" && success;
|
||||
s.format_type = dpp::sf_gif;
|
||||
success = s.get_url() == "https://cdn.discordapp.com/stickers/12345.gif" && success;
|
||||
s.format_type = dpp::sf_lottie;
|
||||
success = s.get_url() == "https://cdn.discordapp.com/stickers/12345.json" && success;
|
||||
set_test("STICKER.GET_URL", success);
|
||||
}
|
||||
|
||||
{ // user url getter
|
||||
dpp::user user1;
|
||||
user1.id = 189759562910400512;
|
||||
@@ -275,6 +400,14 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
);
|
||||
}
|
||||
|
||||
{ // emoji url getter
|
||||
dpp::emoji emoji;
|
||||
emoji.id = 825407338755653641;
|
||||
|
||||
set_test("EMOJI.GET_URL", false);
|
||||
set_test("EMOJI.GET_URL", emoji.get_url() == dpp::utility::cdn_host + "/emojis/825407338755653641.png");
|
||||
}
|
||||
|
||||
{ // channel methods
|
||||
set_test("CHANNEL.SET_TYPE", false);
|
||||
dpp::channel c;
|
||||
@@ -367,9 +500,13 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
set_test("TIMESTRINGTOTIMESTAMP", true);
|
||||
#endif
|
||||
|
||||
set_test("TS", false);
|
||||
dpp::managed m(TEST_USER_ID);
|
||||
set_test("TS", ((uint64_t)m.get_creation_time()) == 1617131800);
|
||||
{
|
||||
set_test("TS", false);
|
||||
dpp::managed m(189759562910400512);
|
||||
set_test("TS", ((uint64_t) m.get_creation_time()) == 1465312605);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> test_image = load_test_image();
|
||||
|
||||
set_test("PRESENCE", false);
|
||||
set_test("CLUSTER", false);
|
||||
@@ -416,12 +553,14 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
bot.on_voice_receive_combined([&](auto& event) {
|
||||
});
|
||||
|
||||
bot.on_ready([&bot](const dpp::ready_t & event) {
|
||||
|
||||
std::promise<void> ready_promise;
|
||||
std::future ready_future = ready_promise.get_future();
|
||||
bot.on_ready([&](const dpp::ready_t & event) {
|
||||
set_test("CONNECTION", true);
|
||||
ready_promise.set_value();
|
||||
|
||||
set_test("APPCOMMAND", false);
|
||||
set_test("LOGGER", false);
|
||||
|
||||
bot.log(dpp::ll_info, "Test log message");
|
||||
|
||||
bot.guild_command_create(dpp::slashcommand().set_name("testcommand")
|
||||
@@ -429,21 +568,26 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
.add_option(dpp::command_option(dpp::co_attachment, "file", "a file"))
|
||||
.set_application_id(bot.me.id)
|
||||
.add_localization("fr", "zut", "Ou est la salor dans Discord?"),
|
||||
TEST_GUILD_ID, [&bot](const dpp::confirmation_callback_t &callback) {
|
||||
TEST_GUILD_ID, [&](const dpp::confirmation_callback_t &callback) {
|
||||
if (!callback.is_error()) {
|
||||
set_test("APPCOMMAND", true);
|
||||
set_test("DELCOMMAND", false);
|
||||
dpp::slashcommand s = std::get<dpp::slashcommand>(callback.value);
|
||||
bot.guild_command_delete(s.id, TEST_GUILD_ID, [&bot](const dpp::confirmation_callback_t &callback) {
|
||||
bot.guild_command_delete(s.id, TEST_GUILD_ID, [&](const dpp::confirmation_callback_t &callback) {
|
||||
if (!callback.is_error()) {
|
||||
dpp::message test_message(TEST_TEXT_CHANNEL_ID, "test message");
|
||||
|
||||
set_test("DELCOMMAND", true);
|
||||
set_test("MESSAGECREATE", false);
|
||||
set_test("MESSAGEEDIT", false);
|
||||
set_test("MESSAGERECEIVE", false);
|
||||
bot.message_create(dpp::message(TEST_TEXT_CHANNEL_ID, "test message"), [&bot](const dpp::confirmation_callback_t &callback) {
|
||||
test_message.add_file("no-mime", "test");
|
||||
test_message.add_file("test.txt", "test", "text/plain");
|
||||
test_message.add_file("test.png", std::string{test_image.begin(), test_image.end()}, "image/png");
|
||||
bot.message_create(test_message, [&bot](const dpp::confirmation_callback_t &callback) {
|
||||
if (!callback.is_error()) {
|
||||
set_test("MESSAGECREATE", true);
|
||||
set_test("REACT", false);
|
||||
set_test("MESSAGEDELETE", false);
|
||||
dpp::message m = std::get<dpp::message>(callback.value);
|
||||
set_test("REACTEVENT", false);
|
||||
bot.message_add_reaction(m.id, TEST_TEXT_CHANNEL_ID, "😄", [](const dpp::confirmation_callback_t &callback) {
|
||||
@@ -453,16 +597,12 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
set_test("REACT", false);
|
||||
}
|
||||
});
|
||||
bot.message_delete(m.id, TEST_TEXT_CHANNEL_ID, [](const dpp::confirmation_callback_t &callback) {
|
||||
|
||||
set_test("EDITEVENT", false);
|
||||
bot.message_edit(dpp::message(m).set_content("test edit"), [](const dpp::confirmation_callback_t &callback) {
|
||||
if (!callback.is_error()) {
|
||||
set_test("MESSAGEDELETE", true);
|
||||
} else {
|
||||
set_test("MESSAGEDELETE", false);
|
||||
set_test("MESSAGEEDIT", true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
set_test("MESSAGECREATE", false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -471,6 +611,475 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
std::mutex loglock;
|
||||
bot.on_log([&](const dpp::log_t & event) {
|
||||
std::lock_guard<std::mutex> locker(loglock);
|
||||
if (event.severity > dpp::ll_trace) {
|
||||
std::cout << "[" << std::fixed << std::setprecision(3) << (dpp::utility::time_f() - get_start_time()) << "]: [\u001b[36m" << dpp::utility::loglevel(event.severity) << "\u001b[0m] " << event.message << "\n";
|
||||
}
|
||||
if (event.message == "Test log message") {
|
||||
set_test("LOGGER", true);
|
||||
}
|
||||
});
|
||||
|
||||
set_test("RUNONCE", false);
|
||||
uint8_t runs = 0;
|
||||
for (int x = 0; x < 10; ++x) {
|
||||
if (dpp::run_once<struct test_run>()) {
|
||||
runs++;
|
||||
}
|
||||
}
|
||||
set_test("RUNONCE", (runs == 1));
|
||||
|
||||
bot.on_message_reaction_add([&](const dpp::message_reaction_add_t & event) {
|
||||
if (event.reacting_user.id == bot.me.id && event.reacting_emoji.name == "😄") {
|
||||
set_test("REACTEVENT", true);
|
||||
}
|
||||
});
|
||||
|
||||
bool message_edit_tested = false;
|
||||
bot.on_message_update([&](const dpp::message_update_t & event) {
|
||||
if (!message_edit_tested && event.msg.author == bot.me.id && event.msg.content == "test edit") {
|
||||
message_edit_tested = true;
|
||||
set_test("EDITEVENT", true);
|
||||
}
|
||||
});
|
||||
|
||||
bot.on_voice_ready([&](const dpp::voice_ready_t & event) {
|
||||
set_test("VOICECONN", true);
|
||||
dpp::discord_voice_client* v = event.voice_client;
|
||||
set_test("VOICESEND", false);
|
||||
if (v && v->is_ready()) {
|
||||
v->send_audio_raw((uint16_t*)testaudio.data(), testaudio.size());
|
||||
} else {
|
||||
set_test("VOICESEND", false);
|
||||
}
|
||||
});
|
||||
|
||||
bot.on_invite_create([](const dpp::invite_create_t &event) {
|
||||
auto &inv = event.created_invite;
|
||||
if (!inv.code.empty() && inv.channel_id == TEST_TEXT_CHANNEL_ID && inv.guild_id == TEST_GUILD_ID && inv.created_at != 0 && inv.max_uses == 100) {
|
||||
set_test("INVITE_CREATE_EVENT", true);
|
||||
}
|
||||
});
|
||||
|
||||
bot.on_invite_delete([](const dpp::invite_delete_t &event) {
|
||||
auto &inv = event.deleted_invite;
|
||||
if (!inv.code.empty() && inv.channel_id == TEST_TEXT_CHANNEL_ID && inv.guild_id == TEST_GUILD_ID) {
|
||||
set_test("INVITE_DELETE_EVENT", true);
|
||||
}
|
||||
});
|
||||
|
||||
bot.on_voice_buffer_send([&](const dpp::voice_buffer_send_t & event) {
|
||||
if (event.buffer_size == 0) {
|
||||
set_test("VOICESEND", true);
|
||||
}
|
||||
});
|
||||
|
||||
set_test("SYNC", false);
|
||||
if (!offline) {
|
||||
dpp::message m = dpp::sync<dpp::message>(&bot, &dpp::cluster::message_create, dpp::message(TEST_TEXT_CHANNEL_ID, "TEST"));
|
||||
set_test("SYNC", m.content == "TEST");
|
||||
}
|
||||
|
||||
bot.on_guild_create([&](const dpp::guild_create_t & event) {
|
||||
if (event.created->id == TEST_GUILD_ID) {
|
||||
set_test("GUILDCREATE", true);
|
||||
if (event.presences.size() && event.presences.begin()->second.user_id > 0) {
|
||||
set_test("PRESENCE", true);
|
||||
}
|
||||
dpp::guild* g = dpp::find_guild(TEST_GUILD_ID);
|
||||
set_test("CACHE", false);
|
||||
if (g) {
|
||||
set_test("CACHE", true);
|
||||
set_test("VOICECONN", false);
|
||||
dpp::discord_client* s = bot.get_shard(0);
|
||||
s->connect_voice(g->id, TEST_VC_ID, false, false);
|
||||
}
|
||||
else {
|
||||
set_test("CACHE", false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// this helper class contains logic for the message tests, deletes the message when all tests are done
|
||||
class message_test_helper
|
||||
{
|
||||
private:
|
||||
std::mutex mutex;
|
||||
bool pin_tested;
|
||||
std::array<bool, 3> files_tested;
|
||||
std::array<bool, 3> files_success;
|
||||
dpp::snowflake channel_id;
|
||||
dpp::snowflake message_id;
|
||||
dpp::cluster ⊥
|
||||
|
||||
void delete_message_if_done() {
|
||||
if (files_tested == std::array{true, true, true} && pin_tested) {
|
||||
set_test("MESSAGEDELETE", false);
|
||||
bot.message_delete(message_id, channel_id, [](const dpp::confirmation_callback_t &callback) {
|
||||
if (!callback.is_error()) {
|
||||
set_test("MESSAGEDELETE", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void set_pin_tested() {
|
||||
assert(!pin_tested);
|
||||
pin_tested = true;
|
||||
delete_message_if_done();
|
||||
}
|
||||
|
||||
void set_file_tested(size_t index) {
|
||||
assert(!files_tested[index]);
|
||||
files_tested[index] = true;
|
||||
if (files_tested == std::array{true, true, true}) {
|
||||
set_test("MESSAGEFILE", files_success == std::array{true, true, true});
|
||||
}
|
||||
delete_message_if_done();
|
||||
}
|
||||
|
||||
void test_files(const dpp::message &message) {
|
||||
set_test("MESSAGEFILE", false);
|
||||
if (message.attachments.size() == 3) {
|
||||
static constexpr auto check_mimetype = [](const auto &headers, std::string mimetype) {
|
||||
if (auto it = headers.find("content-type"); it != headers.end()) {
|
||||
// check that the mime type starts with what we gave : for example discord will change "text/plain" to "text/plain; charset=UTF-8"
|
||||
return it->second.size() >= mimetype.size() && std::equal(it->second.begin(), it->second.begin() + mimetype.size(), mimetype.begin());
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
message.attachments[0].download([&](const dpp::http_request_completion_t &callback) {
|
||||
std::lock_guard lock(mutex);
|
||||
if (callback.status == 200 && callback.body == "test") {
|
||||
files_success[0] = true;
|
||||
}
|
||||
set_file_tested(0);
|
||||
});
|
||||
message.attachments[1].download([&](const dpp::http_request_completion_t &callback) {
|
||||
std::lock_guard lock(mutex);
|
||||
if (callback.status == 200 && check_mimetype(callback.headers, "text/plain") && callback.body == "test") {
|
||||
files_success[1] = true;
|
||||
}
|
||||
set_file_tested(1);
|
||||
});
|
||||
message.attachments[2].download([&](const dpp::http_request_completion_t &callback) {
|
||||
std::lock_guard lock(mutex);
|
||||
// do not check the contents here because discord can change compression
|
||||
if (callback.status == 200 && check_mimetype(callback.headers, "image/png")) {
|
||||
files_success[2] = true;
|
||||
}
|
||||
set_file_tested(2);
|
||||
});
|
||||
}
|
||||
else {
|
||||
set_file_tested(0);
|
||||
set_file_tested(1);
|
||||
set_file_tested(2);
|
||||
}
|
||||
}
|
||||
|
||||
void test_pin() {
|
||||
set_test("MESSAGEPIN", false);
|
||||
set_test("MESSAGEUNPIN", false);
|
||||
bot.message_pin(channel_id, message_id, [=](const dpp::confirmation_callback_t &callback) {
|
||||
std::lock_guard lock(mutex);
|
||||
if (!callback.is_error()) {
|
||||
set_test("MESSAGEPIN", true);
|
||||
bot.message_unpin(TEST_TEXT_CHANNEL_ID, message_id, [=](const dpp::confirmation_callback_t &callback) {
|
||||
std::lock_guard lock(mutex);
|
||||
if (!callback.is_error()) {
|
||||
set_test("MESSAGEUNPIN", true);
|
||||
}
|
||||
set_pin_tested();
|
||||
});
|
||||
}
|
||||
else {
|
||||
set_pin_tested();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public:
|
||||
message_test_helper(dpp::cluster &_bot) : bot(_bot) {}
|
||||
|
||||
void run(const dpp::message &message) {
|
||||
pin_tested = false;
|
||||
files_tested = {false, false, false};
|
||||
files_success = {false, false, false};
|
||||
channel_id = message.channel_id;
|
||||
message_id = message.id;
|
||||
test_pin();
|
||||
test_files(message);
|
||||
}
|
||||
};
|
||||
|
||||
message_test_helper message_helper(bot);
|
||||
bool message_tested = false;
|
||||
bot.on_message_create([&](const dpp::message_create_t & event) {
|
||||
if (event.msg.author.id == bot.me.id && !message_tested) {
|
||||
message_tested = true;
|
||||
set_test("MESSAGERECEIVE", true);
|
||||
message_helper.run(event.msg);
|
||||
set_test("MESSAGESGET", false);
|
||||
bot.messages_get(event.msg.channel_id, 0, event.msg.id, 0, 5, [](const dpp::confirmation_callback_t &cc){
|
||||
if (!cc.is_error()) {
|
||||
dpp::message_map mm = std::get<dpp::message_map>(cc.value);
|
||||
if (mm.size()) {
|
||||
set_test("MESSAGESGET", true);
|
||||
set_test("TIMESTAMP", false);
|
||||
dpp::message m = mm.begin()->second;
|
||||
if (m.sent > 0) {
|
||||
set_test("TIMESTAMP", true);
|
||||
} else {
|
||||
set_test("TIMESTAMP", false);
|
||||
}
|
||||
} else {
|
||||
set_test("MESSAGESGET", false);
|
||||
}
|
||||
} else {
|
||||
set_test("MESSAGESGET", false);
|
||||
}
|
||||
});
|
||||
set_test("MSGCREATESEND", false);
|
||||
event.send("MSGCREATESEND", [&bot, ch_id = event.msg.channel_id] (const auto& cc) {
|
||||
if (!cc.is_error()) {
|
||||
dpp::message m = std::get<dpp::message>(cc.value);
|
||||
if (m.channel_id == ch_id) {
|
||||
set_test("MSGCREATESEND", true);
|
||||
} else {
|
||||
bot.log(dpp::ll_debug, cc.http_info.body);
|
||||
set_test("MSGCREATESEND", false);
|
||||
}
|
||||
bot.message_delete(m.id, m.channel_id);
|
||||
} else {
|
||||
bot.log(dpp::ll_debug, cc.http_info.body);
|
||||
set_test("MSGCREATESEND", false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// set to execute from this thread (main thread) after on_ready is fired
|
||||
auto do_online_tests = [&] {
|
||||
set_test("GUILD_BAN_CREATE", false);
|
||||
set_test("GUILD_BAN_GET", false);
|
||||
set_test("GUILD_BANS_GET", false);
|
||||
set_test("GUILD_BAN_DELETE", false);
|
||||
if (!offline) {
|
||||
// some deleted discord accounts to test the ban stuff with...
|
||||
dpp::snowflake deadUser1(802670069523415057);
|
||||
dpp::snowflake deadUser2(875302419335094292);
|
||||
dpp::snowflake deadUser3(1048247361903792198);
|
||||
|
||||
bot.set_audit_reason("ban reason one").guild_ban_add(TEST_GUILD_ID, deadUser1, 0, [deadUser1, deadUser2, deadUser3, &bot](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) bot.guild_ban_add(TEST_GUILD_ID, deadUser2, 0, [deadUser1, deadUser2, deadUser3, &bot](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) bot.set_audit_reason("ban reason three").guild_ban_add(TEST_GUILD_ID, deadUser3, 0, [deadUser1, deadUser2, deadUser3, &bot](const dpp::confirmation_callback_t &event) {
|
||||
if (event.is_error()) {
|
||||
return;
|
||||
}
|
||||
set_test("GUILD_BAN_CREATE", true);
|
||||
// when created, continue with getting and deleting
|
||||
|
||||
// get ban
|
||||
bot.guild_get_ban(TEST_GUILD_ID, deadUser1, [deadUser1](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) {
|
||||
dpp::ban ban = event.get<dpp::ban>();
|
||||
if (ban.user_id == deadUser1 && ban.reason == "ban reason one") {
|
||||
set_test("GUILD_BAN_GET", true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// get multiple bans
|
||||
bot.guild_get_bans(TEST_GUILD_ID, 0, deadUser1, 3, [deadUser2, deadUser3](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) {
|
||||
dpp::ban_map bans = event.get<dpp::ban_map>();
|
||||
int successCount = 0;
|
||||
for (auto &ban: bans) {
|
||||
if (ban.first == ban.second.user_id) { // the key should match the ban's user_id
|
||||
if (ban.first == deadUser2 && ban.second.reason.empty()) {
|
||||
successCount++;
|
||||
} else if (ban.first == deadUser3 && ban.second.reason == "ban reason three") {
|
||||
successCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (successCount == 2) {
|
||||
set_test("GUILD_BANS_GET", true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// unban them
|
||||
bot.guild_ban_delete(TEST_GUILD_ID, deadUser1, [&bot, deadUser2, deadUser3](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) {
|
||||
bot.guild_ban_delete(TEST_GUILD_ID, deadUser2, [&bot, deadUser3](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) {
|
||||
bot.guild_ban_delete(TEST_GUILD_ID, deadUser3, [](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) {
|
||||
set_test("GUILD_BAN_DELETE", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
set_test("REQUEST_GET_IMAGE", false);
|
||||
if (!offline) {
|
||||
bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get, [&bot](const dpp::http_request_completion_t &callback) {
|
||||
if (callback.status != 200) {
|
||||
return;
|
||||
}
|
||||
set_test("REQUEST_GET_IMAGE", true);
|
||||
|
||||
dpp::emoji emoji;
|
||||
emoji.load_image(callback.body, dpp::i_png);
|
||||
emoji.name = "dpp";
|
||||
|
||||
// emoji unit test with the requested image
|
||||
set_test("EMOJI_CREATE", false);
|
||||
set_test("EMOJI_GET", false);
|
||||
set_test("EMOJI_DELETE", false);
|
||||
bot.guild_emoji_create(TEST_GUILD_ID, emoji, [&bot](const dpp::confirmation_callback_t &event) {
|
||||
if (event.is_error()) {
|
||||
return;
|
||||
}
|
||||
set_test("EMOJI_CREATE", true);
|
||||
|
||||
auto created = event.get<dpp::emoji>();
|
||||
bot.guild_emoji_get(TEST_GUILD_ID, created.id, [&bot, created](const dpp::confirmation_callback_t &event) {
|
||||
if (event.is_error()) {
|
||||
return;
|
||||
}
|
||||
auto fetched = event.get<dpp::emoji>();
|
||||
if (created.id == fetched.id && created.name == fetched.name && created.flags == fetched.flags) {
|
||||
set_test("EMOJI_GET", true);
|
||||
}
|
||||
|
||||
bot.guild_emoji_delete(TEST_GUILD_ID, fetched.id, [](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) {
|
||||
set_test("EMOJI_DELETE", true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
set_test("INVITE_CREATE", false);
|
||||
set_test("INVITE_GET", false);
|
||||
set_test("INVITE_DELETE", false);
|
||||
if (!offline) {
|
||||
dpp::channel channel;
|
||||
channel.id = TEST_TEXT_CHANNEL_ID;
|
||||
dpp::invite invite;
|
||||
invite.max_age = 0;
|
||||
invite.max_uses = 100;
|
||||
set_test("INVITE_CREATE_EVENT", false);
|
||||
bot.channel_invite_create(channel, invite, [&bot, invite](const dpp::confirmation_callback_t &event) {
|
||||
if (event.is_error()) return;
|
||||
|
||||
auto created = event.get<dpp::invite>();
|
||||
if (!created.code.empty() && created.channel_id == TEST_TEXT_CHANNEL_ID && created.guild_id == TEST_GUILD_ID && created.inviter_id != 0) {
|
||||
set_test("INVITE_CREATE", true);
|
||||
}
|
||||
|
||||
bot.invite_get(created.code, [&bot, created](const dpp::confirmation_callback_t &event) {
|
||||
if (event.is_error()) return;
|
||||
|
||||
auto retrieved = event.get<dpp::invite>();
|
||||
if (retrieved.code == created.code && retrieved.expires_at == 0 && retrieved.guild_id == created.guild_id && retrieved.channel_id == created.channel_id && retrieved.inviter_id == created.inviter_id) {
|
||||
set_test("INVITE_GET", true);
|
||||
}
|
||||
|
||||
set_test("INVITE_DELETE_EVENT", false);
|
||||
bot.invite_delete(retrieved.code, [](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) {
|
||||
set_test("INVITE_DELETE", true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
set_test("AUTOMOD_RULE_CREATE", false);
|
||||
set_test("AUTOMOD_RULE_GET", false);
|
||||
set_test("AUTOMOD_RULE_GET_ALL", false);
|
||||
set_test("AUTOMOD_RULE_DELETE", false);
|
||||
if (!offline) {
|
||||
dpp::automod_rule automodRule;
|
||||
automodRule.name = "automod rule (keyword type)";
|
||||
automodRule.trigger_type = dpp::amod_type_keyword;
|
||||
dpp::automod_metadata metadata1;
|
||||
metadata1.keywords.emplace_back("*cat*");
|
||||
metadata1.keywords.emplace_back("train");
|
||||
metadata1.keywords.emplace_back("*.exe");
|
||||
metadata1.regex_patterns.emplace_back("^[^a-z]$");
|
||||
metadata1.allow_list.emplace_back("@silent*");
|
||||
automodRule.trigger_metadata = metadata1;
|
||||
dpp::automod_action automodAction;
|
||||
automodAction.type = dpp::amod_action_timeout;
|
||||
automodAction.duration_seconds = 6000;
|
||||
automodRule.actions.emplace_back(automodAction);
|
||||
|
||||
bot.automod_rules_get(TEST_GUILD_ID, [&bot, automodRule](const dpp::confirmation_callback_t &event) {
|
||||
if (event.is_error()) {
|
||||
return;
|
||||
}
|
||||
auto rules = event.get<dpp::automod_rule_map>();
|
||||
set_test("AUTOMOD_RULE_GET_ALL", true);
|
||||
for (const auto &rule: rules) {
|
||||
if (rule.second.trigger_type == dpp::amod_type_keyword) {
|
||||
// delete one automod rule of type KEYWORD before creating one to make space...
|
||||
bot.automod_rule_delete(TEST_GUILD_ID, rule.first);
|
||||
}
|
||||
}
|
||||
|
||||
// start creating the automod rules
|
||||
bot.automod_rule_create(TEST_GUILD_ID, automodRule, [&bot, automodRule](const dpp::confirmation_callback_t &event) {
|
||||
if (event.is_error()) {
|
||||
return;
|
||||
}
|
||||
auto created = event.get<dpp::automod_rule>();
|
||||
if (created.name == automodRule.name) {
|
||||
set_test("AUTOMOD_RULE_CREATE", true);
|
||||
}
|
||||
|
||||
// get automod rule
|
||||
bot.automod_rule_get(TEST_GUILD_ID, created.id, [automodRule, &bot, created](const dpp::confirmation_callback_t &event) {
|
||||
if (event.is_error()) {
|
||||
return;
|
||||
}
|
||||
auto retrieved = event.get<dpp::automod_rule>();
|
||||
if (retrieved.name == automodRule.name &&
|
||||
retrieved.trigger_type == automodRule.trigger_type &&
|
||||
retrieved.trigger_metadata.keywords == automodRule.trigger_metadata.keywords &&
|
||||
retrieved.trigger_metadata.regex_patterns == automodRule.trigger_metadata.regex_patterns &&
|
||||
retrieved.trigger_metadata.allow_list == automodRule.trigger_metadata.allow_list && retrieved.actions.size() == automodRule.actions.size()) {
|
||||
set_test("AUTOMOD_RULE_GET", true);
|
||||
}
|
||||
|
||||
// delete the automod rule
|
||||
bot.automod_rule_delete(TEST_GUILD_ID, retrieved.id, [](const dpp::confirmation_callback_t &event) {
|
||||
if (!event.is_error()) {
|
||||
set_test("AUTOMOD_RULE_DELETE", true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
set_test("USER_GET", false);
|
||||
set_test("USER_GET_FLAGS", false);
|
||||
@@ -519,6 +1128,59 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
});
|
||||
}
|
||||
|
||||
set_test("VOICE_CHANNEL_CREATE", false);
|
||||
set_test("VOICE_CHANNEL_EDIT", false);
|
||||
set_test("VOICE_CHANNEL_DELETE", false);
|
||||
if (!offline) {
|
||||
dpp::channel channel1;
|
||||
channel1.set_type(dpp::CHANNEL_VOICE)
|
||||
.set_guild_id(TEST_GUILD_ID)
|
||||
.set_name("voice1")
|
||||
.add_permission_overwrite(TEST_GUILD_ID, dpp::ot_role, 0, dpp::p_view_channel)
|
||||
.set_user_limit(99);
|
||||
dpp::channel createdChannel;
|
||||
try {
|
||||
createdChannel = bot.channel_create_sync(channel1);
|
||||
} catch (dpp::rest_exception &exception) {
|
||||
set_test("VOICE_CHANNEL_CREATE", false);
|
||||
}
|
||||
if (createdChannel.name == channel1.name &&
|
||||
createdChannel.user_limit == 99 &&
|
||||
createdChannel.name == "voice1") {
|
||||
for (auto overwrite: createdChannel.permission_overwrites) {
|
||||
if (overwrite.id == TEST_GUILD_ID && overwrite.type == dpp::ot_role && overwrite.deny == dpp::p_view_channel) {
|
||||
set_test("VOICE_CHANNEL_CREATE", true);
|
||||
}
|
||||
}
|
||||
|
||||
// edit the voice channel
|
||||
createdChannel.set_name("foobar2");
|
||||
createdChannel.set_user_limit(2);
|
||||
for (auto overwrite: createdChannel.permission_overwrites) {
|
||||
if (overwrite.id == TEST_GUILD_ID) {
|
||||
overwrite.deny.set(0);
|
||||
overwrite.allow.set(dpp::p_view_channel);
|
||||
}
|
||||
}
|
||||
try {
|
||||
dpp::channel edited = bot.channel_edit_sync(createdChannel);
|
||||
if (edited.name == "foobar2" && edited.user_limit == 2) {
|
||||
set_test("VOICE_CHANNEL_EDIT", true);
|
||||
}
|
||||
} catch (dpp::rest_exception &exception) {
|
||||
set_test("VOICE_CHANNEL_EDIT", false);
|
||||
}
|
||||
|
||||
// delete the voice channel
|
||||
try {
|
||||
bot.channel_delete_sync(createdChannel.id);
|
||||
set_test("VOICE_CHANNEL_DELETE", true);
|
||||
} catch (dpp::rest_exception &exception) {
|
||||
set_test("VOICE_CHANNEL_DELETE", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_test("FORUM_CREATION", false);
|
||||
set_test("FORUM_CHANNEL_GET", false);
|
||||
set_test("FORUM_CHANNEL_DELETE", false);
|
||||
@@ -630,120 +1292,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
set_test("ROLE_DELETE", false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
std::mutex loglock;
|
||||
bot.on_log([&](const dpp::log_t & event) {
|
||||
std::lock_guard<std::mutex> locker(loglock);
|
||||
if (event.severity > dpp::ll_trace) {
|
||||
std::cout << "[" << std::fixed << std::setprecision(3) << (dpp::utility::time_f() - get_start_time()) << "]: [\u001b[36m" << dpp::utility::loglevel(event.severity) << "\u001b[0m] " << event.message << "\n";
|
||||
}
|
||||
if (event.message == "Test log message") {
|
||||
set_test("LOGGER", true);
|
||||
}
|
||||
});
|
||||
|
||||
set_test("RUNONCE", false);
|
||||
uint8_t runs = 0;
|
||||
for (int x = 0; x < 10; ++x) {
|
||||
if (dpp::run_once<struct test_run>()) {
|
||||
runs++;
|
||||
}
|
||||
}
|
||||
set_test("RUNONCE", (runs == 1));
|
||||
|
||||
bot.on_message_reaction_add([&](const dpp::message_reaction_add_t & event) {
|
||||
if (event.reacting_user.id == bot.me.id && event.reacting_emoji.name == "😄") {
|
||||
set_test("REACTEVENT", true);
|
||||
}
|
||||
});
|
||||
|
||||
bot.on_voice_ready([&](const dpp::voice_ready_t & event) {
|
||||
set_test("VOICECONN", true);
|
||||
dpp::discord_voice_client* v = event.voice_client;
|
||||
set_test("VOICESEND", false);
|
||||
if (v && v->is_ready()) {
|
||||
v->send_audio_raw((uint16_t*)testaudio.data(), testaudio.size());
|
||||
} else {
|
||||
set_test("VOICESEND", false);
|
||||
}
|
||||
});
|
||||
|
||||
bot.on_voice_buffer_send([&](const dpp::voice_buffer_send_t & event) {
|
||||
if (event.buffer_size == 0) {
|
||||
set_test("VOICESEND", true);
|
||||
}
|
||||
});
|
||||
|
||||
set_test("SYNC", false);
|
||||
if (!offline) {
|
||||
dpp::message m = dpp::sync<dpp::message>(&bot, &dpp::cluster::message_create, dpp::message(TEST_TEXT_CHANNEL_ID, "TEST"));
|
||||
set_test("SYNC", m.content == "TEST");
|
||||
}
|
||||
|
||||
bot.on_guild_create([&](const dpp::guild_create_t & event) {
|
||||
if (event.created->id == TEST_GUILD_ID) {
|
||||
set_test("GUILDCREATE", true);
|
||||
if (event.presences.size() && event.presences.begin()->second.user_id > 0) {
|
||||
set_test("PRESENCE", true);
|
||||
}
|
||||
dpp::guild* g = dpp::find_guild(TEST_GUILD_ID);
|
||||
set_test("CACHE", false);
|
||||
if (g) {
|
||||
set_test("CACHE", true);
|
||||
set_test("VOICECONN", false);
|
||||
dpp::discord_client* s = bot.get_shard(0);
|
||||
s->connect_voice(g->id, TEST_VC_ID, false, false);
|
||||
}
|
||||
else {
|
||||
set_test("CACHE", false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bool message_tested = false;
|
||||
bot.on_message_create([&](const dpp::message_create_t & event) {
|
||||
if (event.msg.author.id == bot.me.id && !message_tested) {
|
||||
message_tested = true;
|
||||
set_test("MESSAGERECEIVE", true);
|
||||
set_test("MESSAGESGET", false);
|
||||
bot.messages_get(event.msg.channel_id, 0, event.msg.id, 0, 5, [](const dpp::confirmation_callback_t &cc){
|
||||
if (!cc.is_error()) {
|
||||
dpp::message_map mm = std::get<dpp::message_map>(cc.value);
|
||||
if (mm.size()) {
|
||||
set_test("MESSAGESGET", true);
|
||||
set_test("TIMESTAMP", false);
|
||||
dpp::message m = mm.begin()->second;
|
||||
if (m.sent > 0) {
|
||||
set_test("TIMESTAMP", true);
|
||||
} else {
|
||||
set_test("TIMESTAMP", false);
|
||||
}
|
||||
} else {
|
||||
set_test("MESSAGESGET", false);
|
||||
}
|
||||
} else {
|
||||
set_test("MESSAGESGET", false);
|
||||
}
|
||||
});
|
||||
set_test("MSGCREATESEND", false);
|
||||
event.send("MSGCREATESEND", [&bot, ch_id = event.msg.channel_id] (const auto& cc) {
|
||||
if (!cc.is_error()) {
|
||||
dpp::message m = std::get<dpp::message>(cc.value);
|
||||
if (m.channel_id == ch_id) {
|
||||
set_test("MSGCREATESEND", true);
|
||||
} else {
|
||||
bot.log(dpp::ll_debug, cc.http_info.body);
|
||||
set_test("MSGCREATESEND", false);
|
||||
}
|
||||
bot.message_delete(m.id, m.channel_id);
|
||||
} else {
|
||||
bot.log(dpp::ll_debug, cc.http_info.body);
|
||||
set_test("MSGCREATESEND", false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
set_test("BOTSTART", false);
|
||||
try {
|
||||
@@ -821,6 +1370,12 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
|
||||
}
|
||||
testcache.remove(found_tco);
|
||||
|
||||
if (!offline) {
|
||||
if (std::future_status status = ready_future.wait_for(std::chrono::seconds(20)); status != std::future_status::timeout) {
|
||||
do_online_tests();
|
||||
}
|
||||
}
|
||||
|
||||
noparam_api_test(current_user_get, dpp::user_identified, "CURRENTUSER");
|
||||
singleparam_api_test(channel_get, TEST_TEXT_CHANNEL_ID, dpp::channel, "GETCHAN");
|
||||
singleparam_api_test(guild_get, TEST_GUILD_ID, dpp::guild, "GETGUILD");
|
||||
|
||||
Vendored
+7
@@ -232,6 +232,13 @@ int test_summary();
|
||||
*/
|
||||
std::vector<uint8_t> load_test_audio();
|
||||
|
||||
/**
|
||||
* @brief Load test image for the attachment tests
|
||||
*
|
||||
* @return std::vector<uint8_t> data and size for test image
|
||||
*/
|
||||
std::vector<uint8_t> load_test_image();
|
||||
|
||||
/**
|
||||
* @brief Get the token from the environment variable DPP_UNIT_TEST_TOKEN
|
||||
*
|
||||
|
||||
Loaded 100 of 1562 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user