D++ (DPP)  10.0.30
C++ Discord API Bot Library
utility.h File Reference
#include <dpp/export.h>
#include <dpp/snowflake.h>
#include <dpp/misc-enum.h>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <functional>
#include <cstddef>
#include <variant>
#include <memory>
#include <string_view>
Include dependency graph for utility.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  dpp::utility::dummy< T >
 Utility struct that has the same size and alignment as another but does nothing. More...
 
struct  dpp::utility::icon
 Wrapper class around a variant for either iconhash or image, for API objects that have one or the other (generally iconhash when receiving, image when uploading an image) More...
 
struct  dpp::utility::iconhash
 Store a 128 bit icon hash (profile picture, server icon etc) as a 128 bit binary value made of two uint64_t. More...
 
struct  dpp::utility::image_data
 Image to be received or sent to API calls. More...
 
struct  dpp::utility::uptime
 A class used to represent an uptime in hours, minutes, seconds and days, with helper functions to convert from time_t and display as a string. More...
 

Namespaces

 dpp
 The main namespace for D++ functions.
 
 dpp::utility
 Utility helper functions, generally for logging, running programs, time/date manipulation, etc.
 

Macros

#define DPP_CHECK_ABI_COMPAT(a, b)
 Macro that expands to static_asserts checking sizeof and alignof are equal between two types. More...
 

Typedefs

typedef std::function< void(const std::string &output)> dpp::utility::cmd_result_t
 Callback for the results of a command executed via dpp::utility::exec. More...
 

Enumerations

enum  dpp::utility::avx_type_t : uint8_t {
  dpp::utility::avx_none,
  dpp::utility::avx_1,
  dpp::utility::avx_2,
  dpp::utility::avx_512
}
 Supported AVX instruction set type for audio mixing. More...
 
enum  dpp::utility::guild_navigation_type {
  dpp::utility::gnt_customize,
  dpp::utility::gnt_browse,
  dpp::utility::gnt_guide
}
 Guild navigation types for dpp::utility::guild_navigation() More...
 
enum  dpp::utility::time_format : uint8_t {
  dpp::utility::tf_long_date = 'D',
  dpp::utility::tf_long_datetime = 'F',
  dpp::utility::tf_relative_time = 'R',
  dpp::utility::tf_long_time = 'T',
  dpp::utility::tf_short_date = 'd',
  dpp::utility::tf_short_datetime = 'f',
  dpp::utility::tf_short_time = 't'
}
 Timestamp formats for dpp::utility::timestamp() More...
 

Functions

std::string DPP_EXPORT dpp::utility::avatar_size (uint32_t size)
 Get the url query parameter for the cdn endpoint. More...
 
std::string DPP_EXPORT dpp::utility::bot_invite_url (const snowflake bot_id, const uint64_t permissions=0, const std::vector< std::string > &scopes={"bot", "applications.commands"})
 Create a bot invite. More...
 
std::string DPP_EXPORT dpp::utility::bytes (uint64_t c)
 Convert a byte count to display value. More...
 
std::string DPP_EXPORT dpp::utility::cdn_endpoint_url (const std::vector< image_type > &allowed_formats, const std::string &path_without_extension, const dpp::image_type format, uint16_t size, bool prefer_animated=false, bool is_animated=false)
 Helper function to easily create discord's cdn endpoint urls. More...
 
std::string DPP_EXPORT dpp::utility::cdn_endpoint_url_hash (const std::vector< image_type > &allowed_formats, const std::string &path_without_extension, const std::string &hash, const dpp::image_type format, uint16_t size, bool prefer_animated=false, bool is_animated=false)
 Helper function to easily create discord's cdn endpoint urls. More...
 
std::string DPP_EXPORT dpp::utility::cdn_endpoint_url_sticker (snowflake sticker_id, sticker_format format)
 Helper function to easily create discord's cdn endpoint urls (specialised for stickers) More...
 
std::string DPP_EXPORT dpp::utility::channel_mention (const snowflake &id)
 Create a mentionable channel. More...
 
std::string DPP_EXPORT dpp::utility::channel_url (const snowflake &guild_id, const snowflake &channel_id)
 Create a URL for message. More...
 
uint32_t DPP_EXPORT dpp::utility::cmyk (double c, double m, double y, double k)
 Convert doubles to CMYK for sending in embeds. More...
 
uint32_t DPP_EXPORT dpp::utility::cmyk (int c, int m, int y, int k)
 Convert ints to CMYK for sending in embeds. More...
 
std::string DPP_EXPORT dpp::utility::current_date_time ()
 Returns current date and time. More...
 
std::string DPP_EXPORT dpp::utility::debug_dump (uint8_t *data, size_t length)
 Output hex values of a section of memory for debugging. More...
 
std::string DPP_EXPORT dpp::utility::emoji_mention (std::string_view name, snowflake id, bool is_animated=false)
 Create a mentionable emoji. More...
 
void DPP_EXPORT dpp::utility::exec (const std::string &cmd, std::vector< std::string > parameters={}, cmd_result_t callback={})
 Run a commandline program asynchronously. More...
 
std::string DPP_EXPORT dpp::utility::file_extension (image_type type)
 Get the file extension for an image type. More...
 
std::string DPP_EXPORT dpp::utility::file_extension (sticker_format format)
 Get the file extension for a sticker format. More...
 
std::string DPP_EXPORT dpp::utility::guild_navigation (const snowflake guild_id, guild_navigation_type gnt)
 Create a mentionable guild navigation (used in a message). More...
 
bool DPP_EXPORT dpp::utility::has_voice ()
 Returns true if D++ was built with voice support. More...
 
uint32_t DPP_EXPORT dpp::utility::hsl (double h, double s, double l)
 Convert doubles to HSL for sending in embeds. More...
 
