diff --git a/include/sleepy_discord/client.h b/include/sleepy_discord/client.h index 7c44bc436..a552ff2f5 100644 --- a/include/sleepy_discord/client.h +++ b/include/sleepy_discord/client.h @@ -198,6 +198,9 @@ namespace SleepyDiscord { void testFunction(std::string teststring); + //gateway functions + ObjectResponse getGateway(RequestSettings> settings = {}); + //channel functions ObjectResponse getChannel (Snowflake channelID , RequestSettings> settings = {}); ObjectResponse editChannel (Snowflake channelID, std::string name = "", std::string topic = "" , RequestSettings> settings = {}); diff --git a/include/sleepy_discord/gateway.h b/include/sleepy_discord/gateway.h index b91db1e0c..043accd3f 100644 --- a/include/sleepy_discord/gateway.h +++ b/include/sleepy_discord/gateway.h @@ -7,6 +7,46 @@ #include "server.h" namespace SleepyDiscord { + struct SessionStartLimit : public DiscordObject { + SessionStartLimit() = default; + SessionStartLimit(const json::Value & rawJSON); + SessionStartLimit(const nonstd::string_view & json) : + SessionStartLimit(json::fromJSON(json)) {} + + int total; + int remaining; + int resetAfter; + int maxConcurency; + + JSONStructStart + std::make_tuple( + json::pair(&SessionStartLimit::total , "total" , json::OPTIONAL_FIELD), + json::pair(&SessionStartLimit::remaining , "remaining" , json::OPTIONAL_FIELD), + json::pair(&SessionStartLimit::resetAfter , "reset_after" , json::OPTIONAL_FIELD), + json::pair(&SessionStartLimit::maxConcurency, "max_concurrency", json::OPTIONAL_FIELD) + ); + JSONStructEnd + }; + + struct Gateway { + Gateway() = default; + Gateway(const json::Value & rawJSON); + Gateway(const nonstd::string_view & json) : + Gateway(json::fromJSON(json)) {} + + std::string url; + int shards; + SessionStartLimit sessionStartLimit; + + JSONStructStart + std::make_tuple( + json::pair(&Gateway::url , "url" , json::OPTIONAL_FIELD), + json::pair(&Gateway::shards , "shards" , json::OPTIONAL_FIELD), + json::pair(&Gateway::sessionStartLimit, "session_start_limit", json::OPTIONAL_FIELD) + ); + JSONStructEnd + }; + enum Status { statusError = 0, online , diff --git a/sleepy_discord/endpoints.cpp b/sleepy_discord/endpoints.cpp index d88d96dfe..6058beac4 100644 --- a/sleepy_discord/endpoints.cpp +++ b/sleepy_discord/endpoints.cpp @@ -34,6 +34,10 @@ namespace SleepyDiscord { return json::stringify(doc); } + ObjectResponse BaseDiscordClient::getGateway(RequestSettings> settings) { + return ObjectResponse{ request(Get, "gateway/bot", settings) }; + } + ObjectResponse BaseDiscordClient::sendMessage(Snowflake channelID, std::string message, Embed embed, MessageReference replyingTo, TTS tts, RequestSettings> settings) { return ObjectResponse{ request(Post, path("channels/{channel.id}/messages", { channelID }), settings, createMessageBody(message, embed, replyingTo, tts)) }; } diff --git a/sleepy_discord/gateway.cpp b/sleepy_discord/gateway.cpp index 07a06ba3e..c5e9935d8 100644 --- a/sleepy_discord/gateway.cpp +++ b/sleepy_discord/gateway.cpp @@ -1,6 +1,12 @@ #include "gateway.h" namespace SleepyDiscord { + SessionStartLimit::SessionStartLimit(const json::Value& json) : + SessionStartLimit(json::fromJSON(json)) { + } + Gateway::Gateway(const json::Value& json) : + Gateway(json::fromJSON(json)) { + } Ready::Ready(const json::Value & json) : Ready(json::fromJSON(json)) { }