-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/dev' into constructors
- Loading branch information
Showing
17 changed files
with
314 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,66 @@ | ||
\page buildmeson Build a Discord Bot using Meson | ||
\page buildmeson Build a Discord Bot Using Meson | ||
|
||
## 1. Toolchain | ||
|
||
Before compiling, you will need to install `meson` on your system. | ||
To be sure that `meson` is installed, you can type the following command: | ||
Before compiling, you will need to install `meson` on your system. To be sure that `meson` is installed, you can type the following command: | ||
|
||
$ meson --version | ||
0.63.2 | ||
```bash | ||
meson --version | ||
0.63.2 | ||
``` | ||
|
||
## 2. Create a Meson project | ||
|
||
In an empty directory. | ||
First, you'll need to go ahead and create an empty directory, we'll call it `meson-project`. | ||
|
||
- your project/ | ||
Then, run this command: | ||
|
||
run the command | ||
```bash | ||
meson init -l cpp | ||
``` | ||
|
||
$ meson init -l cpp | ||
## 3. Configuring Your Meson Project | ||
|
||
## 3. Configuring your Meson project | ||
Add the following line after the `project()` line in your `meson.build` file. | ||
|
||
add the following line after the `project()` line in your `meson.build` file. | ||
|
||
dpp = dependency('dpp') | ||
```yml | ||
dpp = dependency('dpp') | ||
``` | ||
|
||
add the following line in the executable section of your `meson.build` file. | ||
Add the following line in the executable section of your `meson.build` file. | ||
|
||
dependencies: [dpp] | ||
```yml | ||
dependencies: [dpp] | ||
``` | ||
change the `cpp_std` value in the `project()` to `c++17` | ||
Change the `cpp_std` value in the `project()` to `c++17`. Your `meson.build` should look like this: | ||
|
||
your meson.build should look like this. | ||
~~~~~~~~~~~~~~ | ||
~~~~~~~~~~~~~~yml | ||
project('discord-bot', 'cpp', | ||
version : '0.1', | ||
default_options : ['warning_level=3', | ||
'cpp_std=c++17']) | ||
|
||
dpp = dependency('dpp') | ||
|
||
exe = executable('discord', 'discord_bot.cpp', | ||
install : true, dependencies: [dpp]) | ||
|
||
test('basic', exe) | ||
~~~~~~~~~~~~~~ | ||
|
||
Meson automatically generates a cpp for your project. And a test suite. | ||
|
||
## 4. Building | ||
|
||
To build a meson project run | ||
To build a Meson project, run the following: | ||
|
||
```bash | ||
meson setup builddir | ||
meson compile -C builddir | ||
``` | ||
|
||
Now, your Meson project should be all setup! | ||
|
||
$ meson setup builddir | ||
$ meson compile -C builddir | ||
**Have fun!** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
\page building-a-cpp-discord-bot-in-repl Creating a Discord bot in Replit | ||
\page building-a-cpp-discord-bot-in-repl Creating a Discord Bot in Replit | ||
|
||
@note There is a premade repl, ready for use which was built using the steps above. If you wish to use this repl simply [visit this github repository](https://github.com/alanlichen/dpp-on-repl) and click the "Run on Replit" button. Then, follow the steps in the README file. | ||
\warning Be aware, Replit changes frequently, meaning DPP may not always work. It is out of our control and you simply have to hope that they change it again. If this is an inconvenience, we recommend you obtain some affordable non-free hosting. | ||
|
||
To build a D++ bot in a Replit instance, follow these steps. These steps are slightly more convoluted than installing D++ into a standard container as we don't have access to root in the conventional way or write access to any files outside of our home directory in a repl. This guide sidesteps the issue by locally extracting a libdpp deb file installer, and referencing the local dependencies from the command-line. | ||
\note There is a premade repl, ready for use, which was built using the steps below. If you wish to use this repl simply [visit this GitHub repository](https://github.com/alanlichen/dpp-on-repl) and click the "Run on Replit" button. Then, follow the steps in the README file. | ||
|
||
1. Use wget, or the upload button, to get the precompiled x64 release into your repl as a file, e.g. `wget -O libdpp.deb https://dl.dpp.dev/latest` | ||
To build a D++ bot in a Replit instance, follow these steps. These steps are slightly more convoluted than installing D++ into a standard container as we don't have access to root in the conventional way or write access to any files outside of our home directory in a repl. This guide sidesteps the issue by locally extracting a `libdpp` deb file installer, and referencing the local dependencies from the command-line. | ||
|
||
1. Use wget, or the upload button, to get the precompiled x64 release into your repl as a file, e.g. `wget -O libdpp.deb https://dl.dpp.dev/latest`, | ||
2. Extract this deb file using `dpkg`: | ||
``` | ||
```bash | ||
dpkg -x libdpp.deb . | ||
``` | ||
3. Compile your bot, note that you should be sure to include the `pthread` library explicitly and reference the extracted dpp installation you just put into the repl: | ||
``` | ||
```bash | ||
g++ -o bot main.cpp -ldpp -lpthread -L./usr/lib -I./usr/include -std=c++17 | ||
``` | ||
4. Run your bot! Note that you will need to set `LD_PRELOAD` to reference `libdpp.so` as it will be located in `$HOME` and not `/usr/lib`: | ||
``` | ||
```bash | ||
LD_PRELOAD=./usr/lib/libdpp.so ./bot | ||
``` | ||
|
||
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. | ||
|
||
1. Start a http server. This can be through any webserver, but as a simple solution, use python's built in http.server: | ||
``` | ||
```bash | ||
python3 -m http.server | ||
``` | ||
2. Create an `index.html` file with anything inside it for the server to serve. | ||
3. Go to [uptimerobot.com](https://uptimerobot.com/) and create an account if you don't have one. | ||
4. After verifying your account, click "Add New Monitor". | ||
+ For Monitor Type, select "HTTP(s)" | ||
+ In Friendly Name, put the name of your bot | ||
+ For your url, copy the url of the new website that repl is serving for you | ||
+ For your URL, copy the URL of the new website that repl is serving for you | ||
+ Select any alert contacts you want, then click "Create Monitor" | ||
|
||
Here is an example of a possible uptimerobot configuration: | ||
|
||
\image html uptimerobot.png | ||
|
||
## Troubleshooting | ||
|
||
If the bot fails to start and instead you receive an error message about being banned from the Discord API, there is little to be done about this. These bans are temporary but because Replit is a shared platform, you share an IP address with many thousands of bots, some abusive and some badly written. This will happen often and is outside of the control of yourself and us. However, you can try to migitate this by typing `kill 1` in the shell. This is not guaranteed to work, and you might need to try it a few times. If it still does not work, then we recommend instead you obtain some affordable non-free hosting instead. | ||
- If the bot fails to start and instead you receive an error message about being banned from the Discord API, there is little to be done about this. These bans are temporary but because Replit is a shared platform, you share an IP address with many thousands of bots, some abusive and some badly written. This will happen often and is outside of the control of yourself and us. However, you can try to mitigate this by typing `kill 1` in the shell. This is not guaranteed to work, and you might need to try it a few times. If it still does not work, then we recommend you obtain some affordable non-free hosting instead. | ||
|
||
If your bot continues to fall asleep even though you have a server, we advise you to double check that no errors are happening, and if the server is being pinged. If that still does not work, we again recommend you to obtain some affordable non-free hosting. | ||
- If your bot continues to fall asleep even though you have a server, we advise you to double check that no errors are happening, and if the server is being pinged. If that still does not work then, again, we recommend you obtain some affordable non-free hosting. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.