C++14/17 library for interfacing with the Discord API
This project is licensed under the MIT license. See LICENSE
Libraries used (all are header-only with the exception of zlib):
- Asio
- Websocketpp
- JSON for Modern C++
- spdlog (by extension, fmtlib)
- OpenSSL 1.0.2
- zlib
- zstr
- Voice data send/recv
- Finish documentation
- Finish live example of library in use
- Finish remaining API endpoints
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.
There are multiple ways to make use of this library.
Including the helper header will automatically include all other files.
#include <aegis.hpp>
int main()
{
aegis::core bot;
bot.i_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();
}
You can include #include <aegis/src.hpp>
within a single cpp file while defining -DAEGIS_SEPARATE_COMPILATION
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 -DCXX_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.
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
-DCXX_STANDARD=17
will let you select C++14 (default) or C++17
You can pass these flags to your compiler 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
by setting up to 3 specific functions within the main class:
bot.message_end = std::bind(&AegisBot::message_end, this, std::placeholders::_1, std::placeholders::_2);
bot.js_end = std::bind(&AegisBot::js_end, this, std::placeholders::_1, std::placeholders::_2);
bot.call_end = std::bind(&AegisBot::call_end, this, std::placeholders::_1);
your callbacks will be executed:
message_end
: when a whole message is done being processed including your own callback time but not including js decode timejs_end
: when a js decoding is completedcall_end
: when a rest call function is completed
message_end
and js_end
both are passed 2 parameters (std::chrono::steady_clock::time_point, const std::string &)
while call_end
is only passed (std::chrono::steady_clock::time_point)
. The time_point being passed is the time the action started. The string being the websocket event name being processed.
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
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 minimal.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
.
You can change basic configuration options within the config.json
file that should be in the same directory as the executable when built.
{
"token": "BOTTOKENHERE",
"force-shard-count": 10
}