aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content/resources/guides
diff options
context:
space:
mode:
authorGravatar Boris Muratov <[email protected]>2023-04-07 19:13:53 +0300
committerGravatar GitHub <[email protected]>2023-04-07 19:13:53 +0300
commit8c8d67cedc30dcb4f9903236ee8ffee315ea6ce1 (patch)
tree4d125388fefdd79e9e00479683dfbb9f7706b3e0 /pydis_site/apps/content/resources/guides
parentimprove wording of a couple sections (diff)
parentMerge pull request #932 from python-discord/filters_fix (diff)
Merge branch 'main' into config-scaffolding-guide
Diffstat (limited to 'pydis_site/apps/content/resources/guides')
-rw-r--r--pydis_site/apps/content/resources/guides/pydis-guides/contributing/creating-bot-account.md6
-rw-r--r--pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md4
-rw-r--r--pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md19
-rw-r--r--pydis_site/apps/content/resources/guides/python-guides/discord-messages-with-colors.md23
-rw-r--r--pydis_site/apps/content/resources/guides/python-guides/discordpy-subclassing-context.md129
-rw-r--r--pydis_site/apps/content/resources/guides/python-guides/keeping-tokens-safe.md2
-rw-r--r--pydis_site/apps/content/resources/guides/python-guides/why-not-json-as-database.md2
7 files changed, 162 insertions, 23 deletions
diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/creating-bot-account.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/creating-bot-account.md
index ee38baa3..51da3f34 100644
--- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/creating-bot-account.md
+++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/creating-bot-account.md
@@ -9,9 +9,9 @@ icon: fab fa-discord
4. Change your bot's `Public Bot` setting off so only you can invite it, save, and then get your **Bot Token** with the `Copy` button.
> **Note:** **DO NOT** post your bot token anywhere public. If you do it can and will be compromised.
5. Save your **Bot Token** somewhere safe to use in the project settings later.
-6. In the `General Information` tab, grab the **Client ID**.
-7. Replace `<CLIENT_ID_HERE>` in the following URL and visit it in the browser to invite your bot to your new test server.
+6. In the `General Information` tab, grab the **Application ID**.
+7. Replace `<APPLICATION_ID_HERE>` in the following URL and visit it in the browser to invite your bot to your new test server.
```plaintext
-https://discordapp.com/api/oauth2/authorize?client_id=<CLIENT_ID_HERE>&permissions=8&scope=bot
+https://discordapp.com/api/oauth2/authorize?client_id=<APPLICATION_ID_HERE>&permissions=8&scope=bot
```
Optionally, you can generate your own invite url in the `OAuth` tab, after selecting `bot` as the scope.
diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md
index c9566d23..edfd7ac1 100644
--- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md
+++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md
@@ -10,7 +10,7 @@ You should have already forked the [`sir-lancebot`](https://github.com/python-di
Remember to ensure that you have read the [contributing guidelines](../contributing-guidelines) in full before you start contributing.
### Requirements
-- [Python 3.9](https://www.python.org/downloads/)
+- [Python 3.10.*](https://www.python.org/downloads/)
- [Poetry](https://github.com/python-poetry/poetry#installation)
- [Git](https://git-scm.com/downloads)
- [Windows Installer](https://git-scm.com/download/win)
@@ -59,7 +59,7 @@ You will need your own test server and bot account on Discord to test your chang
* `#dev-log`
* `#sir-lancebot-commands`
4. Create the following roles:
- * `@Admin`
+ * `@Admins`
5. Note down the IDs for your server, as well as any channels and roles created.
* [**Learn how to obtain the ID of a server, channel or role here.**](../setting-test-server-and-bot-account#obtain-the-ids)
diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md
index 51587aac..3862fb2e 100644
--- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md
+++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md
@@ -10,12 +10,12 @@ The following variables are needed for running Sir Lancebot:
| -------- | -------- |
| `BOT_TOKEN` | Bot Token from the [Discord developer portal](https://discord.com/developers/applications) |
| `BOT_GUILD` | ID of the Discord Server |
-| `BOT_ADMIN_ROLE_ID` | ID of the role @Admins |
-| `ROLE_HELPERS` | ID of the role @Helpers |
-| `CHANNEL_ANNOUNCEMENTS` | ID of the #announcements channel |
-| `CHANNEL_DEVLOG` | ID of the #dev-log channel |
-| `CHANNEL_COMMUNITY_BOT_COMMANDS` | ID of the #sir-lancebot-commands channel |
-| `CHANNEL_REDDIT` | ID of the #reddit channel |
+| `BOT_ADMIN_ROLE_ID` | ID of the role `@Admins` |
+| `ROLE_HELPERS` | ID of the role `@Helpers` |
+| `CHANNEL_ANNOUNCEMENTS` | ID of the `#announcements` channel |
+| `CHANNEL_DEVLOG` | ID of the `#dev-log` channel |
+| `CHANNEL_COMMUNITY_BOT_COMMANDS` | ID of the `#sir-lancebot-commands` channel |
+| `CHANNEL_REDDIT` | ID of the `#reddit` channel |
---
## Debug Variables
@@ -32,8 +32,7 @@ Additionally, you may find the following environment variables useful during dev
| `REDIS_PASSWORD` | |
| `USE_FAKEREDIS` | If the FakeRedis module should be used. Set this to true if you don't have a Redis database setup. |
| `BOT_SENTRY_DSN` | The DSN of the sentry monitor. |
-| `TRASHCAN_EMOJI` | The full emoji to use for the trashcan. Format should be like the output of `\:emoji:`. |
-
+| `TRASHCAN_EMOJI` | The full emoji to use for the trashcan. Format should be like the output of sending `\:emoji:` on discord. |
---
## Tokens/APIs
@@ -66,8 +65,8 @@ These variables might come in handy while working on certain cogs:
| Advent of Code | `AOC_ROLE_ID` | ID of the advent of code role.
| Advent of Code | `AOC_IGNORED_DAYS` | Comma separated list of days to ignore while calculating score. |
| Advent of Code | `AOC_YEAR` | Debug variable to change the year used for AoC. |
-| Advent of Code | `AOC_CHANNEL_ID` | The ID of the #advent-of-code channel |
-| Advent of Code | `AOC_COMMANDS_CHANNEL_ID` | The ID of the #advent-of-code-commands channel |
+| Advent of Code | `AOC_CHANNEL_ID` | The ID of the `#advent-of-code` channel |
+| Advent of Code | `AOC_COMMANDS_CHANNEL_ID` | The ID of the `#advent-of-code-commands` channel |
| Advent of Code | `AOC_FALLBACK_SESSION` | |
| Advent of Code | `AOC_SESSION_COOKIE` | |
| Valentines | `LOVEFEST_ROLE_ID` | |
diff --git a/pydis_site/apps/content/resources/guides/python-guides/discord-messages-with-colors.md b/pydis_site/apps/content/resources/guides/python-guides/discord-messages-with-colors.md
index 62ff61f9..0e88490e 100644
--- a/pydis_site/apps/content/resources/guides/python-guides/discord-messages-with-colors.md
+++ b/pydis_site/apps/content/resources/guides/python-guides/discord-messages-with-colors.md
@@ -3,9 +3,10 @@ title: Discord Messages with Colors
description: A guide on how to add colors to your codeblocks on Discord
---
-Discord is now slowly rolling out the ability to send colored text within code blocks. This is done using ANSI color codes which is also how you print colored text in your terminal.
+Discord is now *slowly rolling out* the ability to send colored messages within code blocks. It uses the ANSI color codes, so if you've tried to print colored text in your terminal or console with Python or other languages then it will be easy for you.
-To send colored text in a code block you need to first specify the `ansi` language and use the prefixes similar to the one below:
+## Quick Explanation
+To be able to send a colored text, you need to use the `ansi` language for your code block and provide a prefix of this format before writing your text:
```ansi
\u001b[{format};{color}m
```
@@ -13,15 +14,17 @@ To send colored text in a code block you need to first specify the `ansi` langua
After you've written this, you can now type the text you wish to color. If you want to reset the color back to normal, then you need to use the `\u001b[0m` prefix again.
+## Formats
Here is the list of values you can use to replace `{format}`:
* 0: Normal
* 1: **Bold**
* 4: <ins>Underline</ins>
+## Colors
Here is the list of values you can use to replace `{color}`:
-*The following values will change the **text** color.*
+### Text Colors
* 30: Gray
* 31: Red
@@ -32,7 +35,7 @@ Here is the list of values you can use to replace `{color}`:
* 36: Cyan
* 37: White
-*The following values will change the **text background** color.*
+### Background Colors
* 40: Firefly dark blue
* 41: Orange
@@ -43,7 +46,9 @@ Here is the list of values you can use to replace `{color}`:
* 46: Light gray
* 47: White
-Let's take an example, I want a bold green colored text with the very dark blue background.
+## Example
+
+Let's take an example, I want a bold green colored text with the firefly dark blue background.
I simply use `\u001b[0;40m` (background color) and `\u001b[1;32m` (text color) as prefix. Note that the order is **important**, first you give the background color and then the text color.
Alternatively you can also directly combine them into a single prefix like the following: `\u001b[1;40;32m` and you can also use multiple values. Something like `\u001b[1;40;4;32m` would underline the text, make it bold, make it green and have a dark blue background.
@@ -61,8 +66,14 @@ Result:
![Background and text color result](/static/images/content/discord_colored_messages/result.png)
+### ANSI Colors Showcase
+
The way the colors look like on Discord is shown in the image below:
![ANSI Colors](/static/images/content/discord_colored_messages/ansi-colors.png)
-Note: If the change as not been brought to you yet, or other users, then you can use other code blocks in the meantime to get colored text. See **[this gist](https://gist.github.com/matthewzring/9f7bbfd102003963f9be7dbcf7d40e51)**.
+*Message sent to get the output of above can be found [here](https://gist.github.com/kkrypt0nn/a02506f3712ff2d1c8ca7c9e0aed7c06#file-ansi-colors-showcase-md).*
+
+#### Disclaimer
+
+***Note**: The change has been brought to all stable desktop clients. Since syntax highlighting on mobile is far behind, ANSI is not supported on mobile as well. Refer to [this gist](https://gist.github.com/matthewzring/9f7bbfd102003963f9be7dbcf7d40e51) for other syntax highlighting methods.*
diff --git a/pydis_site/apps/content/resources/guides/python-guides/discordpy-subclassing-context.md b/pydis_site/apps/content/resources/guides/python-guides/discordpy-subclassing-context.md
new file mode 100644
index 00000000..b77cb0f9
--- /dev/null
+++ b/pydis_site/apps/content/resources/guides/python-guides/discordpy-subclassing-context.md
@@ -0,0 +1,129 @@
+---
+title: Subclassing Context in discord.py
+description: "Subclassing the default `commands.Context` class to add more functionability and customizability."
+---
+
+Start by reading the guide on [subclassing the `Bot` class](./subclassing_bot.md). A subclass of Bot has to be used to
+inject your custom context subclass into discord.py.
+
+## Overview
+
+The way this works is by creating a subclass of discord.py's [`Context` class](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context)
+adding whatever functionality you wish. Usually this is done by adding custom methods or properties, so that you don't need to
+copy it around or awkwardly import it elsewhere.
+
+This guide will show you how to add a `prompt()` method to the context and how to use it in a command.
+
+## Example subclass and code
+
+The first part - of course - is creating the actual context subclass. This is done similarly to creating a bot
+subclass, it will look like this:
+
+```python
+import asyncio
+from typing import Optional
+
+from discord import RawReactionActionEvent
+from discord.ext import commands
+
+
+class CustomContext(commands.Context):
+ async def prompt(
+ self,
+ message: str,
+ *,
+ timeout=30.0,
+ delete_after=True
+ ) -> Optional[bool]:
+ """Prompt the author with an interactive confirmation message.
+
+ This method will send the `message` content, and wait for max `timeout` seconds
+ (default is `30`) for the author to react to the message.
+
+ If `delete_after` is `True`, the message will be deleted before returning a
+ True, False, or None indicating whether the author confirmed, denied,
+ or didn't interact with the message.
+ """
+ msg = await self.send(message)
+
+ for reaction in ('✅', '❌'):
+ await msg.add_reaction(reaction)
+
+ confirmation = None
+
+ # This function is a closure because it is defined inside of another
+ # function. This allows the function to access the self and msg
+ # variables defined above.
+
+ def check(payload: RawReactionActionEvent):
+ # 'nonlocal' works almost like 'global' except for functions inside of
+ # functions. This means that when 'confirmation' is changed, that will
+ # apply to the variable above
+ nonlocal confirmation
+
+ if payload.message_id != msg.id or payload.user_id != self.author.id:
+ return False
+
+ emoji = str(payload.emoji)
+
+ if emoji == '✅':
+ confirmation = True
+ return True
+
+ elif emoji == '❌':
+ confirmation = False
+ return True
+
+ # This means that it was neither of the two emojis added, so the author
+ # added some other unrelated reaction.
+ return False
+
+ try:
+ await self.bot.wait_for('raw_reaction_add', check=check, timeout=timeout)
+ except asyncio.TimeoutError:
+ # The 'confirmation' variable is still None in this case
+ pass
+
+ if delete_after:
+ await msg.delete()
+
+ return confirmation
+```
+
+After creating your context subclass, you need to override the `get_context()` method on your
+Bot class and change the default of the `cls` parameter to this subclass:
+
+```python
+from discord.ext import commands
+
+
+class CustomBot(commands.Bot):
+ async def get_context(self, message, *, cls=CustomContext): # From the above codeblock
+ return await super().get_context(message, cls=cls)
+```
+
+Now that discord.py is using your custom context, you can use it in a command. For example:
+
+```python
+import discord
+from discord.ext import commands
+
+# Enable the message intent so that we get message content. This is needed for
+# the commands we define below
+intents = discord.Intents.default()
+intents.message_content = True
+
+
+# Replace '...' with any additional arguments for the bot
+bot = CustomBot(intents=intents, ...)
+
+
+async def massban(ctx: CustomContext, members: commands.Greedy[discord.Member]):
+ prompt = await ctx.prompt(f"Are you sure you want to ban {len(members)} members?")
+ if not prompt:
+ # Return if the author cancelled, or didn't react in time
+ return
+
+ ... # Perform the mass-ban, knowing the author has confirmed this action
+```
diff --git a/pydis_site/apps/content/resources/guides/python-guides/keeping-tokens-safe.md b/pydis_site/apps/content/resources/guides/python-guides/keeping-tokens-safe.md
index 9d523b4b..92eb52a3 100644
--- a/pydis_site/apps/content/resources/guides/python-guides/keeping-tokens-safe.md
+++ b/pydis_site/apps/content/resources/guides/python-guides/keeping-tokens-safe.md
@@ -11,7 +11,7 @@ To help prevent leaking your token,
you should ensure that you don't upload it to an open source program/website,
such as replit and github, as they show your code publicly.
The best practice for storing tokens is generally utilising .env files
-([click here](https://vcokltfre.dev/tips/tokens/.) for more information on storing tokens safely).
+([click here](https://tutorial.vco.sh/tips/tokens/) for more information on storing tokens safely).
# What should I do if my token does get leaked?
diff --git a/pydis_site/apps/content/resources/guides/python-guides/why-not-json-as-database.md b/pydis_site/apps/content/resources/guides/python-guides/why-not-json-as-database.md
index ae34c2b4..6d9f433e 100644
--- a/pydis_site/apps/content/resources/guides/python-guides/why-not-json-as-database.md
+++ b/pydis_site/apps/content/resources/guides/python-guides/why-not-json-as-database.md
@@ -2,7 +2,7 @@
title: Why JSON is unsuitable as a database
description: The many reasons why you shouldn't use JSON as a database, and instead opt for SQL.
relevant_links:
- Tips on Storing Data: https://tutorial.vcokltfre.dev/tips/storage/
+ Tips on Storing Data: https://tutorial.vco.sh/tips/storage/
---
JSON, quite simply, is not a database. It's not designed to be a data storage format,