mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-13 20:18:50 +03:00
ResumeMessage and ModifyGuildObject now uses yyjson
This commit is contained in:
@@ -723,7 +723,7 @@ void DiscordClient::RemoveReaction(Snowflake id, Glib::ustring param) {
|
||||
void DiscordClient::SetGuildName(Snowflake id, const Glib::ustring &name, const sigc::slot<void(DiscordError code)> &callback) {
|
||||
ModifyGuildObject obj;
|
||||
obj.Name = name;
|
||||
m_http.MakePATCH("/guilds/" + std::to_string(id), nlohmann::json(obj).dump(), [callback](const http::response_type &r) {
|
||||
m_http.MakePATCH("/guilds/" + std::to_string(id), obj.BuildJson(), [callback](const http::response_type &r) {
|
||||
if (CheckCode(r))
|
||||
callback(DiscordError::NONE);
|
||||
else
|
||||
@@ -734,7 +734,7 @@ void DiscordClient::SetGuildName(Snowflake id, const Glib::ustring &name, const
|
||||
void DiscordClient::SetGuildIcon(Snowflake id, const std::string &data, const sigc::slot<void(DiscordError code)> &callback) {
|
||||
ModifyGuildObject obj;
|
||||
obj.IconData = data;
|
||||
m_http.MakePATCH("/guilds/" + std::to_string(id), nlohmann::json(obj).dump(), [callback](const http::response_type &r) {
|
||||
m_http.MakePATCH("/guilds/" + std::to_string(id), obj.BuildJson(), [callback](const http::response_type &r) {
|
||||
if (CheckCode(r))
|
||||
callback(DiscordError::NONE);
|
||||
else
|
||||
@@ -2700,7 +2700,7 @@ void DiscordClient::SendResume() {
|
||||
msg.Sequence = m_last_sequence;
|
||||
msg.SessionID = m_session_id;
|
||||
msg.Token = m_token;
|
||||
m_websocket.Send(msg);
|
||||
m_websocket.Send(msg.BuildJson());
|
||||
}
|
||||
|
||||
void DiscordClient::SetHeaders() {
|
||||
|
||||
@@ -651,6 +651,20 @@ struct ResumeMessage : GatewayMessage {
|
||||
std::string SessionID;
|
||||
int Sequence;
|
||||
|
||||
std::string BuildJson() const
|
||||
{
|
||||
YYJsonDocument yyjsn;
|
||||
yyjsn.CreateDoc();
|
||||
yyjsn.AddInt("op",(int)GatewayOp::Resume);
|
||||
yyjsn.CreateBlock();
|
||||
yyjsn.AddString("token",Token.c_str());
|
||||
yyjsn.AddString("session_id",SessionID);
|
||||
yyjsn.AddString("seq",SessionID);
|
||||
yyjsn.PushBlock("d");
|
||||
|
||||
return yyjsn.BuildJson();
|
||||
}
|
||||
|
||||
friend void to_json(nlohmann::json &j, const ResumeMessage &m);
|
||||
};
|
||||
|
||||
@@ -725,6 +739,16 @@ struct ModifyGuildObject {
|
||||
std::optional<std::string> Name;
|
||||
std::optional<std::string> IconData;
|
||||
|
||||
std::string BuildJson() const
|
||||
{
|
||||
YYJsonDocument yyjsn;
|
||||
yyjsn.CreateDoc();
|
||||
if(Name.has_value())
|
||||
yyjsn.AddString("name", Name);
|
||||
if(IconData.has_value())
|
||||
yyjsn.AddString("icon", IconData);
|
||||
}
|
||||
|
||||
friend void to_json(nlohmann::json &j, const ModifyGuildObject &m);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user