Giter Club home page Giter Club logo

ekizu's Introduction

Ekizu

A WIP C++ library for Discord applications.

Features

  • Low memory footprint
  • Discord API v10 support
  • Gateway support, with auto-reconnect
  • JSON support, convert and serialize events/structures to/from JSON

Usage/Examples

#include <dotenv/dotenv.h>
#include <ekizu/http_client.hpp>
#include <ekizu/shard.hpp>
#include <nlohmann/json.hpp>

using namespace ekizu;

std::function<void(Event)> handle_event(HttpClient &http);

int main()
{
	dotenv::init();
	const auto token = dotenv::getenv("DISCORD_TOKEN");

	auto http = HttpClient{ token };
	const auto intents = Intents::AllIntents;
	auto shard = Shard{ ShardId::ONE, token, intents };

	if (const auto res = shard.run(handle_event(http)); !res) {
		fmt::println("Failed to run shard: {}", res.error().message());
		return 1;
	}
}

template <typename... Func> struct overload : Func... {
	using Func::operator()...;
};

template <typename... Func> overload(Func...) -> overload<Func...>;

std::function<void(Event)> handle_event(HttpClient &http)
{
	return [&http](Event ev) {
		std::visit(
			overload{
				[](const Ready &r) {
					fmt::println("{} is ready!",
						     r.user.username);
				},
				[&http](const MessageCreate &payload) {
					const auto &[msg] = payload;

					const auto res =
						http.create_message(
							    msg.channel_id)
							.content(fmt::format(
								"{} said: {}\nAvatar: {}",
								msg.author
									.username,
								msg.content,
								msg.author.avatar ?
									*msg.author
										 .avatar :
									"null"))
							.send();

					if (!res) {
						fmt::println(
							"Failed to send message: {}",
							res.error().message());
					}
				},
				[](Resumed) {
					fmt::println("Resumed Event Called");
				},
				[](const auto &e) {
					fmt::println(
						"Uncaught {} event: {}",
						typeid(e).name(),
						nlohmann::json{ e }.dump());
				} },
			ev);
	};
}

See examples.

Getting Started

Prerequisites

  • CMake (version >= 3.16)
  • Compiler with C++17 support, i.e. MSVC, GCC, Clang

Installing

This library uses CPM.cmake to manage dependencies. It is an amazing package manager for CMake projects and allows us to install the entire library using the following commands:

  git clone https://www.github.com/xminent/ekizu
  cd ekizu
  cmake -S . -B build
  cmake --build build --target install

From there you can simply integrate it into your CMake project like so:

    find_package(ekizu REQUIRED)
    target_link_libraries(${PROJECT_NAME} PRIVATE ekizu::ekizu)

Contributing

Contributions, issues and feature requests are welcome. After cloning and setting up project locally, you can just submit a PR to this repo and it will be deployed once it's accepted.

Take full advantage of the .clang-format file located in the root of the project to ensure that your code is properly formatted.

Dependencies

Third party Dependencies

  • fmt (comes bundled with project)
  • net (comes bundled with project)
  • nlohmann_json (comes bundled with project)
  • zlib (comes bundled with project, unless you have it installed)

License

MIT

ekizu's People

Contributors

jontitorr 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.