forked from OpenGamers/abaddon
@@ -437,6 +437,36 @@ void DiscordClient::RemoveReaction(Snowflake id, Glib::ustring param) {
|
||||
m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/messages/" + std::to_string(id) + "/reactions/" + param + "/@me", [](auto) {});
|
||||
}
|
||||
|
||||
void DiscordClient::SetGuildName(Snowflake id, const Glib::ustring &name) {
|
||||
SetGuildName(id, name, [](auto) {});
|
||||
}
|
||||
|
||||
void DiscordClient::SetGuildName(Snowflake id, const Glib::ustring &name, sigc::slot<void(bool success)> callback) {
|
||||
ModifyGuildObject obj;
|
||||
obj.Name = name;
|
||||
sigc::signal<void, bool> signal;
|
||||
signal.connect(callback);
|
||||
m_http.MakePATCH("/guilds/" + std::to_string(id), nlohmann::json(obj).dump(), [this, signal](const cpr::Response &r) {
|
||||
const auto success = r.status_code == 200;
|
||||
signal.emit(success);
|
||||
});
|
||||
}
|
||||
|
||||
void DiscordClient::SetGuildIcon(Snowflake id, const std::string &data) {
|
||||
SetGuildIcon(id, data, [](auto) {});
|
||||
}
|
||||
|
||||
void DiscordClient::SetGuildIcon(Snowflake id, const std::string &data, sigc::slot<void(bool success)> callback) {
|
||||
ModifyGuildObject obj;
|
||||
obj.IconData = data;
|
||||
sigc::signal<void, bool> signal;
|
||||
signal.connect(callback);
|
||||
m_http.MakePATCH("/guilds/" + std::to_string(id), nlohmann::json(obj).dump(), [this, signal](const cpr::Response &r) {
|
||||
const auto success = r.status_code == 200;
|
||||
signal.emit(success);
|
||||
});
|
||||
}
|
||||
|
||||
void DiscordClient::UpdateToken(std::string token) {
|
||||
if (!IsStarted()) {
|
||||
m_token = token;
|
||||
|
||||
@@ -110,6 +110,10 @@ public:
|
||||
std::optional<Snowflake> FindDM(Snowflake user_id); // wont find group dms
|
||||
void AddReaction(Snowflake id, Glib::ustring param);
|
||||
void RemoveReaction(Snowflake id, Glib::ustring param);
|
||||
void SetGuildName(Snowflake id, const Glib::ustring &name);
|
||||
void SetGuildName(Snowflake id, const Glib::ustring &name, sigc::slot<void(bool success)> callback);
|
||||
void SetGuildIcon(Snowflake id, const std::string &data);
|
||||
void SetGuildIcon(Snowflake id, const std::string &data, sigc::slot<void(bool success)> callback);
|
||||
|
||||
void UpdateToken(std::string token);
|
||||
void SetUserAgent(std::string agent);
|
||||
|
||||
@@ -118,6 +118,13 @@ void GuildData::update_from_json(const nlohmann::json &j) {
|
||||
JS_RD("approximate_presence_count", ApproximatePresenceCount);
|
||||
}
|
||||
|
||||
bool GuildData::HasFeature(const std::string &search_feature) {
|
||||
for (const auto &feature : Features)
|
||||
if (search_feature == feature)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuildData::HasIcon() const {
|
||||
return Icon != "";
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ struct GuildData {
|
||||
friend void from_json(const nlohmann::json &j, GuildData &m);
|
||||
void update_from_json(const nlohmann::json &j);
|
||||
|
||||
bool HasFeature(const std::string &feature);
|
||||
bool HasIcon() const;
|
||||
bool HasAnimatedIcon() const;
|
||||
std::string GetIconURL(std::string ext = "png", std::string size = "32") const;
|
||||
|
||||
@@ -247,3 +247,8 @@ void from_json(const nlohmann::json &j, TypingStartObject &m) {
|
||||
JS_D("timestamp", m.Timestamp);
|
||||
JS_O("member", m.Member);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const ModifyGuildObject &m) {
|
||||
JS_IF("name", m.Name);
|
||||
JS_IF("icon", m.IconData);
|
||||
}
|
||||
|
||||
@@ -345,3 +345,11 @@ struct TypingStartObject {
|
||||
|
||||
friend void from_json(const nlohmann::json &j, TypingStartObject &m);
|
||||
};
|
||||
|
||||
// implement rest as needed
|
||||
struct ModifyGuildObject {
|
||||
std::optional<std::string> Name;
|
||||
std::optional<std::string> IconData;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const ModifyGuildObject &m);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user