Code Monkey home page Code Monkey logo

discord-permission-manager's Introduction

Overview

This tool allows you to view and edit the permissions for categories and channels in a Discord server via Terraform.

Setup

This repo uses asdf to manage Node.JS and Terraform versions. If you have asdf set up, along with with the Terraform (asdf plugin-add terraform https://github.com/asdf-community/asdf-hashicorp.git) and NodeJS (asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git) plugins, you can install and use the correct versions with:

asdf install

Otherwise, manually install NodeJS 20.11.0 and Terraform 1.7.1 (or use other versions at your own risk).

Then, install the NodeJS dependencies:

npm install

Unfortunately, the upstream Discord provider had a bug that prevents importing channel permission resources. Until they merge our fix, you also need to build a forked provider from source.

Clone the repo: https://github.com/benweissmann/terraform-provider-discord/tree/bsw/import-channel-permission and switch to the bsw/import-channel-permission branch.

From that branch, with a go 1.20 toolchain (or above) installed:

go build -o terraform-provider-discord

You should end up with a terraform-provider-discord binary. Running this binary should print a message saying that it's a Terraform plugin.

Then, instruct Terraform to use your fork by creating a .terraformrc file in your Home directory with:

provider_installation {
  dev_overrides {
    "registry.terraform.io/Lucky3028/discord" = "/path/to/repo/for/terraform-provider-discord"
  }
  direct {}
}

Note that that path is to the git repository directory, not the binary itself (i.e., that path is to a directory that contains the terraform-provider-discord binary, not to the binary itself).

Setting up a bot token

You'll need to provide your Bot Token via env var (you should set it as DPM_BOT_TOKEN for this script, and also as TF_VAR_discord_token for the Terraform config):

export DPM_BOT_TOKEN=xxxx
export TF_VAR_discord_token=xxxx # the name is case-sensitive!

This tool requires the permission to list all servers users, which is considered a "privileged intent". In your application, navigate to the "Bot" page, find the "Privileged Gateway Intents" section, and toggle on "Server Members Intent"

Then, add your bot to your Discord server. Select bot permissions, and then select Administrator for the "Bot Permissions" that appear after selecting bot (you might be able to run this tool with lower permissions, but Bots can only grant permissions they themselves have, so your bot will need at least every permission you want it to manage).

Export the ID of your Discord server:

export DPM_SERVER_ID=xxx

Running the tool

Now, you can generate the Terraform for your server's current configuration:

npm start

This will:

  • Delete old generated files (after confirming, if they exist)
  • Use the Discord API to generate ./terraform/imports.tf with imports for every category/category permission/channel/channel permission, ./terraform/data.tf with data blocks for users/roles used in permissions, and ./terraform/channels.tf with Terraform declarations for each channel / category.

From there, you can run cd terraform; terraform init; terraform apply to confirm that there are not pending changes and the terraform was correctly generated, and then apply to carry out the import. DO NOT make any edits to the channels.tf file before doing this first apply to finish the imports.

Then, edit terraform/channels.tf and run cd terraform; terraform apply to preview and apply your changes.

discord-permission-manager's People

Contributors

benweissmann avatar ebroder 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.