D++ (DPP)
C++ Discord API Bot Library
dpp::utility Namespace Reference

Utility helper functions, generally for logging. More...

Classes

struct  iconhash
 Store a 128 bit icon hash (profile picture, server icon etc) as a 128 bit binary value made of two uint64_t. Has a constructor to build one from a string, and a method to fetch the value back in string form. More...
 
struct  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...
 

Typedefs

typedef std::function< void(const std::string &output)> cmd_result_t
 

Functions

void CoreExport exec (const std::string &cmd, std::vector< std::string > parameters={}, cmd_result_t callback={})
 Run a commandline program asyncronously. The command line program is spawned in a separate std::thread, and when complete, its output from stdout is passed to the callback function in its string prameter. For eample. More...
 
std::string CoreExport current_date_time ()
 Returns urrent date and time. More...
 
std::string CoreExport loglevel (dpp::loglevel in)
 Convert a dpp::loglevel enum value to a string. More...
 
double CoreExport time_f ()
 Return the current time with fractions of seconds. This is a unix epoch time with the fractional seconds part after the decimal place. More...
 
bool CoreExport has_voice ()
 Returns true if D++ was built with voice support. More...
 
std::string CoreExport bytes (uint64_t c)
 Convert a byte count to display value. More...
 
void CoreExport debug_dump (uint8_t *data, size_t length)
 Output hex values of a section of memory for debugging. More...
 
size_t CoreExport utf8len (const std::string &str)
 Returns the length of a UTF-8 string in codepoints. More...
 
std::string CoreExport utf8substr (const std::string &str, std::string::size_type start, std::string::size_type length)
 Return substring of a UTF-8 encoded string in codepoints. More...
 

Detailed Description

Utility helper functions, generally for logging.

Typedef Documentation

◆ cmd_result_t

typedef std::function<void(const std::string& output)> dpp::utility::cmd_result_t

Function Documentation

◆ bytes()

std::string CoreExport dpp::utility::bytes ( uint64_t  c)

Convert a byte count to display value.

Parameters
cnumber of bytes
Returns
std::string display value suffixed with M, G, T where neccessary

◆ current_date_time()

std::string CoreExport dpp::utility::current_date_time ( )

Returns urrent date and time.

Returns
std::string Current date and time

◆ debug_dump()

void CoreExport dpp::utility::debug_dump ( uint8_t *  data,
size_t  length 
)

Output hex values of a section of memory for debugging.

Parameters
dataThe start of the data to display
lengthThe length of data to display

◆ exec()

void CoreExport dpp::utility::exec ( const std::string &  cmd,
std::vector< std::string >  parameters = {},
cmd_result_t  callback = {} 
)

Run a commandline program asyncronously. The command line program is spawned in a separate std::thread, and when complete, its output from stdout is passed to the callback function in its string prameter. For eample.

dpp::utility::exec("ls", [](const std::string& output) {
std::cout << "Output of 'ls': " << output << "\n";
});
void CoreExport exec(const std::string &cmd, std::vector< std::string > parameters={}, cmd_result_t callback={})
Run a commandline program asyncronously. The command line program is spawned in a separate std::threa...
Parameters
cmdThe command to run.
parametersCommand line parameters. Each will be escaped using std::quoted.
callbackThe callback to call on completion.

◆ has_voice()

bool CoreExport dpp::utility::has_voice ( )

Returns true if D++ was built with voice support.

Returns
bool True if voice support is compiled in (libsodium/libopus)

◆ loglevel()

std::string CoreExport dpp::utility::loglevel ( dpp::loglevel  in)

Convert a dpp::loglevel enum value to a string.

Parameters
inlog level to convert
Returns
std::string string form of log level

◆ time_f()

double CoreExport dpp::utility::time_f ( )

Return the current time with fractions of seconds. This is a unix epoch time with the fractional seconds part after the decimal place.

Returns
double time with fractional seconds

◆ utf8len()

size_t CoreExport dpp::utility::utf8len ( const std::string &  str)

Returns the length of a UTF-8 string in codepoints.

Parameters
strstring to count length of
Returns
size_t length of string (0 for invalid utf8)

◆ utf8substr()

std::string CoreExport dpp::utility::utf8substr ( const std::string &  str,
std::string::size_type  start,
std::string::size_type  length 
)

Return substring of a UTF-8 encoded string in codepoints.

Parameters
strstring to return substring from
startstart codepoint offset
lengthlength in codepoints
Returns
std::string Substring in UTF-8 or emtpy string if invalid UTF-8 passed in
D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0