Skip to content

Commit 0d6aff8

Browse files
begin refactoring to our namespace and code style
1 parent bebe921 commit 0d6aff8

Some content is hidden

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

62 files changed

+457
-514
lines changed

buildtools/make_vcpkg.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
$vcpkg->constructPortAndVersionFile()
4343
);
4444
if (!empty($sha512)) {
45-
/* Now check out master */
45+
/* now check out master */
4646
if (!$vcpkg->checkoutRepository()) {
4747
exit(1);
4848
}

docpages/advanced_reference/automating-with-jenkins.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Making sure you have your project files in the workspace directory (you can see
4949

5050
Running the builds is the same as any other time, but we'll still cover it! However, we won't cover running it in background and whatnot, that part is completely down to you.
5151

52-
First, you need to get into the `jenkins` user. If you're like me and don't have the Jenkins user password, you can login with your normal login (that has sudo perms) and do `sudo su - jenkins`. Once logged in, you'll be in `/var/lib/jenkins/`. From here, you'll want to do `cd workspace/DiscordBot/` (make sure to replace "DiscordBot" with your bot's name. Remember, you can tab-complete this) and then `cd build`. Now, you can simply do `./DiscordBot`!
52+
First, you need to get into the `jenkins` user. If you're like me and don't have the Jenkins user password, you can login with your normal login (that has sudo perms) and do `sudo su - jenkins`. Once logged in, you'll be in `/var/lib/jenkins/`. From here, you'll want to do `cd workspace/DiscordBot/` (make sure to replace "DiscordBot" with your bot's name. Remember, you can tab-complete this) and then `cd build`. now, you can simply do `./DiscordBot`!
5353

5454
\warning If you are going to be running the bot at the same time as builds, I would heavily advise that you copy the bot (if it's not statically linked, then copy the entire build directory) to a different location. This is so you can pick and choose when the bot gets updated (and even means you can run experimental builds as opposed to stable builds) but also means you avoid any risk of the bot crashing during build (as Jenkins will be overwriting your executable and libraries).
5555

docpages/advanced_reference/lambdas_and_locals.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ It is important to remember that when you put a lambda callback onto a function
88

99
To explain this situation and how it causes issues, I'd like you to imagine the age-old magic trick, where a magician sets a fine table full of cutlery, pots, pans and wine. He indicates to the audience that this is authentic, then with a whip of his wrist, he whips the tablecloth away, leaving the cutlery and other tableware in place (if he is any good as a magician!)
1010

11-
Now imagine the following code scenario. We will describe this code scenario as the magic trick above, in the steps below:
11+
now imagine the following code scenario. We will describe this code scenario as the magic trick above, in the steps below:
1212

1313
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cpp
1414
bot.on_message_create([&bot](const dpp::message_create_t & event) {

docpages/advanced_reference/separate-events.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ int main() {
7474

7575
And there we go! How tidy is that?
7676

77-
Now, the possibilities to this are not limited. If you wish to do this twice (as I explained at first), you can simply have another class and just copy the `bot.on_message_create` line below in the `main.cpp` file and then you can change it to reference the second class, meaning you have two message events firing in two separate classes!
77+
now, the possibilities to this are not limited. If you wish to do this twice (as I explained at first), you can simply have another class and just copy the `bot.on_message_create` line below in the `main.cpp` file and then you can change it to reference the second class, meaning you have two message events firing in two separate classes!

docpages/advanced_reference/voice_model.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ digraph "Example Directory" {
6363
"Discord" -> "HTTP/1.1 204 No Content...";
6464
"Discord" -> "HTTP/1.1 101 Switching Protocols";
6565
66-
label = "Now, we're waiting for a response from Discord.\nIf we receive 204, we'll start initiating voiceconn. However, if we receive 101, then we can do all the voice stuff.";
66+
label = "now, we're waiting for a response from Discord.\nIf we receive 204, we'll start initiating voiceconn. However, if we receive 101, then we can do all the voice stuff.";
6767
}
6868

6969
subgraph cluster_4 {

docpages/example_programs/misc/making_threads.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ After that, you'll be able to see your bot send a message in your thread!
2626

2727
Those of you who are familar with sending messages in regular channels may have also noticed that sending messages to threads is the same as sending a general message. This is because threads are basically channels with a couple more features!
2828

29-
Now, we're going to cover how to lock a thread! With this, you'll also learn how to edit threads in general, meaning you can go forward and learn how to change even more stuff about threads, as much as your heart desires!
29+
now, we're going to cover how to lock a thread! With this, you'll also learn how to edit threads in general, meaning you can go forward and learn how to change even more stuff about threads, as much as your heart desires!
3030

3131
\include{cpp} making_threads3.cpp
3232

docpages/example_programs/misc/setting_status.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If all went well, your bot should now be online and say this on members list!
1515
If you want to make your bot show as Do Not Disturb, then you could change dpp::ps_online to dpp::ps_dnd.
1616
You can also play around with dpp::at_game, changing it to something like dpp::at_custom or dpp::at_listening!
1717

18-
Now, let's cover setting the bot status to say `Playing with x guilds!` every two minutes.
18+
now, let's cover setting the bot status to say `Playing with x guilds!` every two minutes.
1919

2020
\note This example uses timers to update the status every 2 minutes. If you aren't familiar with D++'s own timers, please read \ref using_timers "this page on timers" before you continue.
2121

docpages/example_programs/misc/using-emojis.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ First - Sending emojis. You have to use its mention, which depends on the type.
88

99
\include{cpp} using_emojis1.cpp
1010

11-
Now, our bot will send our epic emojis!
11+
now, our bot will send our epic emojis!
1212

1313
\image html using_emojis1.png
1414

docpages/example_programs/misc/using_timers.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Now, let's make the same timer a one-shot timer, meaning it will only run once!
1414

1515
\include{cpp} timers_example2.cpp
1616

17-
Great! Now we've learnt the basics of timers and how to stop them!
17+
Great! now we've learnt the basics of timers and how to stop them!
1818

1919
To finish off, let's make a timer that you can start and stop with commands. This example will store the timer in a map where the user is the owner of the timer!
2020

docpages/example_programs/the_basics/editing-channels-and-messages.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ After editing the channel:
3333
\image html stuff_edit4.png
3434

3535
## Editing embeds
36-
Now let's send an embed and edit it. If a message has one `content` field, it can have a few `embed` fields, up to 10 to be precise. So we first get the embed we want and edit and change its description.
36+
now let's send an embed and edit it. If a message has one `content` field, it can have a few `embed` fields, up to 10 to be precise. So we first get the embed we want and edit and change its description.
3737

3838
\include{cpp} editing_messages3.cpp
3939

docpages/example_programs/the_basics/private-messaging.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Sometimes it's simply not enough to ping someone in a server with a message, and
66

77
\include{cpp} private_messaging.cpp
88

9-
That's it! Now, you should have something like this:
9+
That's it! now, you should have something like this:
1010

1111
\image html privatemessageexample.png
1212
\image html privatemessageexample2.png

docpages/example_programs/the_basics/using_callback_functions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
\page callback-functions Using Callback Functions
22

3-
When you create or get an object from Discord, you send the request to its API and in return you get either an error or the object you requested/created. You can pass a function to API calls as the callback function. This means that when the request completes, and you get a response from the API, your callback function executes. You must be careful with lambda captures! Good practice would be not capturing variables by reference unless you have to, since when the request completes and the function executes, the variables can already be destructed. Advanced reference can be found [here](https://dpp.dev/lambdas-and-locals.html). Now, let's see callback functions in action:
3+
When you create or get an object from Discord, you send the request to its API and in return you get either an error or the object you requested/created. You can pass a function to API calls as the callback function. This means that when the request completes, and you get a response from the API, your callback function executes. You must be careful with lambda captures! Good practice would be not capturing variables by reference unless you have to, since when the request completes and the function executes, the variables can already be destructed. Advanced reference can be found [here](https://dpp.dev/lambdas-and-locals.html). now, let's see callback functions in action:
44

55
\include{cpp} callbacks.cpp
66

docpages/install/install-windows-vs-zip.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To add D++ to a Visual Studio project, using **Visual Studio 2019** or **Visual
3939
12. Again within the same window, go to the input section, under the linker category, and add '**dpp.lib;**' to the start of the libraries to include, as shown below:
4040
\image html zip_vsproj_11.png
4141

42-
13. Now you can paste some code into the editor, completely replacing the 'hello world' application that Visual Studio made for you. The example code here is the basic bot from the first example on this site. You should at this point also double check that the architecture you have selected (in this case x86) matches the version of the dll/lib files you downloaded from the website. This is **important** as if you mismatch them the compilation will just fail.
42+
13. now you can paste some code into the editor, completely replacing the 'hello world' application that Visual Studio made for you. The example code here is the basic bot from the first example on this site. You should at this point also double check that the architecture you have selected (in this case x86) matches the version of the dll/lib files you downloaded from the website. This is **important** as if you mismatch them the compilation will just fail.
4343
\image html zip_vsproj_12.png
4444

4545
14. Go to the build menu and choose Build Solution (A handy shortcut for this is to just press **F7**):

docpages/make_a_bot/clion.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Now, you can open your `main.cpp` file. If you have code there, then you're one
1010

1111
\include{cpp} firstbot.cpp
1212

13-
Now, you can go ahead and hit the green "Run" button in the top-right to run the bot.
13+
now, you can go ahead and hit the green "Run" button in the top-right to run the bot.
1414

1515
**Congratulations, you've successfully set up a bot!**
1616

docpages/make_a_bot/cmake.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ find_package_handle_standard_args(DPP DEFAULT_MSG DPP_LIBRARIES DPP_INCLUDE_DIR)
120120

121121
## 4. Build the bot.
122122

123-
Now that we have our all our cmake stuff setup and we've got our code in place, we can initalise CMake. You'll want to go inside the `build/` directory and do `cmake ..`.
123+
now that we have our all our cmake stuff setup and we've got our code in place, we can initalise CMake. You'll want to go inside the `build/` directory and do `cmake ..`.
124124

125125
Once that's completed, you'll want to head back to your up-most folder (where all the folders are for your bot) and run `cmake --build build/ -j4` (replace -j4 with however many threads you want to use). This will start compiling your bot and creating the executable.
126126

docpages/make_a_bot/meson.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ meson setup builddir
6161
meson compile -C builddir
6262
```
6363

64-
Now, your Meson project should be all setup!
64+
now, your Meson project should be all setup!
6565

6666
**Have fun!**

docpages/make_a_bot/replit.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ g++ -o bot main.cpp -ldpp -lpthread -L./usr/lib -I./usr/include -std=c++17
2020
LD_PRELOAD=./usr/lib/libdpp.so ./bot
2121
```
2222

23-
Now that your bot is running, you have to keep it online. Replit automatically puts repls to sleep after some time, so you will need to ping a webserver. Unfortunately, Replit is sometimes limiting, and this is one of the only free workarounds to this issue.
23+
now that your bot is running, you have to keep it online. Replit automatically puts repls to sleep after some time, so you will need to ping a webserver. Unfortunately, Replit is sometimes limiting, and this is one of the only free workarounds to this issue.
2424

2525
1. Start a http server. This can be through any webserver, but as a simple solution, use python's built in http.server:
2626
```bash

docpages/make_a_bot/token.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To create a new application, take the steps as follows:
1010
2. Next, enter a name for the application in the pop-up and press the "Create" button.
1111
\image html create_application_confirm_popup.png
1212
In this example we named it "D++ Test Bot".
13-
3. Move on by click the "Bot" tab in the left-hand side of the screen. Now click the "Add Bot" button on the right and confirm that you want to add the bot to your application.
13+
3. Move on by click the "Bot" tab in the left-hand side of the screen. now click the "Add Bot" button on the right and confirm that you want to add the bot to your application.
1414
\image html create_application_add_bot.png
1515
On the resulting screen, you’ll note a page with information regarding your new bot. You can edit your bot name, description, and avatar here if you want to. If you wish to read the message content from messages, you need to enable the message content intent in the "Privileged Gateway Intents" section.
1616
\image html create_application_bot_overview.png

docpages/make_a_bot/windows_wsl.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This tutorial teaches you how to create a lightweight environment for D++ develo
1212
6. Congratulations, you've successfully installed all dependencies! Now comes the real fun: Setting up the environment! For this tutorial we'll use a as small as possible setup, so you might create a more advanced one for production bots.
1313
7. Create a new directory, inside your home directory, using `mkdir MyBot`. Then, you want to open that directory using `cd MyBot`.
1414
8. Now that you've a directory to work in, type `touch mybot.cxx` to create a file you can work in!
15-
9. Now, head on over to Visual Studio Code. Press `CTRL+SHIFT+P` and type `Remote-WSL: New WSL Window` (You don't have to type all of it, it will auto-suggest it!). This will bring up a new window. In the new window, choose `open folder` and choose the directory you've created prior (It should be within your home directory). Press OK and now you have your Folder opened as a Workspace!
15+
9. now, head on over to Visual Studio Code. Press `CTRL+SHIFT+P` and type `Remote-WSL: New WSL Window` (You don't have to type all of it, it will auto-suggest it!). This will bring up a new window. In the new window, choose `open folder` and choose the directory you've created prior (It should be within your home directory). Press OK and now you have your Folder opened as a Workspace!
1616
10. Add code to your CXX file (We suggest using the \ref firstbot "first bot page" if this is your first time!) and compile it by running `g++ -std=c++17 *.cxx -o bot -ldpp` in the same folder as your cxx file. This will create a "bot" file!
1717
11. You can now start your bot by typing `./bot`!
1818

include/dpp/wsclient.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum ws_state : uint8_t {
5454
HTTP_HEADERS,
5555

5656
/**
57-
* @brief Connected as a websocket, and "upgraded". Now talking using binary frames.
57+
* @brief Connected as a websocket, and "upgraded". now talking using binary frames.
5858
*/
5959
CONNECTED
6060
};

src/dpp/dave/array_view.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
#include <cassert>
44
#include <vector>
55

6-
namespace discord {
7-
namespace dave {
6+
namespace dpp::dave {
87

98
template <typename T>
10-
class ArrayView {
9+
class array_view {
1110
public:
12-
ArrayView() = default;
13-
ArrayView(T* data, size_t size)
11+
array_view() = default;
12+
array_view(T* data, size_t size)
1413
: data_(data)
1514
, size_(size)
1615
{
@@ -28,16 +27,16 @@ class ArrayView {
2827
};
2928

3029
template <typename T>
31-
inline ArrayView<T> MakeArrayView(T* data, size_t size)
30+
inline array_view<T> make_array_view(T* data, size_t size)
3231
{
33-
return ArrayView<T>(data, size);
32+
return array_view<T>(data, size);
3433
}
3534

3635
template <typename T>
37-
inline ArrayView<T> MakeArrayView(std::vector<T>& data)
36+
inline array_view<T> make_array_view(std::vector<T>& data)
3837
{
39-
return ArrayView<T>(data.data(), data.size());
38+
return array_view<T>(data.data(), data.size());
4039
}
4140

42-
} // namespace dave
43-
} // namespace discord
41+
} // namespace dpp::dave
42+

src/dpp/dave/cipher_interface.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "cipher_interface.h"
2+
#include "openssl_aead_cipher.h"
3+
4+
namespace dpp::dave {
5+
6+
std::unique_ptr<cipher_interface> create_cipher(const EncryptionKey& encryptionKey)
7+
{
8+
auto cipher = std::make_unique<openssl_aead_cipher>(encryptionKey);
9+
return cipher->IsValid() ? std::move(cipher) : nullptr;
10+
}
11+
12+
} // namespace dpp::dave
13+

src/dpp/dave/cipher_interface.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <memory>
4+
5+
#include "common.h"
6+
#include "array_view.h"
7+
8+
namespace dpp::dave {
9+
10+
class cipher_interface {
11+
public:
12+
virtual ~cipher_interface() = default;
13+
14+
virtual bool Encrypt(array_view<uint8_t> ciphertextBufferOut,
15+
array_view<const uint8_t> plaintextBuffer,
16+
array_view<const uint8_t> nonceBuffer,
17+
array_view<const uint8_t> additionalData,
18+
array_view<uint8_t> tagBufferOut) = 0;
19+
virtual bool Decrypt(array_view<uint8_t> plaintextBufferOut,
20+
array_view<const uint8_t> ciphertextBuffer,
21+
array_view<const uint8_t> tagBuffer,
22+
array_view<const uint8_t> nonceBuffer,
23+
array_view<const uint8_t> additionalData) = 0;
24+
};
25+
26+
std::unique_ptr<cipher_interface> create_cipher(const EncryptionKey& encryptionKey);
27+
28+
} // namespace dpp::dave
29+

src/dpp/dave/clock.h

+11-12
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@
22

33
#include <chrono>
44

5-
namespace discord {
6-
namespace dave {
5+
namespace dpp::dave {
76

8-
class IClock {
7+
class clock_interface {
98
public:
10-
using BaseClock = std::chrono::steady_clock;
11-
using TimePoint = BaseClock::time_point;
12-
using Duration = BaseClock::duration;
9+
using base_clock = std::chrono::steady_clock;
10+
using time_point = base_clock::time_point;
11+
using clock_duration = base_clock::duration;
1312

14-
virtual ~IClock() = default;
15-
virtual TimePoint Now() const = 0;
13+
virtual ~clock_interface() = default;
14+
virtual time_point now() const = 0;
1615
};
1716

18-
class Clock : public IClock {
17+
class Clock : public clock_interface {
1918
public:
20-
TimePoint Now() const override { return BaseClock::now(); }
19+
time_point now() const override { return base_clock::now(); }
2120
};
2221

23-
} // namespace dave
24-
} // namespace discord
22+
} // namespace dpp::dave
23+

0 commit comments

Comments
 (0)