Skip to content

Commit 9256f2a

Browse files
Merge pull request #21 from Real-Dev-Squad/develop
Sync Dev to main
2 parents e5aded1 + 9ccb5c9 commit 9256f2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+13102
-2
lines changed

.eslintrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": ["@typescript-eslint"],
5+
"extends": [
6+
"eslint:recommended",
7+
"plugin:@typescript-eslint/eslint-recommended",
8+
"plugin:@typescript-eslint/recommended"
9+
]
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: pre-merge-checks
2+
on:
3+
pull_request:
4+
branches: [main, develop]
5+
jobs:
6+
Lint-Check:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- run: npm install
11+
- run: npm run lint-check
12+
- run: npm run format-check
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: pre-merge-checks
2+
on:
3+
pull_request:
4+
branches: [main, develop]
5+
jobs:
6+
Run-Tests:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- run: npm install
11+
- run: npm test
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Register and deploy Slash Commands
2+
on:
3+
push:
4+
branches: main
5+
jobs:
6+
Register-Commands:
7+
runs-on: ubuntu-latest
8+
environment: production
9+
steps:
10+
- uses: actions/checkout@v2
11+
- run: npm install
12+
- run: npm run register
13+
env:
14+
DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}}
15+
DISCORD_APPLICATION_ID: ${{secrets.DISCORD_APPLICATION_ID}}
16+
DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}}
17+
Deploy-to-Cloudflare:
18+
needs: [Register-Commands]
19+
runs-on: ubuntu-latest
20+
environment: production
21+
steps:
22+
- uses: actions/checkout@v2
23+
- run: npm install
24+
- uses: cloudflare/[email protected]
25+
with:
26+
apiToken: ${{secrets.CLOUDFLARE_API_TOKEN}}
27+
accountId: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
28+
secrets: |
29+
DISCORD_PUBLIC_KEY
30+
DISCORD_TOKEN
31+
DISCORD_GUILD_ID
32+
CURRENT_ENVIRONMENT
33+
BOT_PRIVATE_KEY
34+
env:
35+
CURRENT_ENVIRONMENT: production
36+
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
37+
DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}}
38+
DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}}
39+
BOT_PRIVATE_KEY: ${{secrets.BOT_PRIVATE_KEY}}
40+
DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Register and deploy Slash Commands
2+
on:
3+
push:
4+
branches: develop
5+
jobs:
6+
Register-Commands:
7+
runs-on: ubuntu-latest
8+
environment: staging
9+
steps:
10+
- uses: actions/checkout@v2
11+
- run: npm install
12+
- run: npm run register
13+
env:
14+
DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}}
15+
DISCORD_APPLICATION_ID: ${{secrets.DISCORD_APPLICATION_ID}}
16+
DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}}
17+
Deploy-to-Cloudflare:
18+
needs: [Register-Commands]
19+
runs-on: ubuntu-latest
20+
environment: staging
21+
steps:
22+
- uses: actions/checkout@v2
23+
- run: npm install
24+
- uses: cloudflare/[email protected]
25+
with:
26+
apiToken: ${{secrets.CLOUDFLARE_API_TOKEN}}
27+
accountId: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
28+
secrets: |
29+
DISCORD_PUBLIC_KEY
30+
DISCORD_TOKEN
31+
DISCORD_GUILD_ID
32+
CURRENT_ENVIRONMENT
33+
BOT_PRIVATE_KEY
34+
env:
35+
CURRENT_ENVIRONMENT: staging
36+
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
37+
DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}}
38+
DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}}
39+
BOT_PRIVATE_KEY: ${{secrets.BOT_PRIVATE_KEY}}
40+
DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
node_modules/
3+
.env

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
coverage/

