Skip to content

Commit

Permalink
Merge pull request #89 from brainboxdotcc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Commandserver authored Jul 17, 2023
2 parents b6fac8f + 7433586 commit 8a8d98e
Show file tree
Hide file tree
Showing 38 changed files with 7,367 additions and 362 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TODO: Discuss about -readability-identifier-length, -readability-avoid-const-params-in-decls
Checks: "-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,llvm-namespace-comment,modernize-*,performance-*,portability-*,readability-*,-bugprone-implicit-widening-of-multiplication-result, -bugprone-easily-swappable-parameters,-readability-identifier-length,-portability-restrict-system-includes,-modernize-use-trailing-return-type,-cppcoreguidelines-non-private-member-variables-in-classes,-readability-avoid-const-params-in-decls"
30 changes: 29 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,35 @@
"CORO",
"cback",
"mentionables",
"awaiter",
"checkered",
"ramen",
"dango",
"tanabata",
"diya",
"nazar",
"hamsa",
"tada",
"izakaya",
"rofl",
"thumbup",
"mwgb",
"mwbb",
"wwgb",
"mwgg",
"wwbb",
"wwgg",
"mmgb",
"mmgg",
"womans",
"mans",
"mens",
"womens",
"mmbb",
"fleur",
"koko",
"moyai",
"kaaba",
"stringified"
],
"flagWords": [
Expand All @@ -104,4 +133,3 @@
"allowCompoundWords": true,
"useCompounds": true
}

4 changes: 2 additions & 2 deletions buildtools/classes/Generator/CoroGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function checkForChanges(): bool
/**
* @inheritDoc
*/
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterTypes, string $parameterNames): string
{
$parameterNames = preg_replace('/^, /', '', $parameterNames);
if (!empty($parameterNames)) {
Expand All @@ -98,7 +98,7 @@ public function generateHeaderDef(string $returnType, string $currentFunction, s
/**
* @inheritDoc
*/
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterTypes, string $parameterNames): string
{
return '';
}
Expand Down
6 changes: 3 additions & 3 deletions buildtools/classes/Generator/SyncGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ public function checkForChanges(): bool
/**
* @inheritDoc
*/
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterTypes, string $parameterNames): string
{
return "$returnType {$currentFunction}_sync($parameters);\n\n";
}

/**
* @inheritDoc
*/
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterTypes, string $parameterNames): string
{
return "$returnType cluster::{$currentFunction}_sync($noDefaults) {\n\treturn dpp::sync<$returnType>(this, &cluster::$currentFunction$parameterNames);\n}\n\n";
return "$returnType cluster::{$currentFunction}_sync($noDefaults) {\n\treturn dpp::sync<$returnType>(this, static_cast<void (cluster::*)($parameterTypes". (!empty($parameterTypes) ? ", " : "") . "command_completion_event_t)>(&cluster::$currentFunction)$parameterNames);\n}\n\n";
}

/**
Expand Down
4 changes: 2 additions & 2 deletions buildtools/classes/StructGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function checkForchanges(): bool;
* @param string $parameterNames Parameter names only
* @return string header content to append
*/
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string;
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterTypes, string $parameterNames): string;

/**
* Generate cpp definition for a function
Expand All @@ -50,7 +50,7 @@ public function generateHeaderDef(string $returnType, string $currentFunction, s
* @param string $parameterNames Parameter names only
* @return string cpp content to append
*/
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string;
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterTypes, string $parameterNames): string;

/**
* Return comment lines to add to each header definition
Expand Down
18 changes: 18 additions & 0 deletions buildtools/emojis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

echo "-- Autogenrating include/dpp/unicode_emoji.h\n";

$header = "#pragma once\n\nnamespace dpp { namespace unicode_emoji {\n";

/* This JSON is generated originally via the NPM package maintained by Discord themselves at https://www.npmjs.com/package/discord-emoji */
$emojis = json_decode(file_get_contents("https://raw.githubusercontent.com/ArkinSolomon/discord-emoji-converter/master/emojis.json"));
if ($emojis) {
foreach ($emojis as $name=>$code) {
if (preg_match("/^\d+/", $name)) {
$name = "_" . $name;
}
$header .= " constexpr const char[] " .$name . " = \"$code\";\n";
}
$header .= "}\n};\n";
file_put_contents("include/dpp/unicode_emoji.h", $header);
}
32 changes: 18 additions & 14 deletions buildtools/make_struct.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@

/* These methods have signatures incompatible with this script */
$blacklist = [
'channel_edit_permissions',
'message_add_reaction',
'message_delete_reaction',
'message_delete_reaction_emoji',
'message_delete_all_reactions',
'message_delete_own_reaction',
'message_get_reactions',
'channel_typing',
'application_role_connection_get', // TODO: rest_request_vector
'application_role_connection_update',
];

