Skip to content

Commit 2db8adb

Browse files
committed
Update to dpp 10.0.35
1 parent 71ac595 commit 2db8adb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+26229
-5292
lines changed

3rdParty/dpp/appcommand.h

Lines changed: 665 additions & 219 deletions
Large diffs are not rendered by default.

3rdParty/dpp/application.h

Lines changed: 389 additions & 61 deletions
Large diffs are not rendered by default.

3rdParty/dpp/auditlog.h

Lines changed: 412 additions & 145 deletions
Large diffs are not rendered by default.

3rdParty/dpp/automod.h

Lines changed: 140 additions & 100 deletions
Large diffs are not rendered by default.

3rdParty/dpp/ban.h

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*
33
* D++, A Lightweight C++ library for Discord
44
*
5+
* SPDX-License-Identifier: Apache-2.0
56
* Copyright 2021 Craig Edwards and D++ contributors
67
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
78
*
@@ -22,7 +23,7 @@
2223
#pragma once
2324
#include <dpp/export.h>
2425
#include <dpp/snowflake.h>
25-
#include <dpp/nlohmann/json_fwd.hpp>
26+
#include <dpp/json_fwd.h>
2627
#include <dpp/json_interface.h>
2728
#include <unordered_map>
2829

@@ -33,35 +34,36 @@ namespace dpp {
3334
*
3435
*/
3536
class DPP_EXPORT ban : public json_interface<ban> {
36-
public:
37-
/** The ban reason */
38-
std::string reason;
39-
/** User ID the ban applies to */
40-
snowflake user_id;
41-
42-
/** Constructor */
43-
ban();
44-
45-
/** Destructor */
46-
virtual ~ban() = default;
37+
protected:
38+
friend struct json_interface<ban>;
4739

4840
/** Read class values from json object
4941
* @param j A json object to read from
5042
* @return A reference to self
5143
*/
52-
ban& fill_from_json(nlohmann::json* j);
44+
ban& fill_from_json_impl(nlohmann::json* j);
45+
46+
public:
47+
/**
48+
* @brief The ban reason.
49+
*/
50+
std::string reason;
5351

5452
/**
55-
* @brief Build json representation of a ban
56-
* @param with_id Include ID in json
57-
*
58-
* @return std::string stringified json
53+
* @brief User ID the ban applies to.
5954
*/
60-
std::string build_json(bool with_id = false) const;
55+
snowflake user_id;
56+
57+
/** Constructor */
58+
ban();
59+
60+
/** Destructor */
61+
virtual ~ban() = default;
6162
};
6263

63-
/** A group of bans
64+
/**
65+
* @brief A group of bans. The key is the user ID.
6466
*/
6567
typedef std::unordered_map<snowflake, ban> ban_map;
6668

67-
};
69+
}

