Skip to content

Commit

Permalink
Merge pull request #87 from brainboxdotcc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Commandserver authored Jul 8, 2023
2 parents 6139229 + 88d07da commit 5b7ca81
Show file tree
Hide file tree
Showing 20 changed files with 1,542 additions and 282 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/39b054c38bba411d9b25b39524016c9e)](https://www.codacy.com/gh/brainboxdotcc/DPP/dashboard?utm_source=github.com&utm_medium=referral&utm_content=brainboxdotcc/DPP&utm_campaign=Badge_Grade)
![Lines of code](https://img.shields.io/tokei/lines/github/brainboxdotcc/DPP)
[![D++ CI](https://github.com/brainboxdotcc/DPP/actions/workflows/ci.yml/badge.svg)](https://github.com/brainboxdotcc/DPP/actions/workflows/ci.yml)
[![AUR version](https://img.shields.io/aur/version/dpp)](https://aur.archlinux.org/packages/dpp) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![AUR version](https://img.shields.io/aur/version/dpp)](https://aur.archlinux.org/packages/dpp)
![vcpkg version](https://img.shields.io/vcpkg/v/dpp)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)

</div>

Expand Down Expand Up @@ -88,6 +90,20 @@ For running your bot on a **Raspberry Pi**, we offer a prebuilt .deb package for
### Other OS
The library should work fine on other operating systems as well, and if you run a D++ bot on something not listed here, please let us know!

## Getting Started

### Installation

D++ can be easily installed using various package managers. Please refer [to our documentation](https://dpp.dev/md_docpages_01_installing.html) for installation tutorials based on your preferred package manager.

### Building from Source

If you prefer to build the library from source, detailed instructions are available [here](https://dpp.dev/install-from-source.html).

### FAQ

For frequently asked questions and their answers, please visit our [FAQ page](https://dpp.dev/md_docpages_01_frequently_asked_questions.html).

## 🤝 Contributing

Contributions, issues and feature requests are welcome. After cloning and setting up project locally, you can just submit
Expand Down
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
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
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>;

};

11 changes: 11 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3027,6 +3027,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 5b7ca81

Please sign in to comment.