Coder Social home page Coder Social logo

fieryswampshire / aegis.cpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zeroxs/aegis.cpp

0.0 1.0 0.0 2.6 MB

Discord C++ library for interfacing with the API. Join our server:

Home Page: https://discord.gg/w7Y3Bb8

License: MIT License

C++ 96.59% CMake 3.07% Shell 0.32% Vim Script 0.01%

aegis.cpp's Introduction

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"))

aegis.cpp's People

Contributors

braindigitalis avatar cydrith avatar emil-jarosz avatar gena2018115rus avatar geniiii avatar gitmeep avatar jpahm avatar lohkdesgds avatar mayankmohan avatar nandemonogatari avatar willem640 avatar zeroxs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.