aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
aegis::core Class Reference

Primary class for managing a bot interface. More...

#include <core.hpp>

Public Types

using typing_start_t = std::function< void(gateway::events::typing_start obj)>
 
using message_create_t = std::function< void(gateway::events::message_create obj)>
 
using message_update_t = std::function< void(gateway::events::message_update obj)>
 
using message_delete_t = std::function< void(gateway::events::message_delete obj)>
 
using message_delete_bulk_t = std::function< void(gateway::events::message_delete_bulk obj)>
 
using guild_create_t = std::function< void(gateway::events::guild_create obj)>
 
using guild_update_t = std::function< void(gateway::events::guild_update obj)>
 
using guild_delete_t = std::function< void(gateway::events::guild_delete obj)>
 
using message_reaction_add_t = std::function< void(gateway::events::message_reaction_add obj)>
 
using message_reaction_remove_t = std::function< void(gateway::events::message_reaction_remove obj)>
 
using message_reaction_remove_all_t = std::function< void(gateway::events::message_reaction_remove_all obj)>
 
using user_update_t = std::function< void(gateway::events::user_update obj)>
 
using ready_t = std::function< void(gateway::events::ready obj)>
 
using resumed_t = std::function< void(gateway::events::resumed obj)>
 
using channel_create_t = std::function< void(gateway::events::channel_create obj)>
 
using channel_update_t = std::function< void(gateway::events::channel_update obj)>
 
using channel_delete_t = std::function< void(gateway::events::channel_delete obj)>
 
using channel_pins_update_t = std::function< void(gateway::events::channel_pins_update obj)>
 
using guild_ban_add_t = std::function< void(gateway::events::guild_ban_add obj)>
 
using guild_ban_remove_t = std::function< void(gateway::events::guild_ban_remove obj)>
 
using guild_emojis_update_t = std::function< void(gateway::events::guild_emojis_update obj)>
 
using guild_integrations_update_t = std::function< void(gateway::events::guild_integrations_update obj)>
 
using guild_member_add_t = std::function< void(gateway::events::guild_member_add obj)>
 
using guild_member_remove_t = std::function< void(gateway::events::guild_member_remove obj)>
 
using guild_member_update_t = std::function< void(gateway::events::guild_member_update obj)>
 
using guild_members_chunk_t = std::function< void(gateway::events::guild_members_chunk obj)>
 
using guild_role_create_t = std::function< void(gateway::events::guild_role_create obj)>
 
using guild_role_update_t = std::function< void(gateway::events::guild_role_update obj)>
 
using guild_role_delete_t = std::function< void(gateway::events::guild_role_delete obj)>
 
using presence_update_t = std::function< void(gateway::events::presence_update obj)>
 
using voice_state_update_t = std::function< void(gateway::events::voice_state_update obj)>
 
using voice_server_update_t = std::function< void(gateway::events::voice_server_update obj)>
 
using webhooks_update_t = std::function< void(gateway::events::webhooks_update obj)>
 
using raw_event_t = std::function< void(json obj, shards::shard *_shard)>
 

Public Member Functions

 core (create_bot_t bot_config)
 
 core (spdlog::level::level_enum loglevel=spdlog::level::level_enum::trace, std::size_t count=10)
 
 core (std::shared_ptr< asio::io_context > _io, spdlog::level::level_enum loglevel=spdlog::level::level_enum::trace)
 
 core (std::shared_ptr< spdlog::logger > _log, std::size_t count=2)
 
 core (std::shared_ptr< asio::io_context > _io, std::shared_ptr< spdlog::logger > _log)
 
 ~core ()
 Destroys the shards, stops the asio::work object, destroys the websocket object.
 
 core (const core &)=delete
 
 core (core &&)=delete
 
coreoperator= (const core &)=delete
 
void debug_trace (shards::shard *_shard) noexcept
 Outputs the last 5 messages received from the gateway. More...
 
void setup_logging ()
 
void setup_context ()
 
void setup_shard_mgr ()
 
