Skip to content
This repository was archived by the owner on Sep 14, 2021. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0neerpat committed Mar 3, 2021
0 parents commit b79b7eb
Show file tree
Hide file tree
Showing 51 changed files with 20,825 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
13 changes: 13 additions & 0 deletions .env.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These environment variables will be used by default if you do not create any
# yourself in .env. This file should be safe to check into your version control
# system. Any custom values should go in .env and .env should *not* be checked
# into version control.

# schema.prisma defaults
DATABASE_URL=file:./dev.db

# location of the test database for api service scenarios (defaults to ./.redwood/test.db if not set)
# TEST_DATABASE_URL=file:./.redwood/test.db

# disables Prisma CLI update notifier
PRISMA_HIDE_UPDATE_MESSAGE=true
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# DATABASE_URL=file:./dev.db
# TEST_DATABASE_URL=file:./.redwood/test.db
# PRISMA_HIDE_UPDATE_MESSAGE=true
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea
.DS_Store
.env
.netlify
.redwood
dev.db
dist
dist-babel
node_modules
yarn-error.log
web/public/mockServiceWorker.js
15 changes: 15 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"recommendations": [
"redwoodjs.redwood",
"dbaeumer.vscode-eslint",
"eamodio.gitlens",
"ofhumanbondage.react-proptypes-intellisense",
"mgmcdermott.vscode-language-babel",
"wix.vscode-import-cost",
"pflannery.vscode-versionlens",
"editorconfig.editorconfig",
"prisma.prisma",
"graphql.vscode-graphql"
],
"unwantedRecommendations": []
}
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": [
{
"command": "yarn redwood dev",
"name": "launch development",
"request": "launch",
"type": "node-terminal"
},
{
"type": "pwa-node",
"request": "launch",
"name": "launch api",
"skipFiles": [
"<node_internals>/**"
],
"cwd": "${workspaceFolder}/api",
"envFile": "${workspaceFolder}/.env.defaults",
"program": "${workspaceFolder}/node_modules/.bin/dev-server"
}
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"editor.tabSize": 2,
"files.trimTrailingWhitespace": true,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"[prisma]": {
"editor.formatOnSave": true
}
}
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 Redwood

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.
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<h1 align="center">Welcome to unlock-protocol-discord-bot 👋</h1>
<p>
<a href="#" target="_blank">
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
</a>
</p>

> A Discord bot which prompts the user to enter their DID, and creates a new challenge for them.
## Whats included

- **Discord bot** w/ docker container in `/bot`
- **API server** RedwoodJS API in `/api`
- **(incomplete) Frontend** RedwoodJS web app in `/web`

## Usage

### Create a new Discord Bot

Create a new application at https://discord.com/developers. Don't worry about naming here.

Now in your app, navigate to "Bot" and create a bot. Choose a username and Icon for your bot here.

Leave "Bot Permissions" alone.

Copy the `TOKEN` which we will need for our node app.

Back in this package, copy `.template.env` to `.env` and add the `TOKEN` you just copied.

### Run locally

```bash
# Start the API service
yarn rw dev api

# Start the bot
cd bot && yarn start
```

### Add the bot to your server

In the Discord Application, in "General Information", copy the `CLIENT ID`. Insert it in this URL, and send it to the server admin.

```
https://discord.com/oauth2/authorize?client_id=<clientID>&scope=bot
```

### Going to Production - Heroku

1. Create a new Heroku app for this repo. Update the build configs to point to the `/packages/bot`.

2. Once deployed, head to the "Resources" tab, turn off the `web` Dyno, and turn on the `worker` Dyno. This Dyno is defined in the repo root `Procfile`.

3. Update the environment variables in "Settings" tab to reflect what you see in the `.env` here.

### Going to Production - Docker

If you've made changes to the bot, you'll need to generate a new Docker image.

```bash
# Build
docker build -t <your username>/unlock-protocol-discord-bot .

# Test it out
docker run -p 8080:8080 -d <your username>/unlock-protocol-discord-bot

# Publish it when ready!
```

When you're ready to host the container, clone this repo on your server and navigate to this package. If you published your own version, the update the image name in `docker-compose.yml`. Be sure to update your `.env` file on the new machine as well.

```bash
# Load the .env file
source .env

# Start in "detached" mode
docker-compose up -d
```

## Author

👤 **Patrick Gallagher**