3rdParty/dpp/bignum.h

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/************************************************************************************
2+
*
3+
* D++, A Lightweight C++ library for Discord
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
* Copyright 2021 Craig Edwards and D++ contributors
7+
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*
21+
************************************************************************************/
22+
23+
#pragma once
24+
#include <dpp/export.h>
25+
#include <dpp/snowflake.h>
26+
#include <memory>
27+
28+
namespace dpp {
29+
30+
/**
31+
* @brief This contains the OpenSSL structs. It is not public,
32+
* so that the public interface doesn't depend on OpenSSL directly.
33+
*/
34+
struct openssl_bignum;
35+
36+
/**
37+
* @brief An arbitrary length integer number.
38+
* Officially, the Discord documentation says that permission values can be any arbitrary
39+
* number of digits. At time of writing there are only 50 bits of permissions, but this is
40+
* set to grow larger and potentially past 64 bits. They will continue to send this data
41+
* as a huge single integer at that point, because this is obviously sensible. /s
42+
*
43+
* @note dpp::bignumber uses OpenSSL BN_* under the hood, as we include openssl anyway
44+
* for HTTPS.
45+
*/
46+
class DPP_EXPORT bignumber {
47+
/**
48+
* @brief Internal opaque struct to contain OpenSSL things
49+
*/
50+
std::shared_ptr<openssl_bignum> ssl_bn{nullptr};
51+
public:
52+
/**
53+
* @brief Construct a new bignumber object
54+
*/
55+
bignumber() = default;
56+
57+
/**
58+
* @brief Parse a std::string of an arbitrary length number into
59+
* a bignumber.
60+
* @param number_string string representation of a number. The
61+
* number must be an integer, and can be positive or negative.
62+
* @note Prefixing number_string with 0x will parse it as hexadecimal.
63+
* This is not case sensitive.
64+
*/
65+
bignumber(const std::string& number_string);
66+
67+
/**
68+
* @brief Build a bignumber from a vector of 64 bit values.
69+
* The values are accepted in "reverse order", so the first vector
70+
* entry at index 0 is the leftmost 64 bits of the bignum.
71+
* The vector can be any arbitrary length.
72+
* @param bits Vector of 64 bit values which represent the number
73+
*/
74+
bignumber(std::vector<uint64_t> bits);
75+
76+
/**
77+
* @brief Default destructor
78+
*/
79+
~bignumber() = default;
80+
81+
/**
82+
* @brief Get the string representation of the bignumber.
83+
* @param hex If false (the default) the number is returned in
84+
* decimal, else if this parameter is true, it will be returned
85+
* as hex (without leading '0x')
86+
* @return String representation of bignumber
87+
*/
88+
[[nodiscard]] std::string get_number(bool hex = false) const;
89+
90+
/**
91+
* @brief Get the array of 64 bit values that represents the
92+
* bignumber. This is what we should use to store bignumbers
93+
* in memory, not this bignumber class itself, as the bignumber
94+
* class instantiates OpenSSL structs and takes significantly
95+
* more ram than just a vector.
96+
* @return Vector of 64 bit values representing the bignumber
97+
*/
98+
[[nodiscard]] std::vector<uint64_t> get_binary() const;
99+
};
100+
101+
}

3rdParty/dpp/cache.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*
33
* D++, A Lightweight C++ library for Discord
44
*
5+
* SPDX-License-Identifier: Apache-2.0
56
* Copyright 2021 Craig Edwards and D++ contributors
67
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
78
*
@@ -64,7 +65,7 @@ template<class T> class cache {
6465
/**
6566
* @brief Construct a new cache object.
6667
*
67-
* Caches must contain classes derived from dpp::managed.
68+
* @note Caches must contain classes derived from dpp::managed.
6869
*/
6970
cache() {
7071
cache_map = new std::unordered_map<snowflake, T*>;
@@ -108,7 +109,7 @@ template<class T> class cache {
108109
} else if (object != existing->second) {
109110
/* Flag old pointer for deletion and replace */
110111
std::lock_guard<std::mutex> delete_lock(deletion_mutex);
111-
deletion_queue[existing->second] = time(NULL);
112+
deletion_queue[existing->second] = time(nullptr);
112113
(*cache_map)[object->id] = object;
113114
}
114115
}
@@ -133,7 +134,7 @@ template<class T> class cache {
133134
auto existing = cache_map->find(object->id);
134135
if (existing != cache_map->end()) {
135136
cache_map->erase(existing);
136-
deletion_queue[object] = time(NULL);
137+
deletion_queue[object] = time(nullptr);
137138
}
138139
}
139140

@@ -249,17 +250,18 @@ template<class T> class cache {
249250
*/
250251
size_t bytes() {
251252
std::shared_lock l(cache_mutex);
252-
return sizeof(this) + (cache_map->bucket_count() * sizeof(size_t));
253+
return sizeof(*this) + (cache_map->bucket_count() * sizeof(size_t));
253254
}
254255

255256
};
256257

257-
/** Run garbage collection across all caches removing deleted items
258+
/**
259+
* Run garbage collection across all caches removing deleted items
258260
* that have been deleted over 60 seconds ago.
259261
*/
260262
void DPP_EXPORT garbage_collection();
261263

262-
#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 ();
264+
#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 ();
263265

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

271-
};
273+
}
272274

0 commit comments

Comments
 (0)