bryxli / zoe-bot

Discord bot that traverses through the Riot Games API to find information about players of the game League of Legends.
https://top.gg/bot/1154647072138608694
MIT License
3 stars 0 forks source link
aws-cdk cloudfront discord-interactions dynamodb flask github-actions lambda nextjs riot-games-api s3 sst webhook

Zoe Bot

Description

Discord bot that traverses through the Riot Games API to find information about players of the game League of Legends.

Table of Contents

Prerequisites

Zoe is an IaC monorepo application that utilizes SST and Discord. Make sure to have the following installed and configured.

Overview

Bot Commands

CloudFormation Stacks

Applications

Initial Setup

Create Discord Application

  1. Create a new Application

  2. Enable Privileged Gateway Intents under Bot

  3. Invite to server with https://discord.com/oauth2/authorize?client_id=<client_id>&permissions=536870912&scope=applications.commands%20bot

    Note: Replace with Application ID

  4. After deploying the bot to AWS using either npm run deploy or npm run deploy:prod, paste InteractionsEndpoint into Interactions Endpoint URL under General Information

Configuration

Set environment configuration config.json

{
  "aws_region": "<AWS REGION>",
  "riot_key": "<RIOT API KEY>",
  "discord_public_key": "<DISCORD PUBLIC KEY>",
  "application_id": "<DISCORD APPLICATION ID>",
  "token": "<DISCORD BOT TOKEN>"
}

Bot Deployment

Startup

The bot is configured to be able to deploy to multiple stages. This changes configurations in the AWS stack.

Production Deployment

Create Redirect

  1. In the Discord Application on Discord Developer Portal under OAuth2, create a redirect URL using URL/load

    The redirect URL will look like this https://abcdefghijklm.cloudfront.net/load

  2. Under Authorization Method, choose In-app Authorization

  3. Enable Scopes: bot, application.commands

  4. Enable Bot Permissions: Manage Webhooks

Integrate with GitHub Actions

Create IAM Role

Instructions to deploy SST apps using GitHub Actions can be found here

Create Secrets

Automated Setup

  1. Set environment configuration config.actions.json
{
  "pat": "<GITHUB TOKEN>",
  "owner": "<GITHUB REPO OWNER>",
  "repo": "<GITHUB REPO>",
  "aws_account_id": "<AWS ACCOUNT ID>",
  "aws_region": "<AWS REGION>",
  "riot_key": "<RIOT API KEY>",
  "dev": {
    "discord_public_key": "<DISCORD PUBLIC KEY>",
    "application_id": "<DISCORD APPLICATION ID>",
    "token": "<DISCORD BOT TOKEN>"
  },
  "prod": {
    "discord_public_key": "<DISCORD PUBLIC KEY>",
    "application_id": "<DISCORD APPLICATION ID>",
    "token": "<DISCORD BOT TOKEN>"
  }
}
  1. In configs, create secrets used by GitHub Actions using npm run start

Manual Setup

  1. In the repo, under Settings > Secrets and variables > Actions, create three new repository secrets

    • AWS_ACCOUNT_ID
    • AWS_REGION
    • RIOT_KEY
  2. Repeat step 1 for Secrets and variables > Dependabot

  3. Additionally, create a new environment called dev and create three new environment secrets

    • APPLICATION_ID
    • DISCORD_PUBLIC_KEY
    • TOKEN
  4. Repeat step 3 for prod