- Website: https://patrickgallagher.dev
- Twitter: [@pi0neerpat](https://twitter.com/pi0neerpat)
- GitHub: [@pi0neerpat](https://github.com/pi0neerpat)

## Show your support

Give a ⭐️ if this project helped you!

---

_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_
1 change: 1 addition & 0 deletions api/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: "../babel.config.js" }
18 changes: 18 additions & 0 deletions api/db/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
datasource DS {
provider = "sqlite"
url = env("DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
binaryTargets = "native"
}

// Define your own datamodels here and run `yarn redwood prisma migrate dev`
// to create migrations for them and apply to your dev DB.
// TODO: Please remove the following example:
model UserExample {
id Int @id @default(autoincrement())
email String @unique
name String?
}
46 changes: 46 additions & 0 deletions api/db/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable no-console */
const { PrismaClient } = require('@prisma/client')
const dotenv = require('dotenv')

dotenv.config()
const db = new PrismaClient()

async function main() {
// https://www.prisma.io/docs/guides/prisma-guides/seed-database
// Seed data is database data that needs to exist for your app to run.
// Ideally this file should be idempotent: running it multiple times
// will result in the same database state (usually by checking for the
// existence of a record before trying to create it). For example:
/*
const result = await db.user.createMany({
data: [
{ email: "alice@example.com" },
{ email: "mark@example.com" },
{ email: "jackie@example.com" },
{ email: "bob@example.com" },
],
skipDuplicates: true, // Supported with Postgres database
})
console.log(`Created ${result.count} users!`)
*/
// Note: createMany creates multiple records in a transaction.
// To enable this feature, add createMany to previewFeatures in your schema.
// See: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#createmany-preview
// Note: createMany is not supported by SQLite.
//
// Example without createMany (supported by all databases):
/*
const existing = await db.user.findMany({ where: { email: 'admin@email.com' }})
if (!existing.length) {
await db.user.create({ data: { name: 'Admin', email: 'admin@email.com' }})
}
*/

console.info('No data to seed. See api/db/seed.js for info.')
}

main()
.catch((e) => console.error(e))
.finally(async () => {
await db.$disconnect()
})
6 changes: 6 additions & 0 deletions api/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { getConfig } = require('@redwoodjs/core')

const config = getConfig({ type: 'jest', target: 'node' })
config.displayName.name = 'api'

module.exports = config
9 changes: 9 additions & 0 deletions api/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"src/*": ["./src/*"]
}
},
"include": ["src/**/*", "../.redwood/index.d.ts"]
}
8 changes: 8 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "api",
"version": "0.0.0",
"private": true,
"dependencies": {
"@redwoodjs/api": "^0.26.2"
}
}
20 changes: 20 additions & 0 deletions api/src/functions/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
createGraphQLHandler,
makeMergedSchema,
makeServices,
} from '@redwoodjs/api'

import schemas from 'src/graphql/**/*.{js,ts}'
import { db } from 'src/lib/db'
import services from 'src/services/**/*.{js,ts}'

export const handler = createGraphQLHandler({
schema: makeMergedSchema({
schemas,
services: makeServices({ services }),
}),
onException: () => {
// Disconnect from your database with an unhandled exception.
db.$disconnect()
},
})
Empty file added api/src/graphql/.keep
Empty file.
6 changes: 6 additions & 0 deletions api/src/lib/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// See https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/constructor
// for options.

import { PrismaClient } from '@prisma/client'

export const db = new PrismaClient()
Empty file added api/src/services/.keep
Empty file.
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@redwoodjs/core/config/babel-preset'],
}
12 changes: 12 additions & 0 deletions bot/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
]
}
3 changes: 3 additions & 0 deletions bot/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
npm-debug.log
.env
15 changes: 15 additions & 0 deletions bot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless

# Webpack directories
.webpack
coverage
.DS_Store

.idea
.env
.keys
4 changes: 4 additions & 0 deletions bot/.template.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DISCORD_TOKEN=
INVOCATION_STRING=!verify
REDIS_URL=
REDIS_PASSWORD=
7 changes: 7 additions & 0 deletions bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:12
WORKDIR /usr/src/bot
COPY package*.json ./
RUN yarn install --production
COPY . .
EXPOSE 8080
CMD [ "node", "src/bot.js" ]
11 changes: 11 additions & 0 deletions bot/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"
services:
discord-bot:
image: pi0neerpat/3box-discord-bot
environment:
- DISCORD_TOKEN=${DISCORD_TOKEN}
- REDIS_URL=${REDIS_URL}
- REDIS_PASSWORD=${REDIS_PASSWORD}
- INVOCATION_STRING=${INVOCATION_STRING}
ports:
- "8080:8080"
Loading

0 comments on commit b79b7eb

Please sign in to comment.