Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

zeroxs/aegis.cpp

Repository files navigation

Library is discontinued. Due to Discord's lack of communication and out-of-touch attitude towards library developers, this library is no longer being maintained. Recommended alternative: https://github.com/brainboxdotcc/DPP - designed similarly to how aegis was and created by users of aegis and a far more complete library than aegis (or any other C++ library) ever was.

Build Status Discord License

Aegis Library

C++14/17 library for interfacing with the Discord API

License

This project is licensed under the MIT license. See LICENSE

Libraries used (all are header-only with the exception of zlib and openssl):

TODO

  • Voice data send/recv
  • Finish documentation
  • Finish live example of library in use

Documentation

You can access the documentation here. It is a work in progress itself and has some missing parts, but most of the library is now documented.

Using this library

This library can be used compiled or as header only. All ways require recursive cloning of this repo. Some of the dependencies are version locked.

Header only

Including the helper header will automatically include all other files.

#include <aegis.hpp>

int main()
{
    aegis::core bot(aegis::create_bot_t().log_level(spdlog::level::trace).token("TOKEN"));
    bot.set_on_message_create([](auto obj)
    {
        if (obj.msg.get_content() == "Hi")
            obj.msg.get_channel().create_message(fmt::format("Hello {}", obj.msg.author.username));
    });
    bot.run();
    bot.yield();
}

Separate compilation

You can include #include <aegis/src.hpp> within a single cpp file while defining -DAEGIS_SEPARATE_COMPILATION, have #include <aegis.hpp> in your program, then build as usual.

Shared/Static library

You can build this library with CMake.

$ git clone --recursive https://github.com/zeroxs/aegis.cpp.git
$ cd aegis.cpp
$ mkdir build
$ cd build
$ cmake ..
// or to use C++17
$ cmake -DCMAKE_CXX_COMPILER=g++-7 -DCMAKE_CXX_STANDARD=17 ..

You can also add -DBUILD_EXAMPLES=1 and it will build 3 examples within the ./src directory.
example_main.cpp;example.cpp will build a bot that runs out of its own class
minimal.cpp will build two versions, one (aegis_minimal) will be with the shared/static library. The other (aegis_headeronly_no_cache) will be header-only but the lib will store no internal cache.

Compiler Options

You can pass these flags to CMake to change what it builds
-DBUILD_EXAMPLES=1 will build the examples
-DCMAKE_CXX_COMPILER=g++-7 will let you select the compiler used
-DCMAKE_CXX_STANDARD=17 will let you select C++14 (default) or C++17

Library

You can pass these flags to your compiler (and/or CMake) to alter how the library is built
-DAEGIS_DISABLE_ALL_CACHE will disable the internal caching of most objects such as member data reducing memory usage by a significant amount
-DAEGIS_DEBUG_HISTORY enables the saving of the last 5 messages sent on the shard's websocket. In the event of an uncaught exception, they are dumped to console.
-DAEGIS_PROFILING enables the usage of 3 callbacks that can help track time spent within the library. See docs:

  1. aegis::core::set_on_message_end Called when message handler is finished. Counts only your message handler time.
  2. aegis::core::set_on_js_end Called when the incoming json event is parsed. Counts only json parse time.
  3. aegis::core::set_on_rest_end Called when a REST (or any HTTP request is made) is finished. Counts only entire HTTP request time and includes response status code.
Your project

Options above, as well as: -DAEGIS_DYN_LINK used when linking the library as a shared object
-DAEGIS_HEADER_ONLY to make library header-only (default option)
-DAEGIS_SEPARATE_COMPILATION used when linking the library as static or separate cpp file within your project

CMake misc

If configured with CMake, it will create a pkg-config file that may help with compiling your own project.
It can be used as such:
g++ -std=c++14 myfile.cpp $(pkg-config --cflags --libs aegis)
to link to the shared object

g++ -std=c++14 myfile.cpp $(pkg-config --cflags --libs aegis_static)
to link to the static object

You can also use this library within your own CMake project by adding find_package(Aegis REQUIRED) to your CMakeLists.txt.

Config

You can change basic configuration options within the config.json file. It should be in the same directory as the executable.

{
	"token": "BOTTOKENHERE",
	"force-shard-count": 10,
	"file-logging": false,
	"log-format": "%^%Y-%m-%d %H:%M:%S.%e [%L] [th#%t]%$ : %v"
}

Alternatively you can configure the library by passing in the create_bot_t() object to the constructor of the aegis::core object. You can make use of it fluent-style.

aegis::core(aegis::create_bot_t().log_level(spdlog::level::trace).token("TOKEN"))