Skip to content

Commit b7f3e6f

Browse files
authored
feat(github): Add pre-commit config. (#19)
* feat: Add .pre-commit-config.yaml * chore: Run pre-commit * chore: Run workflow on all branches * chore: Cache npm dependencies * chore: Don't keep gh-pages branch history on deploy * chore: Run pre-commit in GitHub workflow
1 parent 6a81b18 commit b7f3e6f

31 files changed

+668
-591
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ insert_final_newline = true
1010
trim_trailing_whitespace = true
1111

1212
[*.mdx]
13-
trim_trailing_whitespace = false
13+
trim_trailing_whitespace = false

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
*.mdx linguist-language=javascript
1+
*.mdx linguist-language=javascript

.github/ISSUE_TEMPLATE/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ contact_links:
55
url: https://discord.gg/gJDbCw8aQy
66
- name: disnake issues
77
about: Issue tracker for the disnake library.
8-
url: https://github.com/DisnakeDev/disnake/issues/new/choose
8+
url: https://github.com/DisnakeDev/disnake/issues/new/choose

.github/ISSUE_TEMPLATE/page_addition.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ body:
3737
- Yes, I will be contributing this addition.
3838
- No, I am only suggesting this addition.
3939
validations:
40-
required: true
40+
required: true

.github/ISSUE_TEMPLATE/typo_grammar.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ body:
4040
- type: textarea
4141
attributes:
4242
label: Additional context
43-
description: If any extra information is required, mention the same here.
43+
description: If any extra information is required, mention the same here.

.github/pull_request_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ We highly recommend linking to an issue that has been approved by a maintainer,
1212
This is important, as a topic that is not approved by a maintainer may not be added.
1313
1414
Link the issue by typing: "Closes #<number>" (e.g. "Closes #0" to close issue 0).
15-
-->
15+
-->

.github/workflows/site-deploy.yml

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: Deploy to GitHub Pages
22

33
on:
44
push:
5-
branches: [master]
65
paths:
76
- guide/**
87
- package*.json
@@ -18,15 +17,28 @@ jobs:
1817
with:
1918
node-version: 14.x
2019
cache: npm
20+
- name: Run pre-commit
21+
uses: pre-commit/[email protected]
22+
23+
- name: Cache npm
24+
uses: actions/cache@v2
25+
with:
26+
path: ~/.npm
27+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
28+
restore-keys: |
29+
${{ runner.os }}-node-
2130
- name: Build website
2231
working-directory: guide
2332
run: |
2433
npm ci
2534
npm run build
35+
2636
- name: Deploy to GitHub Pages
37+
if: github.ref == 'refs/heads/master'
2738
uses: peaceiris/actions-gh-pages@v3
2839
with:
2940
github_token: ${{ secrets.GITHUB_TOKEN }}
3041
publish_dir: ./guide/build
3142
user_name: 'github-actions[bot]'
3243
user_email: 'github-actions[bot]@users.noreply.github.com'
44+
force_orphan: true

.pre-commit-config.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: check-case-conflict
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
args: ['--markdown-linebreak-ext=md,mdx']
9+
# for code in .md files
10+
# (patched with support for codeblock options and `py` shortcodes)
11+
- repo: https://github.com/shiftinv/blacken-docs
12+
rev: 161c8eff80b7e1dc388151974aa5ab9010741e09
13+
hooks:
14+
- id: blacken-docs
15+
additional_dependencies: [black==21.12b0]
16+
files: '\.(rst|md|markdown|mdx|py|tex)$'
17+
args: [--line-length=100]
18+
# for code samples
19+
- repo: https://github.com/psf/black
20+
rev: 21.12b0
21+
hooks:
22+
- id: black
23+
args: [--line-length=100]
24+
# for markdown formatting
25+
- repo: https://github.com/pre-commit/mirrors-prettier
26+
rev: v2.5.1
27+
hooks:
28+
- id: prettier
29+
types_or: [html, css, javascript, markdown, mdx]
30+
args: [--print-width=120, --tab-width=4, --prose-wrap=always, --single-quote]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ For more info on development/contributions, see [CONTRIBUTING.md](./CONTRIBUTING
4141
4242
<a href="https://discord.gg/discord-api">Discord API</a>
4343
</p>
44-
<br />
44+
<br />

guide/babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
33
};

guide/docs/faq/good-practices.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ keywords: [disnake, bot, guide, tutorial, good practices, python]
66
# Good practices
77

88
<!-- Imports for content tabs -->
9+
910
import Tabs from '@theme/Tabs';
1011
import TabItem from '@theme/TabItem';
1112

guide/docs/getting-started/creating-commands.mdx

+60-39
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ keywords: [disnake, bot, guide, tutorial, creating, commands, python]
66
# Creating commands
77

88
<!-- Import Discord components -->
9+
910
import {
1011
DiscordButton,
1112
DiscordButtons,
@@ -25,13 +26,16 @@ import isDarkTheme from '../../src/hooks/isDarkTheme';
2526

2627
:::info
2728

28-
This page is a follow-up, and the base code used is from the previous page ([Initial files](./initial-files.mdx)). The code can be found on the GitHub repository [here](https://github.com/DisnakeDev/guide/tree/master/docs/extra-code-samples/code-intial-files).
29+
This page is a follow-up, and the base code used is from the previous page ([Initial files](./initial-files.mdx)). The
30+
code can be found on the GitHub repository
31+
[here](https://github.com/DisnakeDev/guide/tree/master/docs/extra-code-samples/code-intial-files).
2932

3033
:::
3134

32-
Discord also allows developers to register [slash commands](https://discord.com/developers/docs/interactions/application-commands), which
33-
provides users a first-class way of interacting directly with your application. These slash commands shall be covered by
34-
the guide [here](../interactions/application-commands.mdx), in the **Interactions** section.
35+
Discord also allows developers to register
36+
[slash commands](https://discord.com/developers/docs/interactions/application-commands), which provides users a
37+
first-class way of interacting directly with your application. These slash commands shall be covered by the guide
38+
[here](../interactions/application-commands.mdx), in the **Interactions** section.
3539

3640
## A note on prefix commands
3741

@@ -40,7 +44,9 @@ Bot commands that are initiated when a keyword is used along with a specified pr
4044

4145
:::caution Message Intent - Privileged
4246

43-
It is to be noted that handling prefix commands require the **message intent**, which allows the bot to get content and data of messages sent by users. This intent has recently been privileged, i.e., it needs to be manually enabled for the bot application, and its requirement will eventually be reviewed if your bot is in over 100 servers.
47+
It is to be noted that handling prefix commands require the **message intent**, which allows the bot to get content and
48+
data of messages sent by users. This intent has recently been privileged, i.e., it needs to be manually enabled for the
49+
bot application, and its requirement will eventually be reviewed if your bot is in over 100 servers.
4450

4551
You can read more about the message intent [here][message-intent-article].
4652

@@ -53,8 +59,8 @@ be covered in the [**Interactions**](../interactions/application-commands.mdx) s
5359
## Registering commands
5460

5561
This section covers the bare minimum to get you started with registering slash commands. Once again, you can refer to
56-
[this page](../interactions/application-commands.mdx) for an in-depth coverage of topics, including guild
57-
commands, global commands, options, option types, autocomplete and choices.
62+
[this page](../interactions/application-commands.mdx) for an in-depth coverage of topics, including guild commands,
63+
global commands, options, option types, autocomplete and choices.
5864

5965
Now, we shall continue with the base code used in the previous section.
6066

@@ -103,7 +109,11 @@ necessary for replying to the use of the command.
103109

104110
:::note Using `ctx` vs. `inter`
105111

106-
If you have experience with coding bots with [`discord.py`](https://discordpy.readthedocs.io/en/latest), you would be familiar with using `ctx` as an abbreviation for passing context into the function. This guide will primarily be using `inter`, as it is short for `interaction` and refers to [`disnake.ApplicationCommandInteraction`](https://docs.disnake.dev/en/latest/api.html#applicationcommandinteraction). Of course, you're open to using your preferred abbreviation in code.
112+
If you have experience with coding bots with [`discord.py`](https://discordpy.readthedocs.io/en/latest), you would be
113+
familiar with using `ctx` as an abbreviation for passing context into the function. This guide will primarily be using
114+
`inter`, as it is short for `interaction` and refers to
115+
[`disnake.ApplicationCommandInteraction`](https://docs.disnake.dev/en/latest/api.html#applicationcommandinteraction). Of
116+
course, you're open to using your preferred abbreviation in code.
107117

108118
:::
109119

@@ -141,9 +151,11 @@ bot.run("YOUR_BOT_TOKEN")
141151

142152
:::tip Using `test_guilds` in `commands.Bot()`
143153

144-
When you have multiple commands registered under the same test guilds, it is convenient to only have your `guild_ids` defined once. Therefore, you can use the `test_guilds` argument in the `commands.Bot()` instance instead of passing `guild_ids` to every single command -
154+
When you have multiple commands registered under the same test guilds, it is convenient to only have your `guild_ids`
155+
defined once. Therefore, you can use the `test_guilds` argument in the `commands.Bot()` instance instead of passing
156+
`guild_ids` to every single command -
145157

146-
``` python
158+
```python
147159
bot = commands.Bot(test_guilds=[1234, 5678])
148160
```
149161

@@ -178,21 +190,23 @@ bot.run("YOUR_BOT_TOKEN")
178190
```
179191

180192
<br />
181-
<DiscordMessages lightTheme={!isDarkTheme()}>
182-
<DiscordMessage author="Disnake Bot" avatar="/public/disnake-logo.png" bot="true">
183-
<div slot="interactions">
184-
<DiscordInteraction author="AbhigyanTrips" avatar="https://i.imgur.com/8xd9SHa.png" command="true">ping</DiscordInteraction>
185-
</div>
186-
Pong!
187-
</DiscordMessage>
193+
<DiscordMessages lightTheme={!isDarkTheme()}>
194+
<DiscordMessage author="Disnake Bot" avatar="/public/disnake-logo.png" bot="true">
195+
<div slot="interactions">
196+
<DiscordInteraction author="AbhigyanTrips" avatar="https://i.imgur.com/8xd9SHa.png" command="true">
197+
ping
198+
</DiscordInteraction>
199+
</div>
200+
Pong!
201+
</DiscordMessage>
188202
</DiscordMessages>
189203
<br />
190204

191205
### Server info command
192206

193207
`inter.guild` refers to the guild the interaction was sent in (a
194-
[`Guild`](https://docs.disnake.dev/en/latest/api.html#disnake.Guild) instance), which exposes properties such as `.name` or
195-
`.member_count`.
208+
[`Guild`](https://docs.disnake.dev/en/latest/api.html#disnake.Guild) instance), which exposes properties such as `.name`
209+
or `.member_count`.
196210

197211
```python title="main.py" {12-16}
198212
import disnake
@@ -217,20 +231,23 @@ bot.run("YOUR_BOT_TOKEN")
217231
```
218232

219233
<br />
220-
<DiscordMessages lightTheme={!isDarkTheme()}>
221-
<DiscordMessage author="Disnake Bot" avatar="/public/disnake-logo.png" bot="true">
222-
<div slot="interactions">
223-
<DiscordInteraction author="AbhigyanTrips" avatar="https://i.imgur.com/8xd9SHa.png" command="true">server</DiscordInteraction>
224-
</div>
225-
Server name: Disnake Guide <br />
226-
Total members: 2
227-
</DiscordMessage>
234+
<DiscordMessages lightTheme={!isDarkTheme()}>
235+
<DiscordMessage author="Disnake Bot" avatar="/public/disnake-logo.png" bot="true">
236+
<div slot="interactions">
237+
<DiscordInteraction author="AbhigyanTrips" avatar="https://i.imgur.com/8xd9SHa.png" command="true">
238+
server
239+
</DiscordInteraction>
240+
</div>
241+
Server name: Disnake Guide <br />
242+
Total members: 2
243+
</DiscordMessage>
228244
</DiscordMessages>
229245
<br />
230246

231247
:::tip
232248

233-
Refer to the [Guild](https://docs.disnake.dev/en/latest/api.html#disnake.Guild) documentation for a list of all the available properties and methods.
249+
Refer to the [Guild](https://docs.disnake.dev/en/latest/api.html#disnake.Guild) documentation for a list of all the
250+
available properties and methods.
234251

235252
:::
236253

@@ -241,8 +258,8 @@ same manner - use `inter.guild.created_at` or `inter.guild.verification_level`,
241258

242259
A "user" refers to a Discord user. `inter.author` refers to the user the interaction was sent by (a
243260
[User instance](https://docs.disnake.dev/en/latest/api.html#disnake.User) in DM contexts, or a
244-
[Member instance](https://docs.disnake.dev/en/latest/api.html#disnake.Member) in server contexts), which exposes properties
245-
such as `.name` or `.id`. (Using just `inter.author` will give the user's full tag.)
261+
[Member instance](https://docs.disnake.dev/en/latest/api.html#disnake.Member) in server contexts), which exposes
262+
properties such as `.name` or `.id`. (Using just `inter.author` will give the user's full tag.)
246263

247264
```python title="main.py" {12-14}
248265
import disnake
@@ -265,20 +282,24 @@ bot.run("YOUR_BOT_TOKEN")
265282
```
266283

267284
<br />
268-
<DiscordMessages lightTheme={!isDarkTheme()}>
269-
<DiscordMessage author="Disnake Bot" avatar="/public/disnake-logo.png" bot="true">
270-
<div slot="interactions">
271-
<DiscordInteraction author="AbhigyanTrips" avatar="https://i.imgur.com/8xd9SHa.png" command="true">server</DiscordInteraction>
272-
</div>
273-
Your tag: AbhigyanTrips#1234 <br />
274-
Your ID: 123456789012345678
275-
</DiscordMessage>
285+
<DiscordMessages lightTheme={!isDarkTheme()}>
286+
<DiscordMessage author="Disnake Bot" avatar="/public/disnake-logo.png" bot="true">
287+
<div slot="interactions">
288+
<DiscordInteraction author="AbhigyanTrips" avatar="https://i.imgur.com/8xd9SHa.png" command="true">
289+
server
290+
</DiscordInteraction>
291+
</div>
292+
Your tag: AbhigyanTrips#1234 <br />
293+
Your ID: 123456789012345678
294+
</DiscordMessage>
276295
</DiscordMessages>
277296
<br />
278297

279298
:::tip
280299

281-
Refer to the [`User`](https://docs.disnake.dev/en/latest/api.html#disnake.User) and [`Member`](https://docs.disnake.dev/en/latest/api.html#disnake.Member) documentation for a list of all the available properties and methods.
300+
Refer to the [`User`](https://docs.disnake.dev/en/latest/api.html#disnake.User) and
301+
[`Member`](https://docs.disnake.dev/en/latest/api.html#disnake.Member) documentation for a list of all the available
302+
properties and methods.
282303

283304
:::
284305

0 commit comments

Comments
 (0)