CONTRIBUTING.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Contributing to Real Dev Squad Discord Bot
2+
3+
- [Getting Started](#getting-started)
4+
- [Setting Up Local Development](#setting-up-local-development)
5+
6+
## Getting Started
7+
8+
To work on this project please create an account on Cloudflare and Discord.
9+
Also, create a personal discord server.
10+
Copy the guild id of your server and save it in a .env file as `DISCORD_GUILD_ID`
11+
12+
To get the server ID for the first parameter, open Discord, go to Settings > Advanced and enable developer mode.
13+
Then, right-click on the server title and select "Copy ID" to get the guild ID.
14+
15+
- Visit [Discord Developer Portal](https://discord.com/developers/applications)
16+
- Click on new application.
17+
18+
Gather the following details from the Developer portal and save it in a .env file.
19+
20+
```
21+
DISCORD_TOKEN: Available in bot panel of your discord bot after clicking reset token button.
22+
DISCORD_APPLICATION_ID: Available in general panel of your discord bot.
23+
DISCORD_PUBLIC_KEY: Available in general panel of your discord bot.
24+
```
25+
26+
Please set Following permissions for your bot:
27+
28+
- Navigate to OAuth2 > URL Generator
29+
- In scopes select `bot` and `applications.commands`
30+
- In Bot Permissions select
31+
- Manage Roles
32+
- Change Nickname
33+
- Manage Nicknames
34+
- Send messages
35+
- Create public threads
36+
- Create private threads
37+
- Send message in threads
38+
- Embed links
39+
- Mention Everyone
40+
- Use slash commands
41+
42+
After providing all the permissions you will get an url at the bottom of the page use that to invite the bot to your server.
43+
44+
Open the Url you get and invite the bot to your test server.
45+
46+
## Setting Up Local Development
47+
48+
- Clone the Repository to your machine
49+
- Now, get the .env file created above in the project folder
50+
- run `npm install`
51+
- Now, run the command `npm run register`
52+
53+
This will register all the commands to your discord bot.
54+
55+
Now let's link our local development server to our bot.
56+
57+
- After all the commands are installed we need to save few secrets in wrangler cli.
58+
- run command `wrangler secret put DISCORD_TOKEN` and then enter the value of your token.
59+
- run command `wrangler secret put DISCORD_PUBLIC_KEY` and enter the public key.
60+
- Now, start the local server with the command `npm start`
61+
- Once the wrangler starts make sure it is running on port `8787`
62+
- Once the server starts on desired port open another terminal and type in the command `npm run ngrok`
63+
- The above command will give you a `https` link copy that.
64+
- Now, go to [Discord Developer Portal](https://discord.com/developers/applications) and select your bot
65+
- In general information panel you will find a space for `INTERACTIONS ENDPOINT URL`
66+
- Enter the copied link here and hit save.
67+
68+
To verify if your bot is working:
69+
70+
- Go to the server where your bot was invited
71+
- run a /hello command and the bot should reply with `Hello <Your_username>`
72+
73+
Now you are ready to contribute to the Repository.

README.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,68 @@
1-
# website-template
2-
A template to create all public facing sites
1+
# Discord Slash Command
2+
3+
This is a discord bot for RealDevSquad discord server capable of using slash commands.
4+
5+
The bot is written in TypeScript and will be hosted on cloudflare workers. Cloudflare workers provide us with a serverless environment to run our code.
6+
7+
In case you are thinking of using any NPM package on it please check if it is compatible with the Cloudflare workers.
8+
You can do so by visiting the following link: https://workers.cloudflare.com/works
9+
10+
To get an example and look at runtime apis for cloudflare workers you can go to: https://developers.cloudflare.com/workers/runtime-apis
11+
12+
To start the server use
13+
14+
```
15+
npm start
16+
```
17+
18+
This will start your server on `localhost:8787`
19+
20+
To connect this to your own bot you need a https end point. To get a `https` endpoint that redirects all the traffic to your localhost, we are using `ngrok`
21+
22+
To start this, run the command
23+
24+
```
25+
npm run ngrok
26+
```
27+
28+
You can not commit your changes unless it satisfies the required format.
29+
To check the formatting of the file run
30+
31+
```
32+
npm run format-check
33+
```
34+
35+
To check the linting issues use
36+
37+
```
38+
npm run lint-check
39+
```
40+
41+
To fix the formatting issue use
42+
43+
```
44+
npm run format-fix
45+
```
46+
47+
We are using `itty-router` over here which is a light weight router designed for cloudflare workers.
48+
In case you are interested in it you could read more about it here:
49+
50+
- https://github.com/kwhitley/itty-router
51+
- https://developers.cloudflare.com/pages/tutorials/build-an-api-with-workers/
52+
53+
We need few environment variables for this project to work, they are as follows:
54+
55+
```
56+
DISCORD_TOKEN: The token generated for your bot while creating a discord application
57+
DISCORD_PUBLIC_KEY: Public key of your Discord bot helps to verify the bot and apply interaction url
58+
DISCORD_APPLICATION_ID: The application id of your bot.
59+
DISCORD_GUILD_ID: Id of the guild where you want to install the slash commands.
60+
```
61+
62+
To add more commands you need to modify following files:
63+
64+
```
65+
- src/constants/commands.ts (Export your commands as a constant)
66+
- src/register.ts (import the newly added command here and assign it to the commands array)
67+
- now run `npm run register`
68+
```

config/config.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { env, environment } from "../src/typeDefinitions/default.types";
2+
import {
3+
RDS_BASE_API_URL,
4+
RDS_BASE_STAGING_API_URL,
5+
RDS_BASE_DEVELOPMENT_API_URL,
6+
VERIFICATION_SITE_URL,
7+
STAGING_VERIFICATION_SITE_URL,
8+
} from "../src/constants/urls";
9+
10+
const config = (env: env) => {
11+
const environment: environment = {
12+
production: {
13+
RDS_BASE_API_URL: RDS_BASE_API_URL,
14+
VERIFICATION_SITE_URL: VERIFICATION_SITE_URL,
15+
},
16+
staging: {
17+
RDS_BASE_API_URL: RDS_BASE_STAGING_API_URL,
18+
VERIFICATION_SITE_URL: STAGING_VERIFICATION_SITE_URL,
19+
},
20+
default: {
21+
RDS_BASE_API_URL: RDS_BASE_DEVELOPMENT_API_URL,
22+
VERIFICATION_SITE_URL: STAGING_VERIFICATION_SITE_URL,
23+
},
24+
};
25+
26+
return environment[env.CURRENT_ENVIRONMENT] || environment.default;
27+
};
28+
29+
export default config;

0 commit comments

Comments
 (0)