Skip to content

Commit 2a9e291

Browse files
committed
chore: Import 2024 Bot
0 parents  commit 2a9e291

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3744
-0
lines changed

.gitignore

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# editor
2+
.vscode/
3+
4+
# config
5+
config.json
6+
config.json5
7+
8+
# builds
9+
build/
10+
11+
# database
12+
prisma/database.db
13+
data/
14+
15+
# Logs
16+
logs
17+
*.log
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
lerna-debug.log*
22+
23+
# Diagnostic reports (https://nodejs.org/api/report.html)
24+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
25+
26+
# Runtime data
27+
pids
28+
*.pid
29+
*.seed
30+
*.pid.lock
31+
32+
# Directory for instrumented libs generated by jscoverage/JSCover
33+
lib-cov
34+
35+
# Coverage directory used by tools like istanbul
36+
coverage
37+
*.lcov
38+
39+
# nyc test coverage
40+
.nyc_output
41+
42+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
bower_components
47+
48+
# node-waf configuration
49+
.lock-wscript
50+
51+
# Compiled binary addons (https://nodejs.org/api/addons.html)
52+
build/Release
53+
54+
# Dependency directories
55+
node_modules/
56+
jspm_packages/
57+
58+
# TypeScript v1 declaration files
59+
typings/
60+
61+
# TypeScript cache
62+
*.tsbuildinfo
63+
64+
# Optional npm cache directory
65+
.npm
66+
67+
# Optional eslint cache
68+
.eslintcache
69+
70+
# Microbundle cache
71+
.rpt2_cache/
72+
.rts2_cache_cjs/
73+
.rts2_cache_es/
74+
.rts2_cache_umd/
75+
76+
# Optional REPL history
77+
.node_repl_history
78+
79+
# Output of 'npm pack'
80+
*.tgz
81+
82+
# Yarn Integrity file
83+
.yarn-integrity
84+
85+
# dotenv environment variables file
86+
.env
87+
.env.test
88+
89+
# parcel-bundler cache (https://parceljs.org/)
90+
.cache
91+
92+
# Next.js build output
93+
.next
94+
95+
# Nuxt.js build / generate output
96+
.nuxt
97+
dist
98+
99+
# Gatsby files
100+
.cache/
101+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
102+
# https://nextjs.org/blog/next-9-1#public-directory-support
103+
# public
104+
105+
# vuepress build output
106+
.vuepress/dist
107+
108+
# Serverless directories
109+
.serverless/
110+
111+
# FuseBox cache
112+
.fusebox/
113+
114+
# DynamoDB Local files
115+
.dynamodb/
116+
117+
# TernJS port file
118+
.tern-port

Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM node:20
2+
3+
WORKDIR /app
4+
5+
# Dependency layer
6+
COPY ./package.json package.json
7+
COPY ./yarn.lock yarn.lock
8+
RUN yarn install
9+
10+
# Build layer
11+
COPY ./tsconfig.json tsconfig.json
12+
COPY ./src src
13+
COPY ./prisma prisma
14+
RUN yarn build
15+
16+
# Config layer
17+
COPY ./config.json5 config.json5
18+
19+
# Execution layer
20+
CMD yarn prisma:migrate && yarn host

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 WinHacks
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.

