|
| 1 | +# WinHacks 2024 Discord Bot |
| 2 | + |
| 3 | +Bot for WinHacks 2024, written in Typescript with Discord.JS. Uses a SQLite database to store team information and the Google Sheets API to verify users based on the results of an application form. |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +To start, copy `config.json5.example` to `config.json5`. |
| 8 | + |
| 9 | +```bash |
| 10 | +# Mac/Linux: |
| 11 | +cp config.json5.example config.json5 |
| 12 | + |
| 13 | +# Windows: |
| 14 | +copy config.json5.example config.json5 |
| 15 | +``` |
| 16 | + |
| 17 | +**Reminder:** do not under _any_ circumstances commit the `config.json5` file to version control. It more than likely contains secret information that you _really_ should keep secret. |
| 18 | + |
| 19 | +### Discord API Configuration |
| 20 | + |
| 21 | +The Discord API configuration has two "modes" or "groups": **production**, which is the application for the production bot, and **development**, which is the application for the bot "beta" or "in development". |
| 22 | + |
| 23 | +The `dev_mode` option is a boolean which selects between the **production** and **development** modes. |
| 24 | + |
| 25 | +Each mode has the same configuration: |
| 26 | + |
| 27 | +- `app_id`: Your application ID. It is located on the "general information" tab of [your application's page](https://discord.com/developers/applications) |
| 28 | +- `api_token`: Your bot's token. You can find it [here](https://discord.com/developers/applications), under your application > Bot > Token. |
| 29 | +- `api_version`: usually `"9"`. The bot will probably break with any other version. |
| 30 | +- `bot_uid`: the "permission integer" for the bot. You can simply use `8` (Administrator). |
| 31 | + |
| 32 | +### Google Sheets API Configuration |
| 33 | + |
| 34 | +To configure the bot to work with the Google Sheets API, you will need a Google Cloud Platform project with the Google Sheets API enabled and a Service Account. |
| 35 | + |
| 36 | +Once you have a service account, you want to add a JSON key for it. Copy the `private_key` and `client_email` fields into the respective fields in the bot config. Newlines are important. You can use `\n` instead of actually breaking the string across lines, if you wish. |
| 37 | + |
| 38 | +`scopes` is an array of scopes you wish to have for the bot. Currently, all you need is `https://www.googleapis.com/auth/spreadsheets.readonly`. |
| 39 | + |
| 40 | +Helpful links: |
| 41 | + |
| 42 | +- [Creating a GCP Project](https://developers.google.com/workspace/guides/create-project) |
| 43 | +- [Enabling the Google Sheets API](https://developers.google.com/workspace/guides/enable-apis) |
| 44 | +- [Creating a Service Account & Keys](https://developers.google.com/workspace/guides/create-credentials#service-account) |
| 45 | +- [Google Sheets API Scopes](https://developers.google.com/identity/protocols/oauth2/scopes#sheets) |
| 46 | + |
| 47 | +### Command Specific Configuration |
| 48 | + |
| 49 | +#### Bot Info |
| 50 | + |
| 51 | +- `name`: the name to appear on the embed. |
| 52 | +- `color` (optional): a hexadecimal number (such as `0x14c3a2`) representing the color of all embeds the bot sends. |
| 53 | +- `event_name`: the name of the event the bot is being used for. The bot will use this when referring to the event. |
| 54 | +- `title_url` (optional): a URL the embed title should link to. Can be anything, such as the bot's GitHub/GitLab repository, or your event's homepage. |
| 55 | +- `thumbnail` (optional): An external image link to place in the embed thumbnail. |
| 56 | +- `description`: the text content to place in the embed description. Markdown-style inline links are supported. |
| 57 | + |
| 58 | +#### Verify |
| 59 | + |
| 60 | +- `registration_url`: the URL to register for the event. |
| 61 | +- `target_sheet_id`: the ID of the spreadsheet to use for verification. It will need to be shared with the service worker account. You can find the ID in the sheet URL: `https://docs.google.com/spreadsheets/d/**SHEET_ID_HERE**/edit`. |
| 62 | +- `target_sheet`: the name of the sheet to use for verification data. |
| 63 | +- `first_name_column`: the column in the `target_sheet` that contains a user's first name. Must be a single letter. |
| 64 | +- `last_name_column`: the column in the `target_sheet` that contains a user's last name. Must be a single letter. |
| 65 | +- `email_column`: the column in the `target_sheet` that contains emails to verify users against. Must be a single letter. |
| 66 | +- `verified_role_name`: the display name of the role to give verified users. |
| 67 | +- `channel_id`: the id of the channel which is used for verification. **Users are not restricted to using the command in this channel, but rather linked to it when they use `/apply`**. |
| 68 | + |
| 69 | +#### Teams |
| 70 | + |
| 71 | +- `max_name_length`: the number of characters which is considered too long fora team name. Discord limits this to 100. |
| 72 | +- `max_team_size`: the maximum number of members in a team. |
| 73 | +- `teams_per_category`: the number of teams that can be in one channel category. Each team has 2 channels, and Discord doesn't allow more than 50 channels per category, so this should be no more than 25. |
| 74 | +- `category_base_name`: the base name of a team category. The category number is appended to this. For example, base name `Teams` would become `Teams 1` when the first category is created. |
| 75 | +- `moderator_roles`: the names of any additional roles that should be allowed to view all team channels. |
| 76 | + |
| 77 | +#### Socials |
| 78 | + |
| 79 | +The socials item is an array of key-value pairs (`displayName: link`) that tells the bot how to display and link to each social media account. For example: `socials: [{displayName: "Twitter", link: "https://twitter.com/YourOrganization"}]` would show as `Twitter` and link to `https://twitter.com/YourOrganization`. |
| 80 | + |
| 81 | +## Running the Bot |
| 82 | + |
| 83 | +Now that you've configured everything, you need to start it up. We use Docker to make that very simple. |
| 84 | + |
| 85 | +For hosting, its as simple as `yarn docker:host`. Similarly, for development, is as simple as `yarn dev`. You can also install `pino-pretty` with `yarn global add pino-pretty` and use `yarn dev-pretty` for nicer looking logs. |
0 commit comments