33 #pragma warning(disable : 4710)
34 #pragma warning(disable : 4711)
35 #pragma warning(disable : 4251)
36 #pragma warning(disable : 4371)
37 #pragma warning(disable : 4514)
38 #pragma warning(disable : 4623)
39 #pragma warning(disable : 4625)
40 #pragma warning(disable : 4626)
41 #pragma warning(disable : 4820)
42 #pragma warning(disable : 5267)
43 #pragma warning(disable : 5026)
44 #pragma warning(disable : 5027)
45 #pragma warning(disable : 5045)
46 #pragma warning(disable : 5246)
50 #if !defined DiscordCoreAPI_EXPORTS_NOPE
51 #if defined DiscordCoreAPI_EXPORTS
52 #if !defined DiscordCoreAPI_Dll
53 #define DiscordCoreAPI_Dll __declspec(dllexport)
56 #if !defined DiscordCoreAPI_Dll
57 #define DiscordCoreAPI_Dll __declspec(dllimport)
61 #define DiscordCoreAPI_Dll
63 #if !defined WIN32_LEAN_AND_MEAN
64 #define WIN32_LEAN_AND_MEAN
66 #if !defined WINRT_LEAN_AND_MEAN
67 #define WINRT_LEAN_AND_MEAN
69 #if !defined(NOMINMAX)
73inline std::tm getCurrentTimeVal(time_t& result) {
75 localtime_s(&resultTwo, &result);
80 #if !defined DiscordCoreAPI_Dll
81 #define DiscordCoreAPI_Dll
83 #include <arpa/inet.h>
90inline std::tm getCurrentTimeVal(time_t& result) {
91 std::tm resultTwo{ *localtime(&result) };
96#include <jsonifier/Index.hpp>
98#include <source_location>
99#include <shared_mutex>
100#include <immintrin.h>
116using namespace std::literals;
161 extern thread_local jsonifier::jsonifier_core parser;
163 template<
typename value_type>
using stop_watch = jsonifier_internal::stop_watch<value_type>;
164 using sys_clock = std::chrono::system_clock;
165 using hrclock = std::chrono::high_resolution_clock;
166 using milliseconds = std::chrono::duration<int64_t, std::milli>;
167 using microseconds = std::chrono::duration<int64_t, std::micro>;
168 using nanoseconds = std::chrono::duration<int64_t, std::nano>;
169 using seconds = std::chrono::duration<int64_t, std::ratio<1, 1>>;
171 enum class print_message_type {
177 inline constexpr jsonifier::string_view shiftToBrightGreen() {
178 return "\033[1;40;92m";
181 inline constexpr jsonifier::string_view shiftToBrightBlue() {
182 return "\033[1;40;96m";
185 inline constexpr jsonifier::string_view shiftToBrightRed() {
186 return "\033[1;40;91m";
189 inline constexpr jsonifier::string_view reset() {
206 template<
typename value_type>
inline static void initialize(
const value_type& other) {
221 template<pr
int_message_type messageType,
typename string_type>
222 inline static void printError(
const string_type& what, std::source_location where = std::source_location::current()) {
223 switch (messageType) {
224 case print_message_type::general: {
227 *
errorStream << shiftToBrightRed() <<
"General error, caught at: " << where.file_name() <<
", " << where.line() <<
":" << where.column()
228 <<
", in: " << where.function_name() <<
", it is: " << what << std::endl
229 << reset() << std::endl;
233 case print_message_type::websocket: {
236 *
errorStream << shiftToBrightRed() <<
"WebSocket error, caught at: " << where.file_name() <<
", " << where.line() <<
":" << where.column()
237 <<
", in: " << where.function_name() <<
", it is: " << what << std::endl
238 << reset() << std::endl;
242 case print_message_type::https: {
245 *
errorStream << shiftToBrightRed() <<
"Https error, caught at: " << where.file_name() <<
", " << where.line() <<
":" << where.column()
246 <<
", in: " << where.function_name() <<
", it is: " << what << std::endl
247 << reset() << std::endl;
258 template<pr
int_message_type messageType,
typename string_type>
259 inline static void printSuccess(
const string_type& what, std::source_location where = std::source_location::current()) {
260 switch (messageType) {
261 case print_message_type::general: {
264 *
outputStream << shiftToBrightBlue() <<
"General success, caught at: " << where.file_name() <<
", " << where.line() <<
":" << where.column()
265 <<
", in: " << where.function_name() <<
", it is: " << what << std::endl
266 << reset() << std::endl;
270 case print_message_type::websocket: {
273 *
outputStream << shiftToBrightGreen() <<
"WebSocket success, caught at: " << where.file_name() <<
", " << where.line() <<
":" << where.column()
274 <<
", in: " << where.function_name() <<
", it is: " << what << std::endl
275 << reset() << std::endl;
279 case print_message_type::https: {
282 *
outputStream << shiftToBrightGreen() <<
"Https success, caught at: " << where.file_name() <<
", " << where.line() <<
":" << where.column()
283 <<
", in: " << where.function_name() <<
", it is: " << what << std::endl
284 << reset() << std::endl;
323 return static_cast<jsonifier::string
>(*
static_cast<const value_type*
>(
this)) == other;
334 inline static jsonifier::string
convertToFutureISO8601TimeStamp(uint64_t minutesToAdd, uint64_t hoursToAdd, uint64_t daysToAdd, uint64_t monthsToAdd, uint64_t yearsToAdd,
336 std::time_t result = std::time(
nullptr);
337 static constexpr uint64_t secondsPerMinute{ 60ULL };
338 static constexpr uint64_t minutesPerHour{ 60ULL };
339 static constexpr uint64_t secondsPerHour{ minutesPerHour * secondsPerMinute };
340 static constexpr uint64_t hoursPerDay{ 24ULL };
341 static constexpr uint64_t secondsPerDay{ secondsPerHour * hoursPerDay };
342 static constexpr uint64_t daysPerMonth{ 30ULL };
343 static constexpr uint64_t secondsPerMonth{ secondsPerDay * daysPerMonth };
344 static constexpr uint64_t daysPerYear{ 365ULL };
345 static constexpr uint64_t secondsPerYear{ secondsPerDay * daysPerYear };
346 uint64_t secondsToAdd = (yearsToAdd * secondsPerYear) + (monthsToAdd * secondsPerMonth) + (daysToAdd * secondsPerDay) + ((hoursToAdd + 8) * secondsPerHour) +
347 (minutesToAdd * secondsPerMinute);
348 result += secondsToAdd;
349 std::tm resultTwo{ getCurrentTimeVal(result) };
350 jsonifier::string returnString{};
351 if (resultTwo.tm_isdst) {
352 if (resultTwo.tm_hour + 4ULL >= 24) {
353 resultTwo.tm_hour = resultTwo.tm_hour - 24;
357 getTimeSinceEpoch(
static_cast<uint64_t
>(resultTwo.tm_year) + 1900ULL,
static_cast<uint64_t
>(resultTwo.tm_mon) + 1ULL,
static_cast<uint64_t
>(resultTwo.tm_mday),
358 static_cast<uint64_t
>(resultTwo.tm_hour) + 4ULL,
static_cast<uint64_t
>(resultTwo.tm_min),
static_cast<uint64_t
>(resultTwo.tm_sec));
361 if (resultTwo.tm_hour + 5ULL >= 24) {
362 resultTwo.tm_hour = resultTwo.tm_hour - 24;
366 getTimeSinceEpoch(
static_cast<uint64_t
>(resultTwo.tm_year) + 1900ULL,
static_cast<uint64_t
>(resultTwo.tm_mon) + 1ULL,
static_cast<uint64_t
>(resultTwo.tm_mday),
367 static_cast<uint64_t
>(resultTwo.tm_hour) + 5ULL,
static_cast<uint64_t
>(resultTwo.tm_min),
static_cast<uint64_t
>(resultTwo.tm_sec));
377 std::time_t result = std::time(
nullptr);
378 std::tm resultTwo{ getCurrentTimeVal(result) };
379 jsonifier::string returnString{};
380 if (resultTwo.tm_isdst) {
381 if (resultTwo.tm_hour + 4ULL >= 24) {
382 resultTwo.tm_hour = resultTwo.tm_hour - 24;
386 getTimeSinceEpoch(
static_cast<uint64_t
>(resultTwo.tm_year) + 1900ULL,
static_cast<uint64_t
>(resultTwo.tm_mon) + 1ULL,
static_cast<uint64_t
>(resultTwo.tm_mday),
387 static_cast<uint64_t
>(resultTwo.tm_hour) + 4ULL,
static_cast<uint64_t
>(resultTwo.tm_min),
static_cast<uint64_t
>(resultTwo.tm_sec));
390 if (resultTwo.tm_hour + 5ULL >= 24) {
391 resultTwo.tm_hour = resultTwo.tm_hour - 24;
395 getTimeSinceEpoch(
static_cast<uint64_t
>(resultTwo.tm_year) + 1900ULL,
static_cast<uint64_t
>(resultTwo.tm_mon) + 1ULL,
static_cast<uint64_t
>(resultTwo.tm_mday),
396 static_cast<uint64_t
>(resultTwo.tm_hour) + 5ULL,
static_cast<uint64_t
>(resultTwo.tm_min),
static_cast<uint64_t
>(resultTwo.tm_sec));
408 int64_t startTimeRaw{
static_cast<int64_t
>(
convertTimeStampToTimeUnits(
static_cast<jsonifier::string
>(*
static_cast<const value_type*
>(
this)))) };
410 std::chrono::current_zone()->to_sys(std::chrono::local_time<std::chrono::milliseconds>(std::chrono::milliseconds{ startTimeRaw })).time_since_epoch().count();
411 auto currentTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
412 static constexpr int64_t secondsPerMinute = 60ULL;
413 static constexpr int64_t secondsPerHour = secondsPerMinute * 60ULL;
414 static constexpr int64_t secondsPerDay = secondsPerHour * 24ULL;
415 auto targetElapsedTime =
416 ((
static_cast<int64_t
>(days) * secondsPerDay) + ((
static_cast<int64_t
>(hours)) * secondsPerHour) + (
static_cast<int64_t
>(minutes) * secondsPerMinute)) * 1000LL;
417 auto actualElapsedTime = currentTime - startTimeRaw;
418 if (actualElapsedTime <= 0) {
421 if (actualElapsedTime >= targetElapsedTime) {
432 jsonifier::string newString{};
433 static constexpr uint64_t msPerSecond{ 1000ULL };
434 static constexpr uint64_t secondsPerMinute{ 60ULL };
435 static constexpr uint64_t minutesPerHour{ 60ULL };
436 static constexpr uint64_t msPerMinute{ msPerSecond * secondsPerMinute };
437 static constexpr uint64_t msPerHour{ msPerMinute * minutesPerHour };
438 uint64_t hoursLeft =
static_cast<uint64_t
>(trunc(durationInMs / msPerHour));
439 uint64_t minutesLeft =
static_cast<uint64_t
>(trunc((durationInMs % msPerHour) / msPerMinute));
440 uint64_t secondsLeft =
static_cast<uint64_t
>(trunc(((durationInMs % msPerHour) % msPerMinute) / msPerSecond));
441 if (hoursLeft >= 1) {
442 newString += jsonifier::toString(hoursLeft) +
" hours, ";
443 newString += jsonifier::toString(minutesLeft) +
" minutes, ";
444 newString += jsonifier::toString(secondsLeft) +
" seconds.";
445 }
else if (minutesLeft >= 1) {
446 newString += jsonifier::toString(minutesLeft) +
" minutes, ";
447 newString += jsonifier::toString(secondsLeft) +
" seconds.";
449 newString += jsonifier::toString(secondsLeft) +
" seconds.";
459 uint64_t timeValue =
static_cast<uint64_t
>(inputTime) / 1000ULL;
460 time_t rawTime(
static_cast<time_t
>(timeValue));
461 std::tm resultTwo{ getCurrentTimeVal(rawTime) };
462 jsonifier::string timeStamp{};
463 timeStamp.resize(48);
464 switch (timeFormat) {
466 uint64_t sizeResponse = strftime(timeStamp.data(), 48,
"%d %B %G", &resultTwo);
467 timeStamp.resize(sizeResponse);
471 uint64_t sizeResponse = strftime(timeStamp.data(), 48,
"%FT%T", &resultTwo);
472 timeStamp.resize(sizeResponse);
476 uint64_t sizeResponse = strftime(timeStamp.data(), 48,
"%T", &resultTwo);
477 timeStamp.resize(sizeResponse);
481 uint64_t sizeResponse = strftime(timeStamp.data(), 48,
"%d/%m/%g", &resultTwo);
482 timeStamp.resize(sizeResponse);
486 uint64_t sizeResponse = strftime(timeStamp.data(), 48,
"%d %B %G %R", &resultTwo);
487 timeStamp.resize(sizeResponse);
491 uint64_t sizeResponse = strftime(timeStamp.data(), 48,
"%R", &resultTwo);
492 timeStamp.resize(sizeResponse);
510 inline static uint64_t
getTimeSinceEpoch(uint64_t year, uint64_t month, uint64_t day, uint64_t hour, uint64_t minute, uint64_t second) {
511 static constexpr uint64_t secondsInJan{ 31ULL * 24ULL * 60ULL * 60ULL };
512 static constexpr uint64_t secondsInFeb{ 28 * 24ULL * 60ULL * 60ULL };
513 static constexpr uint64_t secondsInMar{ 31ULL * 24ULL * 60ULL * 60ULL };
514 static constexpr uint64_t secondsInApr{ 30ULL * 24ULL * 60ULL * 60ULL };
515 static constexpr uint64_t secondsInMay{ 31ULL * 24ULL * 60ULL * 60ULL };
516 static constexpr uint64_t secondsInJun{ 30ULL * 24ULL * 60ULL * 60ULL };
517 static constexpr uint64_t secondsInJul{ 31ULL * 24ULL * 60ULL * 60ULL };
518 static constexpr uint64_t secondsInAug{ 31ULL * 24ULL * 60ULL * 60ULL };
519 static constexpr uint64_t secondsInSep{ 30ULL * 24ULL * 60ULL * 60ULL };
520 static constexpr uint64_t secondsInOct{ 31ULL * 24ULL * 60ULL * 60ULL };
521 static constexpr uint64_t secondsInNov{ 30ULL * 24ULL * 60ULL * 60ULL };
522 static constexpr uint64_t secondsInDec{ 31ULL * 24ULL * 60ULL * 60ULL };
523 static constexpr uint64_t secondsPerMinute{ 60ULL };
524 static constexpr uint64_t secondsPerHour{ 60ULL * 60ULL };
525 static constexpr uint64_t secondsPerDay{ 60ULL * 60ULL * 24ULL };
527 for (uint64_t x = 1970ULL; x < year; ++x) {
528 value += seconds{ secondsInJan };
529 value += seconds{ secondsInFeb };
530 value += seconds{ secondsInMar };
531 value += seconds{ secondsInApr };
532 value += seconds{ secondsInMay };
533 value += seconds{ secondsInJun };
534 value += seconds{ secondsInJul };
535 value += seconds{ secondsInAug };
536 value += seconds{ secondsInSep };
537 value += seconds{ secondsInOct };
538 value += seconds{ secondsInNov };
539 value += seconds{ secondsInDec };
540 if (x % 4ULL == 0ULL) {
541 value += seconds{ secondsPerDay };
545 value += seconds{
static_cast<uint64_t
>((day - 1ULL) * secondsPerDay) };
546 value += seconds{
static_cast<uint64_t
>(hour * secondsPerHour) };
547 value += seconds{
static_cast<uint64_t
>(minute * secondsPerMinute) };
548 value += seconds{ second };
551 value += seconds{ secondsInJan };
554 value += seconds{ secondsInFeb };
557 value += seconds{ secondsInMar };
560 value += seconds{ secondsInApr };
563 value += seconds{ secondsInMay };
566 value += seconds{ secondsInJun };
569 value += seconds{ secondsInJul };
572 value += seconds{ secondsInAug };
575 value += seconds{ secondsInSep };
578 value += seconds{ secondsInOct };
581 value += seconds{ secondsInNov };
583 return static_cast<uint64_t
>(std::chrono::duration_cast<milliseconds>(value).count());
591 if (originalTimeStamp !=
"" && originalTimeStamp.size() >= 19) {
593 getTimeSinceEpoch(jsonifier::strToUint64(originalTimeStamp.substr(0ULL, 4ULL).data()), jsonifier::strToUint64(originalTimeStamp.substr(5ULL, 6ULL).data()),
594 jsonifier::strToUint64(originalTimeStamp.substr(8ULL, 9ULL).data()), jsonifier::strToUint64(originalTimeStamp.substr(11ULL, 12ULL).data()),
595 jsonifier::strToUint64(originalTimeStamp.substr(14ULL, 15ULL).data()), jsonifier::strToUint64(originalTimeStamp.substr(17ULL, 18ULL).data()));
598 return static_cast<uint64_t
>(std::chrono::duration_cast<milliseconds>(sys_clock::now().time_since_epoch()).count());
655 inline operator uint64_t()
const {
661 inline operator jsonifier::string()
const {
676 inline static value_type toEntity(
snowflake initialId);
688 template<
typename value_type>
inline value_type
toEntity() {
704 if (other.size() > 0) {
705 for (
auto& value: other) {
706 if (!std::isdigit(
static_cast<uint8_t
>(value))) {
710 id = jsonifier::strToUint64(other.data());
737 inline explicit operator jsonifier::string()
const {
738 return jsonifier::toString(
id);
743 inline explicit operator const uint64_t&()
const {
747 inline bool operator==(
const snowflake& other)
const {
748 return id == other.
id;
751 inline bool operator==(jsonifier::string_view other)
const {
752 return operator jsonifier::string() == other;
755 inline bool operator==(uint64_t other)
const {
763 template<jsonifier::concepts::
string_t value_type>
inline jsonifier::string
operator+(jsonifier::string_view rhs)
const {
764 jsonifier::string newString{
operator jsonifier::string() };
774 jsonifier::string lhsNew{
static_cast<jsonifier::string
>(lhs) };
785 template<jsonifier::concepts::
string_t value_type01,
typename value_type02>
friend inline jsonifier::string
operator+(
const value_type01& lhs,
const value_type02& rhs) {
786 jsonifier::string newString{ lhs };
787 newString += rhs.operator jsonifier::string();
797 template<u
int64_t size>
friend inline jsonifier::string
operator+(
const char (&lhs)[size],
const snowflake& rhs) {
798 jsonifier::string newString{ lhs };
799 newString += rhs.operator jsonifier::string();
806 uint64_t timeStamp{
static_cast<uint64_t
>((
id >> 22) + 1420070400000) };
814 inline std::ostream& operator<<(std::ostream& os, snowflake sf) {
815 os << sf.operator jsonifier::string();
824 inline dca_exception(jsonifier::string_view error, std::source_location location = std::source_location::current())
825 : std::runtime_error(std::string{
"thrown from: " + jsonifier::string{ location.file_name() } + jsonifier::string{
" (" } + jsonifier::toString(location.line()) +
":" +
826 jsonifier::toString(location.column()) +
")\n" + error }){};
Class for printing different types of messages to output and error streams.
static std::atomic_bool doWePrintGeneralErrors
Flag to control printing of general error messages.
static std::ostream * outputStream
Pointer to the output stream for message printing.
static std::atomic_bool doWePrintWebSocketSuccesses
Flag to control printing of websocket success messages.
static void printError(const string_type &what, std::source_location where=std::source_location::current())
Print an error message of the specified type.
static std::atomic_bool doWePrintHttpsErrors
Flag to control printing of https error messages.
static std::atomic_bool doWePrintGeneralSuccesses
Flag to control printing of general success messages.
static std::atomic_bool doWePrintWebSocketErrors
Flag to control printing of websocket error messages.
static std::ostream * errorStream
Pointer to the error stream for message printing.
static void printSuccess(const string_type &what, std::source_location where=std::source_location::current())
Print a success message of the specified type.
static void initialize(const value_type &other)
Initialize the message_printer with configuration settings and output/error streams.
static std::atomic_bool doWePrintHttpsSuccesses
Flag to control printing of https success messages.
static std::mutex accessMutex
Mutex for thread-safe access to shared resources.
A class representing a snowflake identifier with various operations.
snowflake(uint64_t other)
Constructor to create a snowflake instance from a uint64_t value.
jsonifier::string getCreatedAtTimeStamp()
Converts the snowflake id into a time and date stamp.
friend jsonifier::string operator+(const value_type01 &lhs, const value_type02 &rhs)
Friend function to concatenate two values.
snowflake & operator=(const jsonifier::string &other)
Assignment operator to assign a string value to snowflake.
value_type toEntity(snowflake additionalId)
A class for converting snowflake id's into the data structures they represent.
jsonifier::string operator+(jsonifier::string_view rhs) const
Concatenation operator to concatenate snowflake and a string value.
snowflake & operator=(uint64_t other)
Assignment operator to assign a uint64_t value to snowflake.
uint64_t id
The snowflake id.
friend jsonifier::string operator+(const snowflake &lhs, jsonifier::string_view other)
Friend function to concatenate snowflake and a string value.
snowflake()=default
Default constructor for snowflake.
friend jsonifier::string operator+(const char(&lhs)[size], const snowflake &rhs)
Friend function to concatenate two values.
snowflake(const jsonifier::string &other)
Constructor to create a snowflake instance from a string value.
value_type toEntity()
A class for converting snowflake id's into the data structures they represent.
A base class for handling time stamps and conversions.
bool operator==(jsonifier::string_view other) const
Checks if the time stamp is equal to a string representation.
static uint64_t getTimeSinceEpoch(uint64_t year, uint64_t month, uint64_t day, uint64_t hour, uint64_t minute, uint64_t second)
Gets the time since the unix epoch for the specified date and time.
static jsonifier::string convertToCurrentISO8601TimeStamp(time_format timeFormat)
Converts the current time into an iso8601 time stamp.
static jsonifier::string convertMsToDurationString(uint64_t durationInMs)
Converts milliseconds into a human-readable duration string.
uint64_t convertStringToUintTimeStamp(jsonifier::string_view stringTimeStamp) const
Converts a string time stamp into a uint64_t time value.
bool hasTimeElapsed(int64_t days, int64_t hours, int64_t minutes) const
Checks if a certain time duration has elapsed.
static uint64_t convertTimeStampToTimeUnits(jsonifier::string_view originalTimeStamp)
Converts a string time stamp into a uint64_t time value.
static jsonifier::string getISO8601TimeStamp(time_format timeFormat, uint64_t inputTime)
Gets an iso8601 time stamp string based on the provided time format.
jsonifier::string convertUintToStringTimeStamp(uint64_t uintTimeStamp) const
Converts a uint64_t time value into a string time stamp.
static jsonifier::string convertToFutureISO8601TimeStamp(uint64_t minutesToAdd, uint64_t hoursToAdd, uint64_t daysToAdd, uint64_t monthsToAdd, uint64_t yearsToAdd, time_format timeFormat)
Converts given time values into a future iso8601 time stamp.
A class that extends time_stamp_base to provide additional functionality.
time_stamp & operator=(jsonifier::string_view valueNew)
Move assignment operator to move a string value into time_stamp.
time_stamp()=default
Default constructor for time_stamp.
time_stamp(jsonifier::string_view valueNew)
Move constructor to create a time_stamp instance by moving a string value.
uint64_t value
The value stored in the time_stamp instance.
time_stamp & operator=(uint64_t valueNew)
Assignment operator to assign a uint64_t value to time_stamp.
time_stamp(uint64_t valueNew)
Constructor to create a time_stamp instance from a uint64_t value.
A class for converting snowflake id's into the data structures they represent.
time_format
Time formatting methods.
@ short_date_time
"20 April 2021 16:20" - Short Date/Time
@ short_time
"16:20" - Short Time
@ short_date
"20/04/2021" - Short Date
@ long_time
"16:20:30" - Long Time
@ long_date
"20 April 2021" - Long Date
@ long_date_time
"Tuesday, 20 April 2021 16:20" - Long Date/Time
stream_type
For selecting the type of streamer that the given bot is, one must be one server and one of client pe...
The main namespace for the forward-facing interfaces.
An exception class derived from std::runtime_error for dca-related exceptions.
dca_exception(jsonifier::string_view error, std::source_location location=std::source_location::current())
Constructor to create a dca_exception with an error message and optional source location.