config.json5.example

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
// production client information
3+
production: {
4+
app_id: "",
5+
api_token: "",
6+
bot_uid: 8,
7+
guild: "",
8+
},
9+
10+
// development client information
11+
development: {
12+
app_id: "",
13+
api_token: "",
14+
bot_uid: 8,
15+
guild: "",
16+
},
17+
18+
// should the bot be in development mode?
19+
dev_mode: false,
20+
21+
// sheets API config
22+
sheets_api: {
23+
scopes: ["https://www.googleapis.com/auth/spreadsheets.readonly"],
24+
private_key: "",
25+
client_email: "",
26+
},
27+
28+
// information for the /about command, and `color` dictates the bot embed color
29+
bot_info: {
30+
name: "",
31+
color: 0x14c3a2, // a hex literal of the form 0xRRGGBB
32+
event_name: "WinHacks 2024",
33+
title_url: "",
34+
thumbnail: "",
35+
description: "An open-source Discord Bot written in TypeScript with Discord.JS by [Borhan Saflo](https://borhansaflo.com) and [Isaac Kilbourne](https://isaac.kilbourne.ca) and published under the MIT license for WinHacks 2024.",
36+
},
37+
38+
// config for the /verify and /unverify commands
39+
verify: {
40+
registration_url: "",
41+
target_sheet_id: "",
42+
target_sheet: "",
43+
first_name_column: "A",
44+
last_name_column: "B",
45+
email_column: "C",
46+
verified_role_name: "Verified",
47+
channel_id: "1234567890",
48+
},
49+
50+
// /team and subcommand config
51+
teams: {
52+
max_name_length: 20,
53+
max_team_size: 4,
54+
teams_per_category: 25, // each team creates 2 channels. Should be at MOST floor(DISCORD_CATEGORY_CHANNEL_LIMIT / 2)
55+
category_base_name: "Teams",
56+
moderator_roles: ["Moderator"],
57+
},
58+
59+
// displayName is the text that will be shown in the socials embed, link is the link it will point to
60+
// The stream command searches for a link named "twitch", "twitchtv", or "twitch.tv" (not case sensitive)
61+
// so that is the name you should give your twitch link if you have one
62+
socials: [
63+
{displayName: "Twitter", link: "https://twitter.com/WinHacksCA"},
64+
{displayName: "Facebook", link: "https://facebook.com/WinHacksCA"},
65+
{displayName: "LinkedIn", link: "https://linkedin.com/company/winhacks"},
66+
{displayName: "Instagram", link: "https://instagram.com/winhacksca"},
67+
{displayName: "Twitch", link: "https://twitch.tv/uwindsorcss"},
68+
{
69+
displayName: "YouTube",
70+
link: "https://www.youtube.com/channel/UCMph1_SzSomH2cUF7j_YqUA",
71+
},
72+
],
73+
}

docker-compose.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
winhacksbot:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
7+
volumes:
8+
- ./data:/app/data:rw

package.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "winhacks24-bot",
3+
"version": "1.0.0",
4+
"description": "Discord.JS Bot for Winhacks 2024",
5+
"main": "index.ts",
6+
"repository": "[email protected]:WinHacks/2024-bot.git",
7+
"author": "kilbouri <[email protected]>",
8+
"license": "MIT",
9+
"private": false,
10+
"scripts": {
11+
"dev": "ts-node ./src/index.ts",
12+
"dev-pretty": "ts-node ./src/index.ts | pino-pretty",
13+
"build": "yarn prisma:generate && tsc -outdir ./build",
14+
"host": "node ./build/index.js",
15+
"prisma:generate": "prisma generate",
16+
"prisma:migrate": "prisma migrate deploy",
17+
"prisma:create-migration": "prisma migrate dev",
18+
"docker:host": "docker compose up -d",
19+
"docker:stop": "docker compose down",
20+
"docker:update": "yarn docker:stop && docker-compose up -d --build"
21+
},
22+
"prettier": {
23+
"tabWidth": 4,
24+
"useTabs": false,
25+
"semi": true,
26+
"singleQuote": false,
27+
"quoteProps": "as-needed",
28+
"trailingComma": "es5",
29+
"bracketSpacing": false,
30+
"arrowParens": "always",
31+
"endOfLine": "lf",
32+
"printWidth": 90
33+
},
34+
"eslintConfig": {
35+
"node": true,
36+
"es6": true
37+
},
38+
"devDependencies": {
39+
"@tsconfig/node16": "^16.1.1",
40+
"ts-node": "^10.9.2",
41+
"typescript": "^5.3.3"
42+
},
43+
"dependencies": {
44+
"@prisma/client": "^5.9.1",
45+
"@types/node": "^20.11.16",
46+
"discord.js": "14.14.1",
47+
"googleapis": "^132.0.0",
48+
"json5": "^2.2.3",
49+
"pino": "^8.18.0",
50+
"prisma": "^5.9.1",
51+
"readline": "^1.3.0",
52+
"shutdown-handler": "^1.0.1",
53+
"systeminformation": "^5.21.24"
54+
}
55+
}

0 commit comments

Comments
 (0)