Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix, test: multiheader-cookie test, now queries a domain and url in our control which returns 3 hard coded test cookies #967

Closed
wants to merge 10 commits into from
75 changes: 11 additions & 64 deletions docpages/advanced_reference/coding_style_standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,20 @@ This covers your standard Curly Braces (commonly known as squiggly brackets), an

Curly Braces should be on the same line as the keyword, for example:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cpp
void foo() {
if (a == b) {
c();
} else {
d();
}

while (true) {
// ...
}

switch (a) {
case 1:
c();
break;
case 2:
d();
break;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\include{cpp} coding_style_standards/curly_braces.cpp

This applies to functions, `while` statements, `if` statements, lambdas, nearly anything that uses curly braces with statements!

### Lists

Lists should have a space after the comma in parameter lists, and after opening brackets and before closing brackets except when calling a function, for example:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cpp
std::vector<std::string> clowns = { "pennywise", "bobo" };

evaluate_clown(clowns[0], evilness(2.5, factor));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\include{cpp} coding_style_standards/lists.cpp

## Dot (.) Notation
When using the dot notation repeatedly (For example, creating an embed.), you should start each `.function()` on a new line, as such:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cpp
stuff{}
.add_stuff()
.add_stuff();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\include{cpp} coding_style_standards/dot_notation.cpp

## Indentation

Expand All @@ -72,7 +43,11 @@ Constants and macros should be all `UPPERCASE` with `SNAKE_CASE` to separate wor

## Comments

All comments should be in `doxygen` format (similar to javadoc). Please see existing class definitions for an example. You should use doxygen style comments in a class definition inside a header file, and can use any other comment types within the .cpp file. Be liberal with comments, especially if your code makes any assumptions!
All comments should be in `doxygen` format (similar to javadoc). Please see existing class definitions for an example. You should use doxygen style comments in a class definition inside a header file. Be liberal with comments, especially if your code makes any assumptions! Comments should follow the format below:

\note Comments that contain doxygen stuff need to use two stars at the beginning (/**). This example doesn't because doxygen gets confused and doesn't show the comments.

\include{cpp} coding_style_standards/comments.cpp

## Spell Checks

Expand All @@ -82,13 +57,7 @@ To prevent typos, a GitHub-Action checks the documentation. If it fails for a wo

If you export a class which is to be accessible to users, be sure to prefix it with the `DPP_EXPORT` macro, for example:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cpp
class DPP_EXPORT my_new_class {
public:
int hats;
int clowns;
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\include{cpp} coding_style_standards/symbol_exporting.cpp

The `DPP_EXPORT` macro ensures that on certain platforms (notably Windows) the symbol is exported to be available to the library user.

Expand Down Expand Up @@ -132,33 +101,11 @@ If a value will only hold values up to 255, use `uint8_t`. If a value cannot hol

Where possible, if you are adding methods to a class you should consider fluent design. Fluent design is the use of class methods that return a reference to self (via `return *this`), so that you can chain object method calls together (in the way dpp::message and dpp::embed do). For example:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cpp
class DPP_EXPORT my_new_class {
public:
int hats;
int clowns;

my_new_class& set_hats(int new_hats);
my_new_class& set_clowns(int new_clowns);
};

my_new_class& my_new_class::set_hats(int new_hats) {
hats = new_hats;
return *this;
}

my_new_class& my_new_class::set_clowns(int new_clowns) {
clowns = new_clowns;
return *this;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\include{cpp} coding_style_standards/fluent_design.cpp

This would allow the user to do this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cpp
dpp::my_new_class nc;
nc.set_hats(3).set_clowns(9001);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\include{cpp} coding_style_standards/fluent_design2.cpp

## Keep All D++ Related Types in the dpp Namespace

Expand Down
27 changes: 27 additions & 0 deletions docpages/example_code/coding_style_standards/comments.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* @brief This is a function that does some cool stuff.
* More stuff here will still go in brief!
* @warning This does nothing!
*/
func_name();

/*
* @brief This turns a name into a meme name!
*
* @param name The name of the user that you want to meme-ify.
* @return a meme name!
*/
std::string name_to_meme(const std::string& name) const;

/* -------------------- .cpp file -------------------- */

int main() {
/* We are now going to do some cool stuff. */
func_name();

/* Going to turn brain into a meme name.
* Why?
* Because why not. That's why.
*/
std::cout << name_to_meme("Brain") << "\n";
}
20 changes: 20 additions & 0 deletions docpages/example_code/coding_style_standards/curly_braces.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
void foo() {
if (a == b) {
c();
} else {
d();
}

while (true) {
// ...
}

switch (a) {
case 1:
c();
break;
case 2:
d();
break;
}
}
5 changes: 5 additions & 0 deletions docpages/example_code/coding_style_standards/dot_notation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stuff{}
.add_stuff()
.add_stuff();

event.reply("This reply function isn't indented!");
18 changes: 18 additions & 0 deletions docpages/example_code/coding_style_standards/fluent_design.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class DPP_EXPORT my_new_class {
public:
int hats;
int clowns;

my_new_class& set_hats(int new_hats);
my_new_class& set_clowns(int new_clowns);
};

my_new_class& my_new_class::set_hats(int new_hats) {
hats = new_hats;
return *this;
}

my_new_class& my_new_class::set_clowns(int new_clowns) {
clowns = new_clowns;
return *this;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dpp::my_new_class nc;
nc.set_hats(3).set_clowns(9001);
3 changes: 3 additions & 0 deletions docpages/example_code/coding_style_standards/lists.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
std::vector<std::string> clowns = { "pennywise", "bobo" };

evaluate_clown(clowns[0], evilness(2.5, factor));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DPP_EXPORT my_new_class {
public:
int hats;
int clowns;
};
2 changes: 2 additions & 0 deletions docpages/example_programs/misc/setting_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

A bot status is pretty cool, and it'd be cooler if you knew how to do it! This tutorial will cover how to set the bot status to say `Playing games!`, as well as covering how to set the status to the amount of guilds every two minutes.

\note dpp::get_guild_cache requires the bot to have the guild cache enabled, if your bot has this disabled then you can't use that. Instead, you should look to use dpp::cluster::current_application_get and get the `approximate_guild_count` from dpp::application in the callback.

First, we'll cover setting the bot status to `Playing games!`.

\include{cpp} setting_status1.cpp
Expand Down
12 changes: 2 additions & 10 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2263,16 +2263,8 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_guild_get_voice_regions(snowflake guild_id);

/**
* @brief Create a webhook
* @note This method supports audit log reasons set by the cluster::set_audit_reason() method.
* @see dpp::cluster::create_webhook
* @see https://discord.com/developers/docs/resources/webhook#create-webhook
* @param w Webhook to create
* @return webhook returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_create_webhook(const class webhook &w);

[[nodiscard]] async<confirmation_callback_t> co_create_webhook(const class webhook &wh);

/**
* @brief Delete a webhook
Expand Down
15 changes: 2 additions & 13 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2782,19 +2782,8 @@ voiceregion_map get_voice_regions_sync();
*/
voiceregion_map guild_get_voice_regions_sync(snowflake guild_id);

/**
* @brief Create a webhook
* @note This method supports audit log reasons set by the cluster::set_audit_reason() method.
* @see dpp::cluster::create_webhook
* @see https://discord.com/developers/docs/resources/webhook#create-webhook
* @param w Webhook to create
* @return webhook returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
webhook create_webhook_sync(const class webhook &w);

webhook create_webhook_sync(const class webhook &wh);

/**
* @brief Delete a webhook
Expand Down
22 changes: 15 additions & 7 deletions include/dpp/emoji.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,29 @@ class DPP_EXPORT emoji : public managed, public json_interface<emoji> {

public:
/**
* @brief Emoji name
* @brief Emoji name.
*/
std::string name{};

/**
* @brief User id who uploaded the emoji
* @brief Roles allowed to use this emoji.
*/
snowflake user_id{0};
std::vector<snowflake> roles;

/**
* @brief Flags for the emoji from dpp::emoji_flags
* @brief The id of the user that created this emoji.
*/
uint8_t flags{0};
snowflake user_id;

/**
* @brief Image data for the emoji if uploading
* @brief Image data for the emoji, if uploading.
*/
std::string image_data{};
std::string image_data;

/**
* @brief Flags for the emoji from dpp::emoji_flags.
*/
uint8_t flags{0};

/**
* @brief Construct a new emoji object
Expand Down
2 changes: 1 addition & 1 deletion include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ struct DPP_EXPORT embed {
/** Optional: timestamp of embed content */
time_t timestamp;
/** Optional: color code of the embed */
uint32_t color;
std::optional<uint32_t> color;
/** Optional: footer information */
std::optional<embed_footer> footer;
/** Optional: image information */
Expand Down
Loading
Loading