Git Product home page Git Product logo

cpp-sdk's Introduction

Top.gg SDK for C++

The official C++ SDK for the Top.gg API.

Building from source

NOTE: To enable C++20 coroutine methods, add -DENABLE_CORO=ON!

Linux (Debian-like)

# install D++
wget -O dpp.deb https://dl.dpp.dev/latest
dpkg -i dpp.deb

# build topgg
cmake -B build .
cmake --build build --config Release

Linux (CentOS-like)

# install D++
yum install wget
wget -O dpp.rpm https://dl.dpp.dev/latest/linux-x64/rpm
yum localinstall dpp.rpm

# build topgg
cmake -B build .
cmake --build build --config Release

macOS

# install D++
brew install libdpp
brew link libdpp

# build topgg
cmake -B build .
cmake --build build --config Release

Windows

cmake -B build .
cmake --build build --config Release

Examples

Fetching a bot from its Discord ID

dpp::cluster bot{"your bot token"};
topgg::client topgg_client{bot, "your top.gg token"};

// using C++17 callbacks
topgg_client.get_bot(264811613708746752, [](const auto& result) {
  try {
    const auto topgg_bot = result.get();
  
    std::cout << topgg_bot.username << std::endl;
  } catch (const std::exception& exc) {
    std::cout << "error: " << exc.what() << std::endl;
  }
});

// using C++20 coroutines
try {
  const auto topgg_bot = co_await topgg_client.co_get_bot(264811613708746752);
  
  std::cout << topgg_bot.username << std::endl;
} catch (const std::exception& exc) {
  std::cout << "error: " << exc.what() << std::endl;
}

Fetching a user from its Discord ID

dpp::cluster bot{"your bot token"};
topgg::client topgg_client{bot, "your top.gg token"};

// using C++17 callbacks
topgg_client.get_user(264811613708746752, [](const auto& result) {
  try {
    const auto user = result.get();
  
    std::cout << user.username << std::endl;
  } catch (const std::exception& exc) {
    std::cout << "error: " << exc.what() << std::endl;
  }
});

// using C++20 coroutines
try {
  const auto user = co_await topgg_client.co_get_user(661200758510977084);
  
  std::cout << user.username << std::endl;
} catch (const std::exception& exc) {
  std::cout << "error: " << exc.what() << std::endl;
}

Posting your bot's statistics

dpp::cluster bot{"your bot token"};
topgg::client topgg_client{bot, "your top.gg token"};

// using C++17 callbacks
topgg_client.post_stats([](const auto success) {
  if (success) {
    std::cout << "stats posted!" << std::endl;
  }
});

// using C++20 coroutines
const auto success = co_await topgg_client.co_post_stats();

if (success) {
  std::cout << "stats posted!" << std::endl;
}

Checking if a user has voted your bot

dpp::cluster bot{"your bot token"};
topgg::client topgg_client{bot, "your top.gg token"};

// using C++17 callbacks
topgg_client.has_voted(661200758510977084, [](const auto& result) {
  try {
    if (result.get()) {
      std::cout << "checks out" << std::endl;
    }
  } catch (const std::exception& exc) {
    std::cout << "error: " << exc.what() << std::endl;
  }
});

// using C++20 coroutines
try {
  const auto voted = co_await topgg_client.co_has_voted(661200758510977084);

  if (voted) {
    std::cout << "checks out" << std::endl;
  }
} catch (const std::exception& exc) {
  std::cout << "error: " << exc.what() << std::endl;
}

Default autoposting

dpp::cluster bot{"your bot token"};
topgg::client topgg_client{bot, "your top.gg token"};

topgg_client.start_autoposter();

Customized autoposting

dpp::cluster bot{"your bot token"};
topgg::client topgg_client{bot, "your top.gg token"};

topgg_client.start_autoposter([](dpp::cluster& bot_inner) {
  return topgg::stats{...};
});

cpp-sdk's People

Contributors

null8626 avatar braindigitalis avatar pixxies avatar voltrexkeyva avatar ffamilyfriendly 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.