/* The script cannot determine the correct return type of these methods,
Expand All @@ -41,9 +31,19 @@
'guild_search_members' => 'guild_member_map',
'message_create' => 'message',
'message_edit' => 'message',
'message_add_reaction' => 'confirmation',
'message_delete_reaction' => 'confirmation',
'message_delete_reaction_emoji' => 'confirmation',
'message_delete_all_reactions' => 'confirmation',
'message_delete_own_reaction' => 'confirmation',
'channel_edit_permissions' => 'confirmation',
'channel_typing' => 'confirmation',
'message_get_reactions' => 'emoji_map',
'thread_create_in_forum' => 'thread',
'threads_get_active' => 'active_threads',
'user_get_cached' => 'user_identified',
'application_role_connection_get' => 'application_role_connection',
'application_role_connection_update' => 'application_role_connection'
];

/* Get the contents of cluster.h into an array */
Expand Down Expand Up @@ -101,22 +101,26 @@
if (!in_array($currentFunction, $blacklist)) {
$parameterList = explode(',', $parameters);
$parameterNames = [];
$parameterTypes = [];
foreach ($parameterList as $parameter) {
$parts = explode(' ', trim($parameter));
$parameterNames[] = trim(preg_replace('/[\s\*\&]+/', '', $parts[count($parts) - 1]));
$name = trim(preg_replace('/[\s\*\&]+/', '', $parts[count($parts) - 1]));
$parameterNames[] = $name;
$parameterTypes[] = trim(substr($parameter, 0, strlen($parameter) - strlen($name)));
}
$content .= getComments($generator, $currentFunction, $returnType, $parameterNames) . "\n";
$fullParameters = getFullParameters($currentFunction, $parameterNames);
$parameterNames = trim(join(', ', $parameterNames));
$parameterTypes = trim(join(', ', $parameterTypes));
if (!empty($parameterNames)) {
$parameterNames = ', ' . $parameterNames;
}
$noDefaults = $parameters;
$parameters = !empty($fullParameters) ? $fullParameters : $parameters;
$content .= $generator->generateHeaderDef($returnType, $currentFunction, $parameters, $noDefaults, $parameterNames);
$cppcontent .= $generator->generateCppDef($returnType, $currentFunction, $parameters, $noDefaults, $parameterNames);
$content .= $generator->generateHeaderDef($returnType, $currentFunction, $parameters, $noDefaults, $parameterTypes, $parameterNames);
$cppcontent .= $generator->generateCppDef($returnType, $currentFunction, $parameters, $noDefaults, $parameterTypes, $parameterNames);
}
$lastFunc = $currentFunction;
$lastFunc = $currentFunction;
$currentFunction = $parameters = $returnType = '';
$state = STATE_SEARCH_FOR_FUNCTION;
}
Expand Down
2 changes: 1 addition & 1 deletion include/dpp/appcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ struct DPP_EXPORT interaction_modal_response : public interaction_response, publ
std::string custom_id;

/**
* @brief Title of the modal form box
* @brief Title of the modal form box (max 25 characters)
*/
std::string title;

Expand Down
4 changes: 4 additions & 0 deletions include/dpp/auditlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ enum audit_type {
aut_automod_flag_to_channel = 144,
/// Member was timed out by Auto Moderation
aut_automod_user_communication_disabled = 145,
/// Creator monetization request was created
aut_creator_monetization_request_created = 150,
/// Creator monetization terms were accepted
aut_creator_monetization_terms_accepted = 151,
};

/**
Expand Down
24 changes: 18 additions & 6 deletions include/dpp/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ struct DPP_EXPORT forum_tag : public managed {
};

/**
* @brief A group of thread member objects. the key is the thread_id of the dpp::thread_member
* @brief A group of thread member objects. the key is the user_id of the dpp::thread_member
*/
typedef std::unordered_map<snowflake, thread_member> thread_member_map;

Expand Down Expand Up @@ -835,12 +835,24 @@ typedef std::unordered_map<snowflake, channel> channel_map;
typedef std::unordered_map<snowflake, thread> thread_map;

/**
* @brief A group of threads and thread_members. returned from the cluster::threads_get_active method
* @brief A thread alongside the bot's optional thread_member object tied to it
*/
typedef struct {
thread_map threads;
thread_member_map thread_members;
} active_threads;
struct active_thread_info {
/**
* @brief The thread object
*/
thread active_thread;

/**
* @brief The bot as a thread member, only present if the bot is in the thread
*/
std::optional<thread_member> bot_member;
};

/**
* @brief A map of threads alongside optionally the thread_member tied to the bot if it is in the thread. The map's key is the thread id. Returned from the cluster::threads_get_active method
*/
using active_threads = std::map<snowflake, active_thread_info>;

};

32 changes: 32 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,16 @@ class DPP_EXPORT cluster {
*/
void interaction_response_edit(const std::string &token, const message &m, command_completion_event_t callback = utility::log_error());

/**
* @brief Get the original response to a slash command
*
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response
* @param token Token for the interaction webhook
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::message object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void interaction_response_get_original(const std::string &token, command_completion_event_t callback = utility::log_error());

/**
* @brief Create a followup message to a slash command
*
Expand Down Expand Up @@ -1344,6 +1354,17 @@ class DPP_EXPORT cluster {
* On success the callback will contain a dpp::message object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void interaction_followup_get(const std::string &token, snowflake message_id, command_completion_event_t callback);

/**
* @brief Get the original followup message to a slash command
* This is an alias for cluster::interaction_response_get_original
* @see cluster::interaction_response_get_original
*
* @param token Token for the interaction webhook
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::message object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void interaction_followup_get_original(const std::string &token, command_completion_event_t callback = utility::log_error());

/**
* @brief Create a global slash command (a bot can have a maximum of 100 of these).
Expand Down Expand Up @@ -3027,6 +3048,17 @@ class DPP_EXPORT cluster {
*/
void thread_create(const std::string& thread_name, snowflake channel_id, uint16_t auto_archive_duration, channel_type thread_type, bool invitable, uint16_t rate_limit_per_user, command_completion_event_t callback = utility::log_error());

/**
* @brief Edit a thread
* @note This method supports audit log reasons set by the cluster::set_audit_reason() method.
*
* @see https://discord.com/developers/docs/topics/threads#editing-deleting-threads
* @param t Thread to edit
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::thread object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void thread_edit(const thread &t, command_completion_event_t callback = utility::log_error());

/**
* @brief Create a thread with a message (Discord: ID of a thread is same as message ID)
* @note This method supports audit log reasons set by the cluster::set_audit_reason() method.
Expand Down
Loading

0 comments on commit 8a8d98e

Please sign in to comment.