GithubHelp home page GithubHelp logo

guledali / swordy-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oneclickdapp/swordy-bot

1.0 0.0 0.0 2.69 MB

Home Page: swordy-bot-discord-pi0neerpat.vercel.app

License: MIT License

Shell 0.17% JavaScript 91.97% Dockerfile 0.12% CSS 5.99% HTML 1.74%

swordy-bot's Introduction

This is an older version of Swordy Bot - not the live production app!

NOTE: You should not expect this to work out-of-the-box, but rather use it as an example and a learning tool. Here are some of my takeaways from this version:

  • Most important! The app logic should not be split between the Heroku Discord Bot and the RedwoodJS app. Instead, the Heroku Discord Bot should be as "dumb" as possible, and simply act as a messenger between Discord and the RedwoodJS app.
  • I did not implement Discord OAuth here, but rather my own solution for verifying ownership which requires DM'ing. Using the Discord Oauth is a better solution overall in terms of UX, and is harder to break, despite being much more work to implement.
  • This bot requires DM'ing the user a unique link to verify ownership. This is an anti-pattern, since many users disable DM'ing from other server participants to prevent spam. This means the bot simply appears "broken" to this set of users.

Welcome to unlock-protocol-discord-bot ๐Ÿ‘‹

License: MIT

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

Local Development

Setup the backend + frontend

yarn

# Initialize SQL-lite and perform initial migrations
yarn rw db save
yarn rw db up

# Start the API service and Frontend
yarn rw dev

Start the bot

cd bot && yarn
yarn start

Going to Production

The easiest way to deploy is using Vercel for the frontend and backend, and Heroku for the bot and postgres database. Hosting this way is free, and can be setup in about 10 minutes.

In order to collect all the required environment variables, you'll need to deploy all three parts (bot, FE+BE, discord app), and go back and update as necessary.

Vercel - Backend + Frontend

Point vercel to your repo, and deploy. Redwood build commands should be auto-configured.

Update the environment variables for what you see in the root .env file. The only new one is DATABASE_URL which you need from your Heroku database in the next step.

Heroku - Bot

Heroku doesn't like apps that aren't in the root folder. To get around this, I added a heroku-prebuild script which installs the bot dependencies. The Procfile runs the bot.js

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.

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

Add a new postgres add-on and add the url to the Vercel environment.

Discord

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 and add it to your bot app.

Now add the bot to your server. In the Discord Application, in "General Information", copy the CLIENT ID. Insert it in this URL, and have the server administrator open it.

# Add the bot with role management permissions
https://discord.com/oauth2/authorize?client_id=<clientID>&scope=bot&permissions=268435456

Docker option

If you want to avoid Heroku for the bot, you can use docker. If you've made changes to the bot, you'll need to generate a new Docker image.

# 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.

# Load the .env file
source .env

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

Notes

Author

๐Ÿ‘ค Patrick Gallagher

Show your support

Give a โญ๏ธ if this project helped you!


This README was generated with โค๏ธ by readme-md-generator

swordy-bot's People

Contributors

pi0neerpat avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.