Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hoonsubin committed Sep 22, 2021
0 parents commit 8d5b272
Show file tree
Hide file tree
Showing 25 changed files with 4,640 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.js
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
};
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
38 changes: 38 additions & 0 deletions .github/workflows/deploy_action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy to Server
# action trigger condition. You can read more from here <https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#on>
on:
push: # you can remove unused branch names
branches:
- 'main'
- 'master'
- 'release/*'
- 'production/*'
release: # triggers on all release events. Remove this if you're not using it
types: [published, created, edited]

jobs:
# build the source code
build:
name: Build Code
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: build
run: |
yarn
yarn build
working-directory: ./
# deploy the build
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to Server
run: echo "Please add the deploy behavior here"
38 changes: 38 additions & 0 deletions .github/workflows/pr_action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: PR Checks
on: [pull_request]

jobs:
run_tests:
name: Unit Tests
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: unit_test
run: |
yarn
yarn test
working-directory: ./
build_code:
name: Build Check
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: build
run: |
yarn
yarn build
working-directory: ./
149 changes: 149 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@

# Created by https://www.toptal.com/developers/gitignore/api/node,visualstudiocode,yarn
# Edit at https://www.toptal.com/developers/gitignore?templates=node,visualstudiocode,yarn

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist
build
lib

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

### yarn ###
# https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored

# .yarn/unplugged and .yarn/build-state.yml should likely always be ignored since
# they typically hold machine-specific build artifacts. Ignoring them might however
# prevent Zero-Installs from working (to prevent this, set enableScripts to false).
.yarn/unplugged
.yarn/build-state.yml

# .yarn/cache and .pnp.* may be safely ignored, but you'll need to run yarn install
# to regenerate them between each branch switch.
# Uncomment the following lines if you're not using Zero-Installs:
# .yarn/cache
# .pnp.*

.DS_Store

### Database ###
.db/*
!.db/.gitkeep

# End of https://www.toptal.com/developers/gitignore/api/node,visualstudiocode,yarn
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
semi: true,
trailingComma: "all",
singleQuote: true,
printWidth: 120,
tabWidth: 4,
};
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Hoon Kim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Discord Bot Starter Project

## Introduction

This is a Discord bot starter project made with [Discord.js](https://discord.js.org/) and TypeScript.
This template project comes with a simple ping-pong slash command for a predefined guild (server).

## Usage

### Creating a Discord Application

To create an application that can be registered to a Discord server, you must create a Discord app via the [Discord Developer Portal](https://discord.com/developers/applications).
Once you created an app, you can access the client ID from the `General Information` setting and the bot token from the `Bot` setting (see image below).

![client-id](https://user-images.githubusercontent.com/40356749/134047191-8ea55a38-f398-4021-b8dc-9f5aedbf7463.png)

![bot-token](https://user-images.githubusercontent.com/40356749/134047251-93424ac3-bb8a-42a7-9dad-5a3855395abe.png)

### Configuration

To start the bot server, you must provide the application credentials environmental variables.
You can do this by creating a `.env` file with the following variables.

```env
# Bot user app token
DISCORD_APP_TOKEN=<bot token>
# Bot user client ID
DISCORD_APP_CLIENT_ID=<bot client>
# Server ID for the bot to be installed
DISCORD_GUILD_ID=<guild id>
```

The `DISCORD_GUILD_ID` refers to the Discord server ID (or guild ID) that the bot will listen to.
You can configure the OAuth2 redirect URL to read and store the guild ID from a remote database when the user add the application to their server for public distribution.

`src/config/appConfig.json` contains the bot permission, scope, and slash commands.
The values must reflect the ones in the Discord Developer Portal app settings.

### Scripts

```bash
# install all the dependencies
yarn

# starts the server app in node.js environment
yarn start
# or you can use `yarn serve`

# starts a development server with ts-node
yarn dev

# transpile the project for production
yarn build
```

### Quick Start

After running `yarn dev`, open <http://localhost:8080/install> to install the application to your Discord server.

Go to a Discord channel that the bot has access to and type `/ping`.

![ping-command](https://user-images.githubusercontent.com/40356749/134050635-43de75ca-24ae-442c-8e9d-9aa75137e09f.png)

## Further Readings

For more information, please refer to the official Discord developer portal or the Discord.js documentation.

- <https://discord.com/developers/docs/intro>
- <https://discord.js.org/#/docs/main/stable/general/welcome>
- <https://discordjs.guide/#before-you-begin>
10 changes: 10 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// jest.config.ts
import type { Config } from '@jest/types';

// Sync object
const config: Config.InitialOptions = {
testEnvironment: 'node',
verbose: true,
preset: 'ts-jest',
};
export default config;
6 changes: 6 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignore": ["**/*.test.ts", "**/*.spec.ts", ".git", "node_modules"],
"watch": ["src"],
"exec": "yarn run start",
"ext": ".ts,.js"
}
Loading

0 comments on commit 8d5b272

Please sign in to comment.