asio::io_context & get_io_context () noexcept
 Get the internal (or external) io_service object.
 
void shutdown () noexcept
 
aegis::future
< gateway::objects::guild
create_guild (std::string name, lib::optional< std::string > voice_region={}, lib::optional< int > verification_level={}, lib::optional< int > default_message_notifications={}, lib::optional< int > explicit_content_filter={}, lib::optional< std::string > icon={}, lib::optional< std::vector< gateway::objects::role >> roles={}, lib::optional< std::vector< std::tuple< std::string, int >>> channels={})
 
aegis::future
< gateway::objects::guild
create_guild (create_guild_t obj)
 
aegis::future
< gateway::objects::member
modify_bot_username (const std::string &username)
 Changes bot's username (not implemented yet. username can be changed in developer panel) More...
 
aegis::future
< gateway::objects::member
modify_bot_avatar (const std::string &avatar)
 Changes bot's avatar (not implemented yet. avatar can be changed in developer panel) More...
 
void run ()
 Starts the shard manager, creates the shards, and connects to the gateway.
 
void yield () noexcept
 
rest::rest_controllerget_rest_controller () noexcept
 Get the rest controller object. More...
 
ratelimit_mgr_tget_ratelimit () noexcept
 Get the ratelimit object. More...
 
shards::shard_mgrget_shard_mgr () noexcept
 Get the shard manager. More...
 
bot_status get_state () const noexcept
 Get current state of the bot. More...
 
void set_state (bot_status s) noexcept
 Set the bot status. More...
 
std::chrono::hours get_tz_bias () const noexcept
 Get the timezone offset. More...
 
userself () const
 Obtain pointer to self object. More...
 
int64_t get_member_count () const noexcept
 Get count of members tracked (includes duplicates from multiple shared guilds) More...
 
int64_t get_user_count () const noexcept
 Get count of unique users tracked. More...
 
int64_t get_channel_count () const noexcept
 Get count of unique channels tracked. More...
 
int64_t get_guild_count () const noexcept
 Get count of unique guilds tracked. More...
 
userfind_user (snowflake id) const noexcept
 Obtain a pointer to a user by snowflake. More...
 
useruser_create (snowflake id) noexcept
 Obtain a pointer to a user by snowflake. If none exists, creates the object. More...
 
const snowflake get_id () const noexcept
 Get the snowflake of the bot. More...
 
channelfind_channel (snowflake id) const noexcept
 Obtain a pointer to a channel by snowflake. More...
 
channelchannel_create (snowflake id) noexcept
 Obtain a pointer to a channel by snowflake. If none exists, creates the object. More...
 
guildfind_guild (snowflake id) const noexcept
 Obtain a pointer to a guild by snowflake. More...
 
guildguild_create (snowflake id, shards::shard *_shard) noexcept
 Obtain a pointer to a guild by snowflake. If none exists, creates the object. More...
 
channeldm_channel_create (const json &obj, shards::shard *_shard)
 Called by CHANNEL_CREATE (DirectMessage) More...
 
aegis::future
< gateway::objects::message
create_dm_message (snowflake member_id, const std::string &content, int64_t nonce=0)
 Send a direct message to a user. More...
 
aegis::future
< gateway::objects::message
create_dm_message (const create_message_t &obj)
 Send a direct message to a user. More...
 
std::string uptime_str () const noexcept
 Return bot uptime as {days hours minutes seconds}. More...
 
int64_t uptime () const noexcept
 Return shard uptime as {days hours minutes seconds}. More...
 
rest::rest_reply call (rest::request_params &&params)
 Performs an immediate blocking HTTP request on the path with content as the request body using the method method. More...
 
rest::rest_reply call (rest::request_params &params)
 Performs an immediate blocking HTTP request on the path with content as the request body using the method method. More...
 
void update_presence (const std::string &text, gateway::objects::activity::activity_type type=gateway::objects::activity::Game, gateway::objects::presence::user_status status=gateway::objects::presence::Online)
 Update presence across all shards at once. More...
 
