Skip to content

Commit

Permalink
Use new Discord markdown support for bot messages (#2726)
Browse files Browse the repository at this point in the history
* feat: use new markdown feature in new help channel message

* feat(tags): update bullet points to dashes in tags

* feat(tags): add dashes to async libraries list

* feat: update markdown in patreon command

* feat: update markdown in otname command

* feat: update markdown in filter command

* feat: update markdown in voiceverify command

* feat: update markdown in docs command

* feat: update markdown in bigbrother command

* feat: update markdown in talentpool command
  • Loading branch information
DownDev committed Nov 25, 2023
1 parent 8f1d956 commit d4fdbce
Show file tree
Hide file tree
Showing 31 changed files with 103 additions and 103 deletions.
6 changes: 3 additions & 3 deletions bot/exts/filtering/_ui/ui.py
Expand Up @@ -155,13 +155,13 @@ def format_response_error(e: ResponseCodeError) -> Embed:
"""Format the response error into an embed."""
description = ""
if isinstance(e.response_json, list):
description = "\n".join(f" {error}" for error in e.response_json)
description = "\n".join(f"- {error}" for error in e.response_json)
elif isinstance(e.response_json, dict):
if "non_field_errors" in e.response_json:
non_field_errors = e.response_json.pop("non_field_errors")
description += "\n".join(f" {error}" for error in non_field_errors) + "\n"
description += "\n".join(f"- {error}" for error in non_field_errors) + "\n"
for field, errors in e.response_json.items():
description += "\n".join(f" {field} - {error}" for error in errors) + "\n"
description += "\n".join(f"- {field} - {error}" for error in errors) + "\n"

description = description.strip()
if len(description) > MAX_EMBED_DESCRIPTION:
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/fun/off_topic_names.py
Expand Up @@ -81,7 +81,7 @@ async def toggle_ot_name_activity(self, ctx: Context, name: str, active: bool) -
async def list_ot_names(self, ctx: Context, active: bool = True) -> None:
"""Send an embed containing active/deactivated off-topic channel names."""
result = await self.bot.api_client.get("bot/off-topic-channel-names", params={"active": json.dumps(active)})
lines = sorted(f" {name}" for name in result)
lines = sorted(f"- {name}" for name in result)
embed = Embed(
title=f"{'Active' if active else 'Deactivated'} off-topic names (`{len(result)}` total)",
colour=Colour.blue()
Expand Down Expand Up @@ -286,7 +286,7 @@ async def search_command(self, ctx: Context, *, query: OffTopicName) -> None:
close_matches = difflib.get_close_matches(query, result.keys(), n=10, cutoff=0.70)

# Send Results
lines = sorted(f" {result[name]}" for name in in_matches.union(close_matches))
lines = sorted(f"- {result[name]}" for name in in_matches.union(close_matches))
embed = Embed(
title="Query results",
colour=Colour.blue()
Expand Down
6 changes: 3 additions & 3 deletions bot/exts/help_channels/_channel.py
Expand Up @@ -19,9 +19,9 @@

NEW_POST_MSG = """
**Remember to:**
**Ask** your Python question, not if you can ask or if there's an expert who can help.
**Show** a code sample as text (rather than a screenshot) and the error message, if you've got one.
**Explain** what you expect to happen and what actually happens.
- **Ask** your Python question, not if you can ask or if there's an expert who can help.
- **Show** a code sample as text (rather than a screenshot) and the error message, if you've got one.
- **Explain** what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
"""
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/info/doc/_cog.py
Expand Up @@ -325,7 +325,7 @@ async def get_command(self, ctx: commands.Context, *, symbol_name: str | None) -
colour=discord.Colour.blue()
)

lines = sorted(f" [`{name}`]({url})" for name, url in self.base_urls.items())
lines = sorted(f"- [`{name}`]({url})" for name, url in self.base_urls.items())
if self.base_urls:
await LinePaginator.paginate(lines, ctx, inventory_embed, max_size=400, empty=False)

Expand Down
2 changes: 1 addition & 1 deletion bot/exts/info/patreon.py
Expand Up @@ -77,7 +77,7 @@ async def send_current_supporters(self, channel: discord.abc.Messageable, automa

# Filter out any members where this is not their highest tier.
patrons = [member for member in role.members if get_patreon_tier(member) == tier]
patron_names = [f" {patron}" for patron in patrons]
patron_names = [f"- {patron}" for patron in patrons]

embed = discord.Embed(
title=role.name,
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/moderation/voice_gate.py
Expand Up @@ -181,7 +181,7 @@ async def voice_verify(self, ctx: Context, *_) -> None:
if failed:
embed = discord.Embed(
title="Voice Gate failed",
description=FAILED_MESSAGE.format(reasons="\n".join(f" You {reason}." for reason in failed_reasons)),
description=FAILED_MESSAGE.format(reasons="\n".join(f"- You {reason}." for reason in failed_reasons)),
color=Colour.red()
)
try:
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/moderation/watchchannels/_watchchannel.py
Expand Up @@ -353,7 +353,7 @@ async def prepare_watched_users_data(
list_data["info"] = {}
for user_id, user_data in watched_iter:
member = await get_or_fetch_member(ctx.guild, user_id)
line = f" `{user_id}`"
line = f"- `{user_id}`"
if member:
line += f" ({member.name}#{member.discriminator})"
inserted_at = user_data["inserted_at"]
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/recruitment/talentpool/_cog.py
Expand Up @@ -279,7 +279,7 @@ async def list_nominations(
return ["*None*"]

for nomination in nominations:
line = f" `{nomination.user_id}`"
line = f"- `{nomination.user_id}`"

member = await get_or_fetch_member(ctx.guild, nomination.user_id)
if member:
Expand Down
8 changes: 4 additions & 4 deletions bot/resources/tags/args-kwargs.md
Expand Up @@ -11,9 +11,9 @@ These special parameters allow functions to take arbitrary amounts of positional
`**kwargs` will ingest an arbitrary amount of **keyword arguments**, and store it in a dictionary. There can be **no** additional parameters **after** `**kwargs` in the parameter list.

**Use cases**
**Decorators** (see `/tag decorators`)
**Inheritance** (overriding methods)
**Future proofing** (in the case of the first two bullet points, if the parameters change, your code won't break)
**Flexibility** (writing functions that behave like `dict()` or `print()`)
- **Decorators** (see `/tag decorators`)
- **Inheritance** (overriding methods)
- **Future proofing** (in the case of the first two bullet points, if the parameters change, your code won't break)
- **Flexibility** (writing functions that behave like `dict()` or `print()`)

*See* `/tag positional-keyword` *for information about positional and keyword arguments*
10 changes: 5 additions & 5 deletions bot/resources/tags/blocking.md
Expand Up @@ -19,8 +19,8 @@ async def ping(ctx):
A blocking operation is wherever you do something without `await`ing it. This tells Python that this step must be completed before it can do anything else. Common examples of blocking operations, as simple as they may seem, include: outputting text, adding two numbers and appending an item onto a list. Most common Python libraries have an asynchronous version available to use in asynchronous contexts.

**`async` libraries**
The standard async library - `asyncio`
Asynchronous web requests - `aiohttp`
Talking to PostgreSQL asynchronously - `asyncpg`
MongoDB interactions asynchronously - `motor`
Check out [this](https://github.com/timofurrer/awesome-asyncio) list for even more!
- The standard async library - `asyncio`
- Asynchronous web requests - `aiohttp`
- Talking to PostgreSQL asynchronously - `asyncpg`
- MongoDB interactions asynchronously - `motor`
- Check out [this](https://github.com/timofurrer/awesome-asyncio) list for even more!
6 changes: 3 additions & 3 deletions bot/resources/tags/contribute.md
Expand Up @@ -5,9 +5,9 @@ embed:
Looking to contribute to Open Source Projects for the first time? Want to add a feature or fix a bug on the bots on this server? We have on-going projects that people can contribute to, even if you've never contributed to open source before!

**Projects to Contribute to**
[Sir Lancebot](https://github.com/python-discord/sir-lancebot) - our fun, beginner-friendly bot
[Python](https://github.com/python-discord/bot) - our utility & moderation bot
[Site](https://github.com/python-discord/site) - resources, guides, and more
- [Sir Lancebot](https://github.com/python-discord/sir-lancebot) - our fun, beginner-friendly bot
- [Python](https://github.com/python-discord/bot) - our utility & moderation bot
- [Site](https://github.com/python-discord/site) - resources, guides, and more

**Where to start**
1. Read our [contribution guide](https://pythondiscord.com/pages/guides/pydis-guides/contributing/)
Expand Down
4 changes: 2 additions & 2 deletions bot/resources/tags/decorators.md
Expand Up @@ -29,5 +29,5 @@ Finished!
```

More information:
[Corey Schafer's video on decorators](https://youtu.be/FsAPt_9Bf3U)
[Real python article](https://realpython.com/primer-on-python-decorators/)
- [Corey Schafer's video on decorators](https://youtu.be/FsAPt_9Bf3U)
- [Real python article](https://realpython.com/primer-on-python-decorators/)
10 changes: 5 additions & 5 deletions bot/resources/tags/environments.md
Expand Up @@ -18,12 +18,12 @@ If Python's `sys.executable` doesn't match pip's, then they are currently using

**Why use a virtual environment?**

Resolve dependency issues by allowing the use of different versions of a package for different projects. For example, you could use Package A v2.7 for Project X and Package A v1.3 for Project Y.
Make your project self-contained and reproducible by capturing all package dependencies in a requirements file. Try running `pip freeze` to see what you currently have installed!
Keep your global `site-packages/` directory tidy by removing the need to install packages system-wide which you might only need for one project.
- Resolve dependency issues by allowing the use of different versions of a package for different projects. For example, you could use Package A v2.7 for Project X and Package A v1.3 for Project Y.
- Make your project self-contained and reproducible by capturing all package dependencies in a requirements file. Try running `pip freeze` to see what you currently have installed!
- Keep your global `site-packages/` directory tidy by removing the need to install packages system-wide which you might only need for one project.


**Further reading:**

[Python Virtual Environments: A Primer](https://realpython.com/python-virtual-environments-a-primer)
[pyenv: Simple Python Version Management](https://github.com/pyenv/pyenv)
- [Python Virtual Environments: A Primer](https://realpython.com/python-virtual-environments-a-primer)
- [pyenv: Simple Python Version Management](https://github.com/pyenv/pyenv)
4 changes: 2 additions & 2 deletions bot/resources/tags/foo.md
Expand Up @@ -8,5 +8,5 @@ Common examples include `foobar`, `foo`, `bar`, `baz`, and `qux`.
Python has its own metasyntactic variables, namely `spam`, `eggs`, and `bacon`. This is a reference to a [Monty Python](https://en.wikipedia.org/wiki/Monty_Python) sketch (the eponym of the language).

More information:
[History of foobar](https://en.wikipedia.org/wiki/Foobar)
[Monty Python sketch](https://en.wikipedia.org/wiki/Spam_%28Monty_Python%29)
- [History of foobar](https://en.wikipedia.org/wiki/Foobar)
- [Monty Python sketch](https://en.wikipedia.org/wiki/Spam_%28Monty_Python%29)
6 changes: 3 additions & 3 deletions bot/resources/tags/if-name-main.md
Expand Up @@ -23,6 +23,6 @@ If you run this module named `bar.py`, it will execute the code in `foo.py`. Fir

**Why would I do this?**

Your module is a library, but also has a special case where it can be run directly
Your module is a library and you want to safeguard it against people running it directly (like what `pip` does)
Your module is the main program, but has unit tests and the testing framework works by importing your module, and you want to avoid having your main code run during the test
- Your module is a library, but also has a special case where it can be run directly
- Your module is a library and you want to safeguard it against people running it directly (like what `pip` does)
- Your module is the main program, but has unit tests and the testing framework works by importing your module, and you want to avoid having your main code run during the test
4 changes: 2 additions & 2 deletions bot/resources/tags/mutable-default-args.md
Expand Up @@ -44,7 +44,7 @@ function is **called**:

**Note**:

This behavior can be used intentionally to maintain state between
- This behavior can be used intentionally to maintain state between
calls of a function (eg. when writing a caching function).
This behavior is not unique to mutable objects, all default
- This behavior is not unique to mutable objects, all default
arguments are evaulated only once when the function is defined.
14 changes: 7 additions & 7 deletions bot/resources/tags/names.md
Expand Up @@ -26,14 +26,14 @@ y ━━ 1
```
**Names are created in multiple ways**
You might think that the only way to bind a name to an object is by using assignment, but that isn't the case. All of the following work exactly the same as assignment:
`import` statements
`class` and `def`
`for` loop headers
`as` keyword when used with `except`, `import`, and `with`
formal parameters in function headers
- `import` statements
- `class` and `def`
- `for` loop headers
- `as` keyword when used with `except`, `import`, and `with`
- formal parameters in function headers

There is also `del` which has the purpose of *unbinding* a name.

**More info**
Please watch [Ned Batchelder's talk](https://youtu.be/_AEJHKGk9ns) on names in python for a detailed explanation with examples
[Official documentation](https://docs.python.org/3/reference/executionmodel.html#naming-and-binding)
- Please watch [Ned Batchelder's talk](https://youtu.be/_AEJHKGk9ns) on names in python for a detailed explanation with examples
- [Official documentation](https://docs.python.org/3/reference/executionmodel.html#naming-and-binding)
4 changes: 2 additions & 2 deletions bot/resources/tags/nomodule.md
Expand Up @@ -8,8 +8,8 @@ You can read about Python environments at `/tag environments` and `/tag venv`.

Common causes of this problem include:

You installed your package using `pip install ...`. It could be that the `pip` command is not pointing to the environment where your code runs. For greater control, you could instead run pip as a module within the python environment you specify:
- You installed your package using `pip install ...`. It could be that the `pip` command is not pointing to the environment where your code runs. For greater control, you could instead run pip as a module within the python environment you specify:
```
python -m pip install <your_package>
```
Your editor/ide is configured to create virtual environments automatically (PyCharm is configured this way by default).
- Your editor/ide is configured to create virtual environments automatically (PyCharm is configured this way by default).
6 changes: 3 additions & 3 deletions bot/resources/tags/off-topic-names.md
Expand Up @@ -3,9 +3,9 @@ embed:
title: "Off-topic channels"
---
There are three off-topic channels:
<#291284109232308226>
<#463035241142026251>
<#463035268514185226>
- <#291284109232308226>
- <#463035241142026251>
- <#463035268514185226>

The channel names change every night at midnight UTC and are often fun meta references to jokes or conversations that happened on the server.

Expand Down
16 changes: 8 additions & 8 deletions bot/resources/tags/open.md
Expand Up @@ -5,9 +5,9 @@ embed:
The built-in function `open()` is one of several ways to open files on your computer. It accepts many different parameters, so this tag will only go over two of them (`file` and `mode`). For more extensive documentation on all these parameters, consult the [official documentation](https://docs.python.org/3/library/functions.html#open). The object returned from this function is a [file object or stream](https://docs.python.org/3/glossary.html#term-file-object), for which the full documentation can be found [here](https://docs.python.org/3/library/io.html#io.TextIOBase).

See also:
`!tags with` for information on context managers
`!tags pathlib` for an alternative way of opening files
`!tags seek` for information on changing your position in a file
- `!tags with` for information on context managers
- `!tags pathlib` for an alternative way of opening files
- `!tags seek` for information on changing your position in a file

**The `file` parameter**

Expand All @@ -21,8 +21,8 @@ See `!tags relative-path` for more information on relative paths.

This is an optional string that specifies the mode in which the file should be opened. There's not enough room to discuss them all, but listed below are some of the more confusing modes.

`'r+'` Opens for reading and writing (file must already exist)
`'w+'` Opens for reading and writing and truncates (can create files)
`'x'` Creates file and opens for writing (file must **not** already exist)
`'x+'` Creates file and opens for reading and writing (file must **not** already exist)
`'a+'` Opens file for reading and writing at **end of file** (can create files)
- `'r+'` Opens for reading and writing (file must already exist)
- `'w+'` Opens for reading and writing and truncates (can create files)
- `'x'` Creates file and opens for writing (file must **not** already exist)
- `'x+'` Creates file and opens for reading and writing (file must **not** already exist)
- `'a+'` Opens file for reading and writing at **end of file** (can create files)
24 changes: 12 additions & 12 deletions bot/resources/tags/pathlib.md
Expand Up @@ -6,18 +6,18 @@ Python 3 comes with a new module named `Pathlib`. Since Python 3.6, `pathlib.Pat

**Feature spotlight**:

Normalizes file paths for all platforms automatically
Has glob-like utilites (eg. `Path.glob`, `Path.rglob`) for searching files
Can read and write files, and close them automatically
Convenient syntax, utilising the `/` operator (e.g. `Path('~') / 'Documents'`)
Can easily pick out components of a path (eg. name, parent, stem, suffix, anchor)
Supports method chaining
Move and delete files
And much more
- Normalizes file paths for all platforms automatically
- Has glob-like utilites (eg. `Path.glob`, `Path.rglob`) for searching files
- Can read and write files, and close them automatically
- Convenient syntax, utilising the `/` operator (e.g. `Path('~') / 'Documents'`)
- Can easily pick out components of a path (eg. name, parent, stem, suffix, anchor)
- Supports method chaining
- Move and delete files
- And much more

**More Info**:

[**Why you should use pathlib** - Trey Hunner](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
[**Answering concerns about pathlib** - Trey Hunner](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
[**Official Documentation**](https://docs.python.org/3/library/pathlib.html)
[**PEP 519** - Adding a file system path protocol](https://peps.python.org/pep-0519/)
- [**Why you should use pathlib** - Trey Hunner](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
- [**Answering concerns about pathlib** - Trey Hunner](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
- [**Official Documentation**](https://docs.python.org/3/library/pathlib.html)
- [**PEP 519** - Adding a file system path protocol](https://peps.python.org/pep-0519/)
4 changes: 2 additions & 2 deletions bot/resources/tags/pep8.md
Expand Up @@ -5,5 +5,5 @@ embed:
**PEP 8** is the official style guide for Python. It includes comprehensive guidelines for code formatting, variable naming, and making your code easy to read. Professional Python developers are usually required to follow the guidelines, and will often use code-linters like flake8 to verify that the code they're writing complies with the style guide.

More information:
[PEP 8 document](https://peps.python.org/pep-0008/)
[Our PEP 8 song!](https://www.youtube.com/watch?v=hgI0p1zf31k) :notes:
- [PEP 8 document](https://peps.python.org/pep-0008/)
- [Our PEP 8 song!](https://www.youtube.com/watch?v=hgI0p1zf31k) :notes:
6 changes: 3 additions & 3 deletions bot/resources/tags/positional-keyword.md
Expand Up @@ -35,6 +35,6 @@ The reverse is also true:
```

**More info**
[Keyword only arguments](https://peps.python.org/pep-3102/)
[Positional only arguments](https://peps.python.org/pep-0570/)
`/tag param-arg` (Parameters vs. Arguments)
- [Keyword only arguments](https://peps.python.org/pep-3102/)
- [Positional only arguments](https://peps.python.org/pep-0570/)
- `/tag param-arg` (Parameters vs. Arguments)
4 changes: 2 additions & 2 deletions bot/resources/tags/quotes.md
Expand Up @@ -18,5 +18,5 @@ Example:
If you need both single and double quotes inside your string, use the version that would result in the least amount of escapes. In the case of a tie, use the quotation you use the most.

**References:**
[pep-8 on quotes](https://peps.python.org/pep-0008/#string-quotes)
[convention for triple quoted strings](https://peps.python.org/pep-0257/)
- [pep-8 on quotes](https://peps.python.org/pep-0008/#string-quotes)
- [convention for triple quoted strings](https://peps.python.org/pep-0257/)

0 comments on commit d4fdbce

Please sign in to comment.