Reduced compiletime
This commit is contained in:
parent
d8aeec28a2
commit
c9d10bb1f7
@ -41,7 +41,7 @@ public:
|
||||
|
||||
enum class State {
|
||||
kReady, // We recieved our READY event
|
||||
kNearly, // We sent our IDENTITY, waiting for ready
|
||||
kHello, // We sent our IDENTITY, waiting for ready
|
||||
kConnecting, // Trying to connect to the socket
|
||||
kReconnecting, // Got disconnected, trying again
|
||||
kDisconnected, // We are not connected at all
|
||||
|
@ -22,13 +22,15 @@
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
#include "api/rest.hpp"
|
||||
#include "api/shard.hpp"
|
||||
#include "presence.hpp"
|
||||
#include "snowflake.hpp"
|
||||
|
||||
namespace neko::discord {
|
||||
namespace json = rapidjson;
|
||||
|
||||
namespace api {
|
||||
class Shard;
|
||||
}
|
||||
class Guild;
|
||||
class GuildMember;
|
||||
class Message;
|
||||
@ -41,6 +43,8 @@ public:
|
||||
BaseClient();
|
||||
void Login(std::string_view token, int num_shards = 1);
|
||||
void Disconnect();
|
||||
void GetToken();
|
||||
|
||||
// Events
|
||||
protected:
|
||||
virtual void onReady(){}
|
||||
@ -49,29 +53,28 @@ protected:
|
||||
virtual void onChannelCreate(Channel*){}
|
||||
virtual void onGuildUpdate(Guild*) {}
|
||||
virtual void onDisconnect() {}
|
||||
|
||||
// Info retrieval
|
||||
public:
|
||||
const User* FetchClientUser();
|
||||
//Invite FetchInvite(std::string_view);
|
||||
User* FetchUser(Snowflake id, bool cache = true); // Whether or not to use the cache
|
||||
Guild* FetchGuild(Snowflake id, bool cache = true);
|
||||
Emoji* FetchEmoji(Snowflake id);
|
||||
Channel* FetchChannel(Snowflake id);
|
||||
//std::vector<VoiceRegion> FetchVoiceRegions();
|
||||
//Webhook FetchWebhook(Snowflake id, std::string_view = std::string_view());
|
||||
//std::string GenerateInvite()
|
||||
//void SyncGuilds();
|
||||
// This fetch user takes in data and caches it
|
||||
User* FetchUser(Snowflake, const json::Value&);
|
||||
User* FetchUser(const json::Value& v);
|
||||
Guild* FetchGuild(Snowflake, const json::Value&);
|
||||
Guild* FetchGuild(const json::Value& v);
|
||||
|
||||
// Internal events
|
||||
private:
|
||||
// Cache
|
||||
void onReady(const json::Value&);
|
||||
void onGuildCreate(const json::Value&);
|
||||
void onMessageCreate(const json::Value&);
|
||||
void onChannelCreate(const json::Value&);
|
||||
void onGuildUpdate(const json::Value&);
|
||||
|
||||
|
||||
// Cache
|
||||
User* user;
|
||||
std::unordered_map<Snowflake, Channel*> channels;
|
||||
std::unordered_map<Snowflake, Emoji*> emojis;
|
||||
@ -79,28 +82,18 @@ private:
|
||||
std::unordered_map<Snowflake, Presence> presences;
|
||||
std::unordered_map<Snowflake, User*> users;
|
||||
|
||||
friend Guild; // So they can fill the cache themselves
|
||||
friend Channel;
|
||||
friend DMChannel;
|
||||
friend GroupDMChannel;
|
||||
friend Emoji;
|
||||
friend GuildMember;
|
||||
friend Message;
|
||||
// This fetch user takes in data and caches it
|
||||
User* FetchUser(Snowflake, const json::Value&);
|
||||
User* FetchUser(const json::Value& v);
|
||||
Guild* FetchGuild(Snowflake, const json::Value&);
|
||||
Guild* FetchGuild(const json::Value& v);
|
||||
|
||||
// Connection info
|
||||
// Connection info
|
||||
std::string token;
|
||||
|
||||
friend api::RestAPI;
|
||||
api::RestAPI http;
|
||||
|
||||
friend api::Shard;
|
||||
std::vector<api::Shard*> shards;
|
||||
void EmitEvent(std::string_view event, const json::Value& msg);
|
||||
void EmitEvent(std::string_view event, const json::Value& data);
|
||||
// easy access
|
||||
friend Channel;
|
||||
friend Guild;
|
||||
friend Emoji;
|
||||
friend GuildMember;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include "client.hpp"
|
||||
|
||||
#include "api/shard.hpp"
|
||||
|
||||
namespace neko::discord::api {
|
||||
using namespace std::string_view_literals;
|
||||
using namespace std::chrono_literals;
|
||||
@ -156,7 +158,7 @@ void Shard::Send(const json::Value& msg) {
|
||||
|
||||
void Shard::Heartbeat() {
|
||||
// Check for acknowledge
|
||||
if (!this->last_heartbeat_ack) {
|
||||
if (this->state == State::kReady && !this->last_heartbeat_ack) {
|
||||
std::cerr << "Shard: Heartbeat not acknowledged, reconnecting!" << std::endl;
|
||||
this->Disconnect(true);
|
||||
return;
|
||||
@ -252,13 +254,14 @@ void Shard::RecieveMessage(std::string_view raw) {
|
||||
}, hb_int);
|
||||
}
|
||||
|
||||
this->state = State::kNearly;
|
||||
this->state = State::kHello;
|
||||
|
||||
if(!this->session_id.empty()) {
|
||||
this->Resume();
|
||||
} else {
|
||||
this->Identify();
|
||||
}
|
||||
this->last_heartbeat_ack = true;
|
||||
this->Heartbeat();
|
||||
break;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <neko/filesystem.hpp>
|
||||
#include <rapidjson/writer.h>
|
||||
|
||||
#include "api/shard.hpp"
|
||||
#include "guild/guild.hpp"
|
||||
#include "channel.hpp"
|
||||
#include "message.hpp"
|
||||
|
Reference in New Issue
Block a user