std::shared_ptr
< asio::steady_timer > 
set_timer (long duration, std::function< void(const asio::error_code &)> callback)
 Passes through to Websocket++. More...
 
void set_on_typing_start (typing_start_t cb)
 TYPING_START callback.
 
void set_on_typing_start_raw (raw_event_t cb)
 
void set_on_message_create (message_create_t cb)
 MESSAGE_CREATE callback.
 
void set_on_message_create_raw (raw_event_t cb)
 
void set_on_message_create_dm (message_create_t cb)
 MESSAGE_CREATE callback for direct messages.
 
void set_on_message_create_dm_raw (raw_event_t cb)
 
void set_on_message_update (message_update_t cb)
 MESSAGE_UPDATE callback.
 
void set_on_message_update_raw (raw_event_t cb)
 
void set_on_message_delete (message_delete_t cb)
 MESSAGE_DELETE callback.
 
void set_on_message_delete_raw (raw_event_t cb)
 
void set_on_message_delete_bulk (message_delete_bulk_t cb)
 MESSAGE_DELETE_BULK callback.
 
void set_on_message_delete_bulk_raw (raw_event_t cb)
 
void set_on_guild_create (guild_create_t cb)
 GUILD_CREATE callback.
 
void set_on_guild_create_raw (raw_event_t cb)
 
void set_on_guild_update (guild_update_t cb)
 GUILD_UPDATE callback.
 
void set_on_guild_update_raw (raw_event_t cb)
 
void set_on_guild_delete (guild_delete_t cb)
 GUILD_DELETE callback.
 
void set_on_guild_delete_raw (raw_event_t cb)
 
void set_on_message_reaction_add (message_reaction_add_t cb)
 MESSAGE_REACTION_ADD callback.
 
void set_on_message_reaction_add_raw (raw_event_t cb)
 
void set_on_message_reaction_remove (message_reaction_remove_t cb)
 MESSAGE_REACTION_REMOVE callback.
 
void set_on_message_reaction_remove_raw (raw_event_t cb)
 
void set_on_message_reaction_remove_all (message_reaction_remove_all_t cb)
 MESSAGE_REACTION_REMOVE_ALL callback.
 
void set_on_message_reaction_remove_all_raw (raw_event_t cb)
 
void set_on_user_update (user_update_t cb)
 USER_UPDATE callback.
 
void set_on_user_update_raw (raw_event_t cb)
 
void set_on_ready (ready_t cb)
 READY callback.
 
void set_on_ready_raw (raw_event_t cb)
 
void set_on_resumed (resumed_t cb)
 RESUME callback.
 
void set_on_resumed_raw (raw_event_t cb)
 
void set_on_channel_create (channel_create_t cb)
 CHANNEL_CREATE callback.
 
void set_on_channel_create_raw (raw_event_t cb)
 
void set_on_channel_update (channel_update_t cb)
 CHANNEL_UPDATE callback.
 
void set_on_channel_update_raw (raw_event_t cb)
 
void set_on_channel_delete (channel_delete_t cb)
 CHANNEL_DELETE callback.
 
void set_on_channel_delete_raw (raw_event_t cb)
 
void set_on_channel_pins_update (channel_pins_update_t cb)
 CHANNEL_PINS_UPDATE callback.
 
void set_on_channel_pins_update_raw (raw_event_t cb)
 
void set_on_guild_ban_add (guild_ban_add_t cb)
 GUILD_BAN_ADD callback.
 
void set_on_guild_ban_add_raw (raw_event_t cb)
 
void set_on_guild_ban_remove (guild_ban_remove_t cb)
 GUILD_BAN_REMOVE callback.
 
void set_on_guild_ban_remove_raw (raw_event_t cb)
 
void set_on_guild_emojis_update (guild_emojis_update_t cb)
 GUILD_EMOJIS_UPDATE callback.
 
void set_on_guild_emojis_update_raw (raw_event_t cb)
 
