-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from acmcsufoss/wip
Shorter: Discord application command
- Loading branch information
Showing
18 changed files
with
871 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Required: | ||
DISCORD_PUBLIC_KEY="" | ||
DISCORD_CLIENT_ID="" | ||
DISCORD_TOKEN="" | ||
DISCORD_ROLE_ID="" | ||
GITHUB_TOKEN="" | ||
|
||
# Optional: | ||
PORT="8080" |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: check | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
deno-version: [canary] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: ${{ matrix.deno-version }} | ||
|
||
- run: deno lint && git diff-index --quiet HEAD | ||
- run: deno fmt && git diff-index --quiet HEAD |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
ngrok.exe |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"deno.enable": true, | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"[typescript]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
Version 2, December 2004 | ||
|
||
Copyright (C) 2004 Sam Hocevar <[email protected]> | ||
|
||
Everyone is permitted to copy and distribute verbatim or modified | ||
copies of this license document, and changing it is allowed as long | ||
as the name is changed. | ||
|
||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
|
||
0. You just DO WHAT THE FUCK YOU WANT TO. |
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,2 +1,109 @@ | ||
# shorter | ||
|
||
🔗 Discord slash command URL shortener. | ||
|
||
## Development | ||
|
||
### Run the server | ||
|
||
> **NOTE** | ||
> | ||
> Be sure to set the environment variables before running the server. | ||
> | ||
> Be sure to [install Deno](https://deno.land/install) before running the | ||
> server. | ||
You will need to use two terminal windows; one for the HTTP server and one for | ||
Ngrok. | ||
|
||
#### Terminal 1 | ||
|
||
To run the server, run the following command: | ||
|
||
```bash | ||
deno task start | ||
``` | ||
|
||
#### Terminal 2 | ||
|
||
> **NOTE** You will need to have | ||
> [Ngrok](https://dashboard.ngrok.com/get-started/setup) installed and in your | ||
> path. | ||
```bash | ||
deno task ngrok | ||
``` | ||
|
||
In **Terminal 2**, copy the URL that is generated under **Forwarding**. | ||
|
||
- The URL should look similar to this: | ||
`https://ab01-23-456-78-910.ngrok-free.app` | ||
|
||
Set this new URL as the **Interactions Endpoint URL** in the **General** tab of | ||
your Discord application. Find your application | ||
[here](https://discord.com/developers/applications). | ||
|
||
### Deploy | ||
|
||
This server is deployed on [Deno Deploy](https://deno.com/deploy). To deploy, | ||
set the entrypoint file to `main.ts` and set the environment variables in the | ||
Deno Deploy dashboard. | ||
|
||
### Slash command usage | ||
|
||
To understand the usage of the slash command, refer to the source code in | ||
[`bot/app/app.ts`](bot/app/app.ts). | ||
|
||
### Discord Application Command setup | ||
|
||
1. [Create a Discord application](https://discord.com/developers/applications). | ||
1. Create a bot for the application. | ||
1. Copy the bot token and set it as the `DISCORD_TOKEN` environment variable. | ||
1. Copy the public key and set it as the `DISCORD_PUBLIC_KEY` environment | ||
variable. | ||
1. Copy the client ID and set it as the `DISCORD_CLIENT_ID` environment | ||
variable. | ||
1. Spin up the server. Set the Discord interactions endpoint URL to the URL of | ||
the server (Ngrok or Deno Deploy). | ||
|
||
### Environment variables | ||
|
||
Refer to `.env.example` for a list of environment variables that need to be set. | ||
|
||
#### `DISCORD_PUBLIC_KEY` | ||
|
||
The public key of the Discord application. This is used to verify that the | ||
request is coming from Discord. | ||
|
||
#### `DISCORD_CLIENT_ID` | ||
|
||
The client ID of the Discord application. This is used to generate the OAuth2 | ||
URL. | ||
|
||
#### `DISCORD_TOKEN` | ||
|
||
The bot token of the Discord application. | ||
|
||
#### `DISCORD_ROLE_ID` | ||
|
||
The ID of the role that is allowed to use the slash command. Board members are | ||
intended to use this command. | ||
|
||
#### `GITHUB_TOKEN` | ||
|
||
The GitHub personal access token. This is used to access the GitHub API via | ||
[Codemod](https://deno.land/x/codemod). | ||
|
||
#### `PORT` | ||
|
||
**Not required**. The port that the server will listen on. | ||
|
||
#### `DEV` | ||
|
||
**Not required**. If set to `true`, the server will spin up an Ngrok tunnel and | ||
print the URL to the console. This is intended for development. Paste this URL | ||
into the Discord application's Discord interactions endpoint URL. | ||
|
||
--- | ||
|
||
Programmed with ❤️ by [**@acmcsufoss**](https://oss.acmcsuf.com/). |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { discord } from "../deps.ts"; | ||
|
||
export const SHORTER = "shorter"; | ||
export const SHORTER_DESCRIPTION = "Manage acmcsuf.com shortlinks."; | ||
|
||
export const SHORTER_ALIAS = "alias"; | ||
export const SHORTER_ALIAS_DESCRIPTION = | ||
"The alias of the shortlink (e.g. `discord`, `example/a/b/c`, etc.)."; | ||
|
||
export const SHORTER_DESTINATION = "destination"; | ||
export const SHORTER_DESTINATION_DESCRIPTION = | ||
"The destination of the shortlink."; | ||
|
||
/** | ||
* APP_SHORTER is the top-level command for the Shorter Application Command. | ||
*/ | ||
export const APP_SHORTER: discord.RESTPostAPIApplicationCommandsJSONBody = { | ||
type: discord.ApplicationCommandType.ChatInput, | ||
name: SHORTER, | ||
description: SHORTER_DESCRIPTION, | ||
options: [ | ||
{ | ||
type: discord.ApplicationCommandOptionType.String, | ||
name: SHORTER_ALIAS, | ||
description: SHORTER_ALIAS_DESCRIPTION, | ||
required: true, | ||
}, | ||
{ | ||
type: discord.ApplicationCommandOptionType.String, | ||
name: SHORTER_DESTINATION, | ||
description: SHORTER_DESTINATION_DESCRIPTION, | ||
required: true, | ||
}, | ||
], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./app.ts"; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"lock": "./deno.lock", | ||
"tasks": { | ||
"udd": "deno run -r --allow-read=. --allow-write=. --allow-net https://deno.land/x/udd/main.ts deps.ts && deno task lock", | ||
"lock": "deno cache --lock=deno.lock --lock-write deps.ts", | ||
"all": "deno task udd && deno task lint && deno task fmt", | ||
"start": "deno run -A main.ts", | ||
"ngrok": "ngrok http 8080" | ||
} | ||
} |
Oops, something went wrong.