uint32_t DPP_EXPORT dpp::utility::hsl (int h, int s, int l)
 Convert ints to HSL for sending in embeds. More...
 
bool DPP_EXPORT dpp::utility::is_coro_enabled ()
 Returns true if D++ was built with coroutine support. More...
 
std::string DPP_EXPORT dpp::utility::loglevel (dpp::loglevel in)
 Convert a dpp::loglevel enum value to a string. More...
 
std::string DPP_EXPORT dpp::utility::make_url_parameters (const std::map< std::string, std::string > &parameters)
 Build a URL parameter string e.g. More...
 
std::string DPP_EXPORT dpp::utility::make_url_parameters (const std::map< std::string, uint64_t > &parameters)
 Build a URL parameter string e.g. More...
 
std::string DPP_EXPORT dpp::utility::markdown_escape (const std::string &text, bool escape_code_blocks=false)
 Escapes Discord's markdown sequences in a string. More...
 
std::string DPP_EXPORT dpp::utility::message_url (const snowflake &guild_id, const snowflake &channel_id, const snowflake &message_id)
 Create a URL for message. More...
 
std::string DPP_EXPORT dpp::utility::mime_type (image_type type)
 Get the mime type for an image type. More...
 
std::string DPP_EXPORT dpp::utility::mime_type (sticker_format format)
 Get the mime type for a sticker format. More...
 
std::string DPP_EXPORT dpp::utility::read_file (const std::string &filename)
 Read a whole file into a std::string. More...
 
uint32_t DPP_EXPORT dpp::utility::rgb (double red, double green, double blue)
 Convert doubles to RGB for sending in embeds. More...
 
uint32_t DPP_EXPORT dpp::utility::rgb (int red, int green, int blue)
 Convert ints to RGB for sending in embeds. More...
 
std::string DPP_EXPORT dpp::utility::role_mention (const snowflake &id)
 Create a mentionable role. More...
 
void DPP_EXPORT dpp::utility::set_thread_name (const std::string &name)
 Set the name of the current thread for debugging and statistical reporting. More...
 
std::string DPP_EXPORT dpp::utility::slashcommand_mention (snowflake command_id, const std::string &command_name, const std::string &subcommand="")
 Create a mentionable slashcommand (used in a message). More...
 
std::string DPP_EXPORT dpp::utility::slashcommand_mention (snowflake command_id, const std::string &command_name, const std::string &subcommand_group, const std::string &subcommand)
 Create a mentionable slashcommand (used in a message). More...
 
std::string DPP_EXPORT dpp::utility::thread_url (const snowflake &guild_id, const snowflake &thread_id)
 Create a URL for message. More...
 
double DPP_EXPORT dpp::utility::time_f ()
 Return the current time with fractions of seconds. More...
 
std::string DPP_EXPORT dpp::utility::timestamp (time_t ts, time_format tf=tf_short_datetime)
 Return a mentionable timestamp (used in a message). More...
 
std::vector< std::string > DPP_EXPORT dpp::utility::tokenize (std::string const &in, const char *sep="\r\n")
 Split (tokenize) a string into a vector, using the given separators. More...
 
std::string DPP_EXPORT dpp::utility::url_encode (const std::string &value)
 Encodes a url parameter similar to php urlencode() More...
 
std::string DPP_EXPORT dpp::utility::user_mention (const snowflake &id)
 Create a mentionable user. More...
 
std::string DPP_EXPORT dpp::utility::user_url (const snowflake &user_id)
 Create a URL for message. More...
 
size_t DPP_EXPORT dpp::utility::utf8len (std::string_view str)
 Returns the length of a UTF-8 string in codepoints. More...
 
std::string DPP_EXPORT dpp::utility::utf8substr (std::string_view str, size_t start, size_t length)
 Return substring of a UTF-8 encoded string in codepoints. More...
 
std::string_view DPP_EXPORT dpp::utility::utf8subview (std::string_view str, size_t start, size_t length)
 Return subview of a UTF-8 encoded string in codepoints. More...
 
std::string DPP_EXPORT dpp::utility::validate (const std::string &value, size_t _min, size_t _max, const std::string &exception_message)
 Validate a string value In the event the length of the string is less than _min, then an exception of type dpp:length_exception will be thrown. More...
 
std::string DPP_EXPORT dpp::utility::version ()
 Returns the library's version string. More...
 
avx_type_t DPP_EXPORT dpp::utility::voice_avx ()
 Returns an enum value indicating which AVX instruction set is used for mixing received voice data, if any. More...
 

Variables

template<typename F , typename R , typename... Args>
constexpr bool dpp::utility::callable_returns_v = std::is_convertible_v<std::invoke_result_t<F, Args...>, R>
 Type trait to check if a callable F can be called using the arguments Args, and that its return value is convertible to R. More...
 
const std::string dpp::utility::cdn_host = "https://cdn.discordapp.com"
 The base URL for CDN content such as profile pictures and guild icons. More...
 
const std::string dpp::utility::url_host = "https://discord.com"
 The base URL for message/user/channel links. More...
 

Macro Definition Documentation

◆ DPP_CHECK_ABI_COMPAT

#define DPP_CHECK_ABI_COMPAT (   a,
 
)
Value:
static_assert(sizeof(a) == sizeof(b), #a " and " #b " must be the same size for ABI compatibility"); \
static_assert(alignof(a) == alignof(b), #a " and " #b " must be the same alignment for ABI compatibility"); \

Macro that expands to static_asserts checking sizeof and alignof are equal between two types.

dpp::unicode_emoji::a
constexpr const char a[]
Definition: unicode_emoji.h:5254
dpp::unicode_emoji::b
constexpr const char b[]
Definition: unicode_emoji.h:5255