void set_on_guild_integrations_update (guild_integrations_update_t cb)
 GUILD_INTEGRATIONS_UPDATE callback.
 
void set_on_guild_integrations_update_raw (raw_event_t cb)
 
void set_on_guild_member_add (guild_member_add_t cb)
 GUILD_MEMBER_ADD callback.
 
void set_on_guild_member_add_raw (raw_event_t cb)
 
void set_on_guild_member_remove (guild_member_remove_t cb)
 GUILD_MEMBER_REMOVE callback.
 
void set_on_guild_member_remove_raw (raw_event_t cb)
 
void set_on_guild_member_update (guild_member_update_t cb)
 GUILD_MEMBER_UPDATE callback.
 
void set_on_guild_member_update_raw (raw_event_t cb)
 
void set_on_guild_member_chunk (guild_members_chunk_t cb)
 GUILD_MEMBERS_CHUNK callback.
 
void set_on_guild_member_chunk_raw (raw_event_t cb)
 
void set_on_guild_role_create (guild_role_create_t cb)
 GUILD_ROLE_CREATE callback.
 
void set_on_guild_role_create_raw (raw_event_t cb)
 
void set_on_guild_role_update (guild_role_update_t cb)
 GUILD_ROLE_UPDATE callback.
 
void set_on_guild_role_update_raw (raw_event_t cb)
 
void set_on_guild_role_delete (guild_role_delete_t cb)
 GUILD_ROLE_DELETE callback.
 
void set_on_guild_role_delete_raw (raw_event_t cb)
 
void set_on_presence_update (presence_update_t cb)
 PRESENCE_UPDATE callback.
 
void set_on_presence_update_raw (raw_event_t cb)
 
void set_on_voice_state_update (voice_state_update_t cb)
 VOICE_STATE_UPDATE callback.
 
void set_on_voice_state_update_raw (raw_event_t cb)
 
void set_on_voice_server_update (voice_server_update_t cb)
 VOICE_SERVER_UPDATE callback.
 
void set_on_voice_server_update_raw (raw_event_t cb)
 
void set_on_webhooks_update (webhooks_update_t cb)
 WEBHOOKS_UPDATE callback.
 
void set_on_webhooks_update_raw (raw_event_t cb)
 
void set_on_shard_disconnect (std::function< void(aegis::shards::shard *)> cb)
 Shard disconnect callback.
 
void set_on_shard_connect (std::function< void(aegis::shards::shard *)> cb)
 Shard connect callback.
 
void send_all_shards (const std::string &msg)
 Send a websocket message to a single shard. More...
 
void send_all_shards (const json &msg)
 Send a websocket message to a single shard. More...
 
shards::shardget_shard_by_id (uint16_t shard_id)
 Get a reference to the shard by shard id. More...
 
shards::shardget_shard_by_guild (snowflake guild_id)
 Get a reference to the shard that the provided guild is on. More...
 
uint64_t get_shard_transfer () const noexcept
 Get total transfer of bot in bytes. More...
 
uint64_t get_shard_u_transfer () const noexcept
 Get total transfer of bot in bytes after decompression. More...
 
const std::string & get_token () const noexcept
 Obtain bot's token. More...
 
std::size_t add_run_thread () noexcept
 Interrupt and end threads. More...
 
void reduce_threads (std::size_t count) noexcept
 Interrupt and end threads. More...
 
aegis::future
< gateway::objects::message
create_message (snowflake channel_id, const std::string &msg, int64_t nonce=0, bool perform_lookup=false) noexcept
 
aegis::future
< gateway::objects::message
create_message_embed (snowflake channel_id, const std::string &msg, const json &_obj, int64_t nonce=0, bool perform_lookup=false) noexcept
 
template<typename T , typename V = std::result_of_t<T()>, typename = std::enable_if_t<!std::is_void<V>::value>>
aegis::future< V > async (T f) noexcept
 Run async task. More...
 
template<typename T , typename V = std::enable_if_t<std::is_void<std::result_of_t<T()>>::value>>
aegis::future< V > async (T f) noexcept
 Run async task. More...
 
