Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
884 changes: 665 additions & 219 deletions 3rdParty/dpp/appcommand.h

Large diffs are not rendered by default.

450 changes: 389 additions & 61 deletions 3rdParty/dpp/application.h

Large diffs are not rendered by default.

557 changes: 412 additions & 145 deletions 3rdParty/dpp/auditlog.h

Large diffs are not rendered by default.

240 changes: 140 additions & 100 deletions 3rdParty/dpp/automod.h

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions 3rdParty/dpp/ban.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* D++, A Lightweight C++ library for Discord
*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
Expand All @@ -22,7 +23,7 @@
#pragma once
#include <dpp/export.h>
#include <dpp/snowflake.h>
#include <dpp/nlohmann/json_fwd.hpp>
#include <dpp/json_fwd.h>
#include <dpp/json_interface.h>
#include <unordered_map>

Expand All @@ -33,35 +34,36 @@ namespace dpp {
*
*/
class DPP_EXPORT ban : public json_interface<ban> {
public:
/** The ban reason */
std::string reason;
/** User ID the ban applies to */
snowflake user_id;

/** Constructor */
ban();

/** Destructor */
virtual ~ban() = default;
protected:
friend struct json_interface<ban>;

/** Read class values from json object
* @param j A json object to read from
* @return A reference to self
*/
ban& fill_from_json(nlohmann::json* j);
ban& fill_from_json_impl(nlohmann::json* j);

public:
/**
* @brief The ban reason.
*/
std::string reason;

/**
* @brief Build json representation of a ban
* @param with_id Include ID in json
*
* @return std::string stringified json
* @brief User ID the ban applies to.
*/
std::string build_json(bool with_id = false) const;
snowflake user_id;

/** Constructor */
ban();

/** Destructor */
virtual ~ban() = default;
};

/** A group of bans
/**
* @brief A group of bans. The key is the user ID.
*/
typedef std::unordered_map<snowflake, ban> ban_map;

};
}
101 changes: 101 additions & 0 deletions 3rdParty/dpp/bignum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/

#pragma once
#include <dpp/export.h>
#include <dpp/snowflake.h>
#include <memory>

namespace dpp {

/**
* @brief This contains the OpenSSL structs. It is not public,
* so that the public interface doesn't depend on OpenSSL directly.
*/
struct openssl_bignum;

/**
* @brief An arbitrary length integer number.
* Officially, the Discord documentation says that permission values can be any arbitrary
* number of digits. At time of writing there are only 50 bits of permissions, but this is
* set to grow larger and potentially past 64 bits. They will continue to send this data
* as a huge single integer at that point, because this is obviously sensible. /s
*
* @note dpp::bignumber uses OpenSSL BN_* under the hood, as we include openssl anyway
* for HTTPS.
*/
class DPP_EXPORT bignumber {
/**
* @brief Internal opaque struct to contain OpenSSL things
*/
std::shared_ptr<openssl_bignum> ssl_bn{nullptr};
public:
/**
* @brief Construct a new bignumber object
*/
bignumber() = default;

/**
* @brief Parse a std::string of an arbitrary length number into
* a bignumber.
* @param number_string string representation of a number. The
* number must be an integer, and can be positive or negative.
* @note Prefixing number_string with 0x will parse it as hexadecimal.
* This is not case sensitive.
*/
bignumber(const std::string& number_string);

/**
* @brief Build a bignumber from a vector of 64 bit values.
* The values are accepted in "reverse order", so the first vector
* entry at index 0 is the leftmost 64 bits of the bignum.
* The vector can be any arbitrary length.
* @param bits Vector of 64 bit values which represent the number
*/
bignumber(std::vector<uint64_t> bits);

/**
* @brief Default destructor
*/
~bignumber() = default;

/**
* @brief Get the string representation of the bignumber.
* @param hex If false (the default) the number is returned in
* decimal, else if this parameter is true, it will be returned
* as hex (without leading '0x')
* @return String representation of bignumber
*/
[[nodiscard]] std::string get_number(bool hex = false) const;

/**
* @brief Get the array of 64 bit values that represents the
* bignumber. This is what we should use to store bignumbers
* in memory, not this bignumber class itself, as the bignumber
* class instantiates OpenSSL structs and takes significantly
* more ram than just a vector.
* @return Vector of 64 bit values representing the bignumber
*/
[[nodiscard]] std::vector<uint64_t> get_binary() const;
};

}
16 changes: 9 additions & 7 deletions 3rdParty/dpp/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* D++, A Lightweight C++ library for Discord
*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
Expand Down Expand Up @@ -64,7 +65,7 @@ template<class T> class cache {
/**
* @brief Construct a new cache object.
*
* Caches must contain classes derived from dpp::managed.
* @note Caches must contain classes derived from dpp::managed.
*/
cache() {
cache_map = new std::unordered_map<snowflake, T*>;
Expand Down Expand Up @@ -108,7 +109,7 @@ template<class T> class cache {
} else if (object != existing->second) {
/* Flag old pointer for deletion and replace */
std::lock_guard<std::mutex> delete_lock(deletion_mutex);
deletion_queue[existing->second] = time(NULL);
deletion_queue[existing->second] = time(nullptr);
(*cache_map)[object->id] = object;
}
}
Expand All @@ -133,7 +134,7 @@ template<class T> class cache {
auto existing = cache_map->find(object->id);
if (existing != cache_map->end()) {
cache_map->erase(existing);
deletion_queue[object] = time(NULL);
deletion_queue[object] = time(nullptr);
}
}

Expand Down Expand Up @@ -249,17 +250,18 @@ template<class T> class cache {
*/
size_t bytes() {
std::shared_lock l(cache_mutex);
return sizeof(this) + (cache_map->bucket_count() * sizeof(size_t));
return sizeof(*this) + (cache_map->bucket_count() * sizeof(size_t));
}

};

/** Run garbage collection across all caches removing deleted items
/**
* Run garbage collection across all caches removing deleted items
* that have been deleted over 60 seconds ago.
*/
void DPP_EXPORT garbage_collection();

#define cache_decl(type, setter, getter, counter) DPP_EXPORT class type * setter (snowflake id); DPP_EXPORT cache<class type> * getter (); DPP_EXPORT uint64_t counter ();
#define cache_decl(type, setter, getter, counter) /** Find an object in the cache by id. @return type* Pointer to the object or nullptr when it's not found */ DPP_EXPORT class type * setter (snowflake id); DPP_EXPORT cache<class type> * getter (); /** Get the amount of cached type objects. */ DPP_EXPORT uint64_t counter ();

/* Declare major caches */
cache_decl(user, find_user, get_user_cache, get_user_count);
Expand All @@ -268,5 +270,5 @@ cache_decl(role, find_role, get_role_cache, get_role_count);
cache_decl(channel, find_channel, get_channel_cache, get_channel_count);
cache_decl(emoji, find_emoji, get_emoji_cache, get_emoji_count);

};
}

Loading