Skip to content

Commit

Permalink
add contribution guide
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev committed Apr 16, 2024
1 parent 7858c95 commit 8ba47b2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 14 deletions.
81 changes: 81 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Contributing

## Table of Contents

- [Getting Started](#getting-started)
- [Installation](#installation)
- [Environment Setup](#environment-setup)
- [Running the Bot](#running-the-bot)
- [Adding Commands](#adding-commands)
- [Submitting Changes](#submitting-changes)

## Getting Started

### Installation

If you haven't already, install [Node.js](https://nodejs.org) with a version no less than `20.11.0`.

Afterwards, install `pnpm` by running `corepack enable`.

[Corepack](https://nodejs.org/api/corepack.html#corepack) is a tool that manages package managers, and comes bundled with Node.js.

Then, install the needed dependencies with `pnpm install --frozen-lockfile`.

### Environment Setup

First, create an application on the [Discord Developer Portal](https://discord.com/developers/applications).

It will be a used as a test application for development purposes of the bot.

Then, create a `.env` file at the root of the project with the following variables obtained from the dev portal:

```env
APPLICATION_ID=
DISCORD_TOKEN=
PUBLIC_KEY=
```

### Running the Bot

Make sure you run the `deploy-commands` script before you start! It updates the command list on Discord.

You can do that by running `pnpm deploy-commands`.

Once that's done, you can run the bot locally with `pnpm dev`.

You need to forward the port used, and specify it in the dev portal as the interactions endpoint URL.

## Adding Commands

Create a new file in the `src/commands` directory, with the following structure (you can use this as a template):

```ts
import { SlashCommandBuilder } from '@discordjs/builders';
import { type APIApplicationCommandInteraction, InteractionResponseType } from 'discord-api-types/v10';
import { reply } from '../reply.js';

export async function onXSlashCommand(interaction: APIApplicationCommandInteraction) {
return reply(InteractionResponseType.ChannelMessageWithSource, {
content: 'you just ran the test command. good job',
});
}

export const slashCommandData = new SlashCommandBuilder()
.setName('replace-me')
.setDescription('replace this too');
```

Rename the onXSlashCommand function to match the command name (i.e. `onTestSlashCommand` for a command named `test`),
and replace the placeholder text in the builder.

Then, import the command in `src/commands/index.ts` and add it to the switch statement in the handleInteraction function.

Remember to run `pnpm deploy-commands` after adding a new command, to update the command list on Discord.

## Submitting Changes

When you're ready to submit your changes, make sure to run `pnpm check` and `pnpm typecheck` to ensure everything is in order.

Then, create a [pull request](https://github.com/biomejs/discord-utils-bot/pulls).

Once the PR is approved, it will be merged and deployed to the production bot.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

Util bot for the Biome Discord server. [WIP]

## Deploying
## Contributing

Make sure you run the `deploy-commands` script before deploying! It updates the command list on Discord.

It needs a `.env` file at the root of the project, with `APPLICATION_ID` and `DISCORD_TOKEN` variables.

When you're done running the script, go ahead and run `pnpm run deploy` to instantly deploy your changes to Cloudflare.
Check out [`CONTRIBUTING.md`](CONTRIBUTING.md) information on how to contribute.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"type": "module",
"license": "MIT OR Apache-2.0",
"scripts": {
"format": "biome format --write .",
"check": "biome check .",
"check:apply": "biome check --apply-unsafe .",
"typecheck": "tsc",
"dev": "wrangler dev",
"start": "wrangler dev",
"deploy": "wrangler deploy",
"deploy-commands": "tsx --env-file=.env scripts/deploy-commands.ts",
"dev": "wrangler dev",
"start": "wrangler dev"
"check": "biome check .",
"check:apply": "biome check --apply-unsafe .",
"format": "biome format --write .",
"typecheck": "tsc"
},
"devDependencies": {
"@biomejs/biome": "^1.7.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { onTestSlashCommand } from './commands/test.js';
import { reply } from './reply.js';
import { isChatInputCommand, isMessageComponent, isPing } from './typeguards.js';
export type Env = {
publicKey: string;
PUBLIC_KEY: string;
};

export default {
Expand All @@ -17,7 +17,7 @@ export default {
}

// Check if the request is valid
const isValid = await isValidRequest(request, env.publicKey, PlatformAlgorithm.Cloudflare).catch(() => false);
const isValid = await isValidRequest(request, env.PUBLIC_KEY, PlatformAlgorithm.Cloudflare).catch(() => false);
if (!isValid) {
return new Response('Invalid signature', { status: 401 });
}
Expand Down

0 comments on commit 8ba47b2

Please sign in to comment.