shared_mutex & get_guild_mutex ()
 Get the internal guild mutex.
 
shared_mutex & get_channel_mutex ()
 Get the internal channel mutex.
 
shared_mutex & get_user_mutex ()
 Get the internal user mutex.
 
std::unordered_map< snowflake,
std::unique_ptr< guild > > & 
get_guild_map ()
 Get the guild map. More...
 
std::unordered_map< snowflake,
std::unique_ptr< channel > > & 
get_channel_map ()
 Get the channel map. More...
 
std::unordered_map< snowflake,
std::unique_ptr< user > > & 
get_user_map ()
 Get the user map. More...
 

Public Attributes

std::unordered_map< snowflake,
std::unique_ptr< channel > > 
channels
 
std::unordered_map< snowflake,
std::unique_ptr< channel > > 
stale_channels
 
std::unordered_map< snowflake,
std::unique_ptr< guild > > 
guilds
 
std::unordered_map< snowflake,
std::unique_ptr< guild > > 
stale_guilds
 
std::unordered_map< snowflake,
std::unique_ptr< user > > 
users
 
std::unordered_map< snowflake,
std::unique_ptr< user > > 
stale_users
 
std::map< std::string, uint64_t > message_count
 
std::string self_presence
 
uint32_t force_shard_count = 0
 
uint32_t shard_max_count = 0
 
std::string mention
 
bool wsdbg = false
 
std::unique_ptr
< asio::io_context::strand > 
ws_open_strand
 
std::shared_ptr< spdlog::logger > log
 
std::vector< std::unique_ptr
< thread_state > > 
threads
 
std::recursive_mutex _global_m
 

Friends

class guild
 
class channel
 

Detailed Description

Primary class for managing a bot interface.

Only one instance of this object can exist safely

Constructor & Destructor Documentation

aegis::core::core ( create_bot_t  bot_config)
explicit

Constructs the aegis object that tracks all of the shards, guilds, channels, and members This constructor creates its own spdlog::logger and asio::io_context

Parameters
loglevelThe level of logging to use
countAmount of threads to start
aegis::core::core ( spdlog::level::level_enum  loglevel = spdlog::level::level_enum::trace,
std::size_t  count = 10 
)
explicit

Constructs the aegis object that tracks all of the shards, guilds, channels, and members This constructor creates its own spdlog::logger and asio::io_context

Deprecated:
Parameters
loglevelThe level of logging to use
countAmount of threads to start
aegis::core::core ( std::shared_ptr< asio::io_context >  _io,
spdlog::level::level_enum  loglevel = spdlog::level::level_enum::trace 
)
explicit

Constructs the aegis object that tracks all of the shards, guilds, channels, and members This constructor creates its own spdlog::logger and expects you to create the asio::io_context. It also expects you to manage the event loop or start threads on the io_context.

Deprecated:
Parameters
loglevelThe level of logging to use
aegis::core::core ( std::shared_ptr< spdlog::logger >  _log,
std::size_t  count = 2 
)
explicit

Constructs the aegis object that tracks all of the shards, guilds, channels, and members This constructor creates its own asio::io_context and expects you to create the spdlog::logger

Deprecated:
Parameters
_logYour pre-constructed spdlog::logger object
countAmount of threads to start
aegis::core::core ( std::shared_ptr< asio::io_context >  _io,
std::shared_ptr< spdlog::logger >  _log 
)
explicit

Constructs the aegis object that tracks all of the shards, guilds, channels, and members This constructor accepts a logger and io_context that you create. It expects you to manage the event loop or start threads on the io_context.

Deprecated:
Parameters
_ioYour pre-constructed asio::io_context object
_logYour pre-constructed spdlog::logger object

Member Function Documentation

std::size_t aegis::core::add_run_thread ( )
noexcept

Interrupt and end threads.

