Skip to content

Commit

Permalink
Merge pull request #12 from dadatuputi/refactor-to-typescript
Browse files Browse the repository at this point in the history
Refactor to typescript
  • Loading branch information
dadatuputi authored Jun 20, 2023
2 parents 2ba0c57 + 80f98e0 commit 6c015a5
Show file tree
Hide file tree
Showing 46 changed files with 4,935 additions and 3,097 deletions.
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BOT_AVATAR=res/xx_logo_color.png # this is not updated on bot login

# XX API variables
ENDPOINT=https://dashboard-api.xx.network/v1/nodes
ENDPOINT_POLLING=60 # how often to pull the current node list
ENDPOINT_CRON=* * * * * # how often (in seconds) to pull the current node list (default is every minute)
DASHBOARD_URL=https://dashboard.xx.network/nodes # used to build dashbord URIs

# MongoDb variables
Expand Down
File renamed without changes.
136 changes: 135 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,135 @@
.env
built
*.crt

# Boilerplate from https://github.com/github/gitignore/blob/main/Node.gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-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/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# 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 variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

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

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# 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

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# 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

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch index.ts",
"type": "node",
"request": "launch",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/index.ts"
],
"env": {
"TS_NODE_PROJECT": "${workspaceFolder}/tsconfig.json"
},
"envFile": "${workspaceFolder}/.env"
}
]
}

16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY bot/package*.json ./

COPY package*.json ./
COPY tsconfig.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY bot .
# Copy source code & resources
COPY src ./src
COPY res ./res

# Build the project
RUN npm run build

CMD [ "node", "index.js" ]
CMD [ "npm", "run", "start" ]
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Demo

The latest version of this bot is accessible at the [engul.ph discord server](https://discord.gg/Y7jQEbv5za).

# Getting Started

Clone this repo into your linux environment.
Expand Down Expand Up @@ -65,7 +69,7 @@ Use the `bot-utils.js` script to deploy the bot commands to your dev server or g
Run this command to view the script options:

```
$ docker run --env-file .env -it xx_monitor_bot-bot node bot-utils.js
$ docker run --env-file .env -it xx_monitor_bot-bot node built/bot-utils.js
```

### **Required:** Deploy commands to server or globally
Expand All @@ -75,19 +79,19 @@ You may choose to deploy globally or to a specific server. Deploying globally al
To deploy globally:

```
$ docker run --env-file .env -it xx_monitor_bot-bot node bot-utils.js deploy --global
$ docker run --env-file .env -it xx_monitor_bot-bot node built/bot-utils.js deploy --global
```

To deploy to a server:

```
$ docker run --env-file .env -it xx_monitor_bot-bot node bot-utils.js deploy
$ docker run --env-file .env -it xx_monitor_bot-bot node built/bot-utils.js deploy
```

To un-deploy:

```
$ docker run --env-file .env -it xx_monitor_bot-bot node bot-utils.js deploy --reset
$ docker run --env-file .env -it xx_monitor_bot-bot node built/bot-utils.js deploy --reset
```

**To deploy changes you make to the `SlashCommandBuilder` object in your commands**:
Expand All @@ -96,24 +100,22 @@ Just deploy as you originally did, either globally or to a server.

### Update username
```
$ docker run --env-file .env -it xx_monitor_bot-bot node bot-utils.js username "xx monitor bot"
$ docker run --env-file .env -it xx_monitor_bot-bot node built/bot-utils.js username "xx monitor bot"
```

### Update avatar
```
$ docker run --env-file .env --volume <image path>:/image -it xx_monitor_bot-bot node bot-utils.js avatar /image
$ docker run --env-file .env --volume <image path, e.g. ./image.jpg>:/image -it xx_monitor_bot-bot node built/bot-utils.js avatar /image
```

### Using `bot-utils.js` locally

Use the following commands to install the required packages and publish the slash commands to your server:

```bash
$ cd bot
$ npm install
$ node bot-utils.js help
$ node built/bot-utils.js help
$ [... command output ...]
$ cd ..
```

You can also set the bot username and status with the `BOT_USERNAME` and `BOT_STATUS` variables in `.env` and they will be set each time the bot starts.
Expand Down Expand Up @@ -161,15 +163,14 @@ To run the bot outside docker for testing or development, first start up an ephe

```bash
$ cd bot
$ docker compose -f mongo-only-compose.yml --env-file ../.env up
$ docker compose -f mongo-only-compose.yml --env-file .env up
```

From another terminal, run:

```bash
$ cd bot
$ npm install # if it hasn't been run before
$ node index.js
$ npm run start
```

Now you can run the app without building a docker image for each test run.
Expand All @@ -191,5 +192,5 @@ $ docker compose build
...
$ docker compose up -d
...
$ docker run --env-file .env -it xx_monitor_bot-bot node bot-utils.js deploy --global # note! deploy how you originally deployed
$ docker run --env-file .env -it xx_monitor_bot-bot node built/bot-utils.js deploy --global # note! deploy how you originally deployed
```
Loading

0 comments on commit 6c015a5

Please sign in to comment.