Skip to content

Commit

Permalink
Add get bot gateway for shards count
Browse files Browse the repository at this point in the history
  • Loading branch information
yourWaifu committed Jan 21, 2022
1 parent cd1638f commit d09eb9b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/sleepy_discord/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ namespace SleepyDiscord {

void testFunction(std::string teststring);

//gateway functions
ObjectResponse<Gateway> getGateway(RequestSettings<ObjectResponse<Gateway>> settings = {});

//channel functions
ObjectResponse<Channel > getChannel (Snowflake<Channel> channelID , RequestSettings<ObjectResponse<Channel>> settings = {});
ObjectResponse<Channel > editChannel (Snowflake<Channel> channelID, std::string name = "", std::string topic = "" , RequestSettings<ObjectResponse<Channel>> settings = {});
Expand Down
40 changes: 40 additions & 0 deletions include/sleepy_discord/gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SessionStartLimit>(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<Gateway>(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 ,
Expand Down
4 changes: 4 additions & 0 deletions sleepy_discord/endpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace SleepyDiscord {
return json::stringify(doc);
}

ObjectResponse<Gateway> BaseDiscordClient::getGateway(RequestSettings<ObjectResponse<Gateway>> settings) {
return ObjectResponse<Gateway>{ request(Get, "gateway/bot", settings) };
}

ObjectResponse<Message> BaseDiscordClient::sendMessage(Snowflake<Channel> channelID, std::string message, Embed embed, MessageReference replyingTo, TTS tts, RequestSettings<ObjectResponse<Message>> settings) {
return ObjectResponse<Message>{ request(Post, path("channels/{channel.id}/messages", { channelID }), settings, createMessageBody(message, embed, replyingTo, tts)) };
}
Expand Down
6 changes: 6 additions & 0 deletions sleepy_discord/gateway.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include "gateway.h"

namespace SleepyDiscord {
SessionStartLimit::SessionStartLimit(const json::Value& json) :
SessionStartLimit(json::fromJSON<SessionStartLimit>(json)) {
}
Gateway::Gateway(const json::Value& json) :
Gateway(json::fromJSON<Gateway>(json)) {
}
Ready::Ready(const json::Value & json) :
Ready(json::fromJSON<Ready>(json)) {
}
Expand Down

0 comments on commit d09eb9b

Please sign in to comment.