Parameters
countAmount of threads to shutdown
template<typename T , typename V = std::result_of_t<T()>, typename = std::enable_if_t<!std::is_void<V>::value>>
aegis::future<V> aegis::core::async ( f)
noexcept

Run async task.

This function will queue your task (a lambda or std::function) within Asio for execution at a later time This version will return an aegis::future of your type that the passed function returns that you may chain a continuation onto and receive that value within in

Example:

return 5;
}).then([](int value){
return std::string("result received");
});
Parameters
fFunction to run async
Returns
aegis::future<V>
template<typename T , typename V = std::enable_if_t<std::is_void<std::result_of_t<T()>>::value>>
aegis::future<V> aegis::core::async ( f)
noexcept

Run async task.

This function will queue your task (a lambda or std::function) within Asio for execution at a later time This version will return an aegis::future<void> that will still allow chaining continuations on

Example:

return;
}).then([](){
return std::string("continuation executed");
});
Parameters
fFunction to run async
Returns
aegis::future<V>
aegis::rest::rest_reply aegis::core::call ( rest::request_params &&  params)

Performs an immediate blocking HTTP request on the path with content as the request body using the method method.

See also
rest::rest_reply
rest::request_params
Parameters
paramsA struct of HTTP parameters to perform the request
Returns
Response object
aegis::rest::rest_reply aegis::core::call ( rest::request_params params)

Performs an immediate blocking HTTP request on the path with content as the request body using the method method.

See also
rest::rest_reply
rest::request_params
Parameters
paramsA struct of HTTP parameters to perform the request
Returns
Response object
channel * aegis::core::channel_create ( snowflake  id)
noexcept

Obtain a pointer to a channel by snowflake. If none exists, creates the object.

Parameters
idSnowflake of channel to search for
Returns
Pointer to channel
aegis::future< gateway::objects::message > aegis::core::create_dm_message ( snowflake  member_id,
const std::string &  content,
int64_t  nonce = 0 
)

Send a direct message to a user.

Deprecated:
Parameters
idSnowflake of member to message
contentstring of message to send
nonceUnique id to track when message verifies (can be omitted)
Returns
aegis::future<gateway::objects::message>
aegis::future< gateway::objects::message > aegis::core::create_dm_message ( const create_message_t obj)

Send a direct message to a user.

See also
aegis::create_message_t
Parameters
objStruct of the contents of the request
Returns
aegis::future<gateway::objects::message>
aegis::future< gateway::objects::guild > aegis::core::create_guild ( std::string  name,
lib::optional< std::string >  voice_region = {},
lib::optional< int >  verification_level = {},
lib::optional< int >  default_message_notifications = {},
lib::optional< int >  explicit_content_filter = {},
lib::optional< std::string >  icon = {},
lib::optional< std::vector< gateway::objects::role >>  roles = {},
lib::optional< std::vector< std::tuple< std::string, int >>>  channels = {} 
)

Create new guild - Unique case. Does not belong to any ratelimit bucket so it is run directly on the same thread and does not attempt to manage ratelimits due to the already existing requirement that the bot must be in less than 10 guilds for this call to succeed

Parameters
nameSet name of guild
voice_regionSet region for voice
verification_levelSet verification level from unrestricted level to verified phone level (NONE=0, LOW(verified email)=1, MEDIUM(registered >5m)=2, HIGH(member of server >10m)=3 VERY_HIGH(verified phone)=4
default_message_notificationsSet default notification level for new members
explicit_content_filterSet filter level for new content (DISABLED=0, MEMBERS_WITHOUT_ROLES=1, ALL_MEMBERS=2)
afk_channel_idSet channel for idle voice connections to be moved to
afk_timeoutSet time where voice connections are considered to be idle
Todo:
Parameters
iconSet icon
Parameters
rolesvector of roles to create
channelsvector of channels to create
Returns
aegis::future<gateway::objects::guild>
aegis::future< gateway::objects::guild > aegis::core::create_guild ( create_guild_t  obj)

Create new guild - Unique case. Does not belong to any ratelimit bucket so it is run directly on the same thread and does not attempt to manage ratelimits due to the already existing requirement that the bot must be in less than 10 guilds for this call to succeed

See also
aegis::create_guild_t
Parameters
objStruct of the contents of the request
Returns
aegis::future<gateway::objects::guild>
void aegis::core::debug_trace ( shards::shard _shard)
noexcept

Outputs the last 5 messages received from the gateway.

Parameters
_shardPointer to the shard object to dump recent messages
channel * aegis::core::dm_channel_create ( const json &  obj,
shards::shard _shard 
)

Called by CHANNEL_CREATE (DirectMessage)

Parameters
objjson obj of DM channel
_shardShard this channel will exist on
Returns
Pointer to channel
Todo:
channel * aegis::core::find_channel ( snowflake  id) const
noexcept

Obtain a pointer to a channel by snowflake.

Parameters
idSnowflake of channel to search for
Returns
Pointer to channel or nullptr
guild * aegis::core::find_guild ( snowflake  id) const
noexcept

Obtain a pointer to a guild by snowflake.

Parameters
idSnowflake of guild to search for
Returns
Pointer to guild or nullptr
user * aegis::core::find_user ( snowflake  id) const
noexcept

Obtain a pointer to a user by snowflake.

Parameters
idSnowflake of user to search for
Returns
Pointer to user or nullptr
int64_t aegis::core::get_channel_count ( ) const
noexcept

Get count of unique channels tracked.

Returns
int64_t of channel count
std::unordered_map<snowflake, std::unique_ptr<channel> >& aegis::core::get_channel_map ( )

Get the channel map.

This will return the internal unordered_map of all the channels currently tracked. Does not include stale items. You MUST lock the appropriate mutex BEFORE accessing it to prevent potential race conditions and possible crashes.

Example:

std::shared_lock<aegis::shared_mutex> l(get_channel_mutex());
Returns
std::unordered_map<snowflake, std::unique_ptr<channel>>
int64_t aegis::core::get_guild_count ( ) const
noexcept

Get count of unique guilds tracked.

Returns
int64_t of guild count
std::unordered_map<snowflake, std::unique_ptr<guild> >& aegis::core::get_guild_map ( )

Get the guild map.

This will return the internal unordered_map of all the guilds currently tracked. Does not include stale items. You MUST lock the appropriate mutex BEFORE accessing it to prevent potential race conditions and possible crashes.

Example:

std::shared_lock<aegis::shared_mutex> l(get_guild_mutex());
Returns
std::unordered_map<snowflake, std::unique_ptr<guild>>
const snowflake aegis::core::get_id ( ) const
noexcept

Get the snowflake of the bot.

Returns
A snowflake of the bot
int64_t aegis::core::get_member_count ( ) const
noexcept

Get count of members tracked (includes duplicates from multiple shared guilds)

Returns
int64_t of member count
ratelimit_mgr_t& aegis::core::get_ratelimit ( )
noexcept

Get the ratelimit object.

Returns
Reference to the internal rate limiter
rest::rest_controller& aegis::core::get_rest_controller ( )
noexcept

Get the rest controller object.

Returns
Reference to the internal rest controller
aegis::shards::shard & aegis::core::get_shard_by_guild ( snowflake  guild_id)

Get a reference to the shard that the provided guild is on.

Parameters
guild_idSnowflake of guild
Returns
Reference to shard
aegis::shards::shard & aegis::core::get_shard_by_id ( uint16_t  shard_id)

Get a reference to the shard by shard id.

Parameters
shard_idShard id
Returns
Reference to shard
shards::shard_mgr& aegis::core::get_shard_mgr ( )
noexcept

Get the shard manager.

Returns
Reference to the internal shard manager
uint64_t aegis::core::get_shard_transfer ( ) const
noexcept

Get total transfer of bot in bytes.

Returns
uint64_t
uint64_t aegis::core::get_shard_u_transfer ( ) const
noexcept

Get total transfer of bot in bytes after decompression.

Returns
uint64_t
bot_status aegis::core::get_state ( ) const
noexcept

Get current state of the bot.

See also
bot_status
Returns
Current bot status
const std::string& aegis::core::get_token ( ) const
noexcept

Obtain bot's token.

Returns
std::string
std::chrono::hours aegis::core::get_tz_bias ( ) const
noexcept

Get the timezone offset.

Returns
std::chrono::hours of timezone bias
int64_t aegis::core::get_user_count ( ) const
noexcept

Get count of unique users tracked.

Returns
int64_t of user count
std::unordered_map<snowflake, std::unique_ptr<user> >& aegis::core::get_user_map ( )

Get the user map.

This will return the internal unordered_map of all the users currently tracked. Does not include stale items. You MUST lock the appropriate mutex BEFORE accessing it to prevent potential race conditions and possible crashes.

Example:

std::shared_lock<aegis::shared_mutex> l(get_user_mutex());
Returns
std::unordered_map<snowflake, std::unique_ptr<user>>
guild * aegis::core::guild_create ( snowflake  id,
shards::shard _shard 
)
noexcept

Obtain a pointer to a guild by snowflake. If none exists, creates the object.

Parameters
idSnowflake of guild to search for
_shardShard this guild will exist on
Returns
Pointer to guild
aegis::future< gateway::objects::member > aegis::core::modify_bot_avatar ( const std::string &  avatar)

Changes bot's avatar (not implemented yet. avatar can be changed in developer panel)

Parameters
avatarString of the avatar to set
Returns
aegis::future<gateway::objects::member>
aegis::future< gateway::objects::member > aegis::core::modify_bot_username ( const std::string &  username)

Changes bot's username (not implemented yet. username can be changed in developer panel)

Parameters
usernameString of the username to set
Returns
aegis::future<gateway::objects::member>
void aegis::core::reduce_threads ( std::size_t  count)
noexcept

Interrupt and end threads.

Parameters
countAmount of threads to shutdown
user* aegis::core::self ( ) const

Obtain pointer to self object.

Returns
Pointer to the user object of the bot
void aegis::core::send_all_shards ( const std::string &  msg)

Send a websocket message to a single shard.

Parameters
msgJSON encoded message to be sent
void aegis::core::send_all_shards ( const json &  msg)

Send a websocket message to a single shard.

Parameters
msgJSON encoded message to be sent
void aegis::core::set_state ( bot_status  s)
noexcept

Set the bot status.

See also
bot_status
Parameters
sStatus to set
std::shared_ptr<asio::steady_timer> aegis::core::set_timer ( long  duration,
std::function< void(const asio::error_code &)>  callback 
)

Passes through to Websocket++.

Parameters
durationTime until function should be run in milliseconds
callbackFunction to run when timer expires
void aegis::core::shutdown ( )
noexcept

Invokes a shutdown on the entire lib. Sets internal state to Shutdown and propagates the Shutdown state along with closing all websockets within the shard vector

void aegis::core::update_presence ( const std::string &  text,
gateway::objects::activity::activity_type  type = gateway::objects::activity::Game,
gateway::objects::presence::user_status  status = gateway::objects::presence::Online 
)

Update presence across all shards at once.

See also
aegis::gateway::objects::activity
aegis::gateway::objects::presence
Parameters
textText of presence message
typeEnum of the activity type
statusEnum of the status
int64_t aegis::core::uptime ( ) const
noexcept

Return shard uptime as {days hours minutes seconds}.

Returns
Time in milliseconds since shard received ready
std::string aegis::core::uptime_str ( ) const
noexcept

Return bot uptime as {days hours minutes seconds}.

Returns
std::string of hh mm ss formatted time
user * aegis::core::user_create ( snowflake  id)
noexcept

Obtain a pointer to a user by snowflake. If none exists, creates the object.

Parameters
idSnowflake of user to search for
Returns
Pointer to user
void aegis::core::yield ( )
noexcept

Yields operation of the current thread until library shutdown is detected


The documentation for this class was generated from the following files: