Skip to content

Commit

Permalink
[DISC-120] Implementation of Various Features (#197)
Browse files Browse the repository at this point in the history
* migrate from insou api to circles for the handbook commands (#128)

* migrate from insou api to circles for the handbook commands

* remove trailing forward slash in handbook.json

* handbook: the handbook is fixed

* Update handbook.js

commented out a console.log

---------

Co-authored-by: tunein <z5371683@ad.unsw.edu.au>
Co-authored-by: zcDay1 <113964162+zcDay1@users.noreply.github.com>

* prettier formatted

* chore(deps): update `renovate` config

* chore(deps): update docker/build-push-action action to v4 (#134)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Projects description command feature (#145)

* projects-descriptions v1 commit

* project-descriptions command v2 commit

* linting fixes for project-descriptions.js, and for handbook.js

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>

* disable annoying carrotboard pins

* rolesPermOverride command is a script or one-time use command to attach every course role with permissions to view and send messages in any text channel with identical name. Please review and test before merging

* Revert "rolesPermOverride command is a script or one-time use command to attach every course role with permissions to view and send messages in any text channel with identical name. Please review and test before merging"

This reverts commit 2f59c71.

* rolesPermOverride command  (#152)

* rolesPermOverride command is a script or one-time use command to attach every course role with permissions to view and send messages in any text channel with identical name. Please review and test before mergin

* BUGGY CODE but still progress over the previous commit, I will come back this evening to fix

* rolesPermOverride command: now admin-only command, and I've tested it for various cases regarding if a channel exists, if a role exists for a channel that doesnt exist, if there are two channels with the same name as a role and vice versa, and it works without error

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>

* Roles perm override (#153)

* rolesPermOverride command is a script or one-time use command to attach every course role with permissions to view and send messages in any text channel with identical name. Please review and test before mergin

* BUGGY CODE but still progress over the previous commit, I will come back this evening to fix

* rolesPermOverride command: now admin-only command, and I've tested it for various cases regarding if a channel exists, if a role exists for a channel that doesnt exist, if there are two channels with the same name as a role and vice versa, and it works without error

* course.js: removed code to create individual user permission overwrites in each channel

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>

* Project descriptions (#154)

* project-descriptions.js: updated course descriptions written by the directors for 2023 levelling up with Projects Fair Day, and the discord bot CTF flag easter egg entry under this command included too for this event.

* made messages ephemeral to prevent chat from being spammed by users. And got rid of link embeds in the messages.

* lint update

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>

* Dev/course channel fix 3 (#158)

* course-chat-fix-2, make new roles where there arent any in /rolespermoverride and also remove individual permission overwrites, and also updates to /course join to catch when there doesn't exist a role for a course and also /course leave to attempt to remove individual permission overwrites along with removing course role PLEASE TEST THOROUGHLY AND INSPECT CODE THOROUGHLY. I wrote this ASAP and haven't got time to properly review it.

* Modified functions for course channel fixes

* Check for if user only has read perms for overwrite replacing and fix looping over members

* Fix to functionality of iteration and editing roles

* Fix to initial working state

* Fix linting

* Additional fixes to ordering and component operations to remove role and individual permissions correctly

* Appended filter for both view only perms and view + send messages perms

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>
Co-authored-by: Wolfdragon24 <dragonbomber24@gmail.com>

* dev/course-channel-fix-5 (#160)

* course-chat-fix-2, make new roles where there arent any in /rolespermoverride and also remove individual permission overwrites, and also updates to /course join to catch when there doesn't exist a role for a course and also /course leave to attempt to remove individual permission overwrites along with removing course role PLEASE TEST THOROUGHLY AND INSPECT CODE THOROUGHLY. I wrote this ASAP and haven't got time to properly review it.

* Modified functions for course channel fixes

* Check for if user only has read perms for overwrite replacing and fix looping over members

* Fix to functionality of iteration and editing roles

* Fix to initial working state

* Fix linting

* Additional fixes to ordering and component operations to remove role and individual permissions correctly

* Appended filter for both view only perms and view + send messages perms

* Appended single channel mode for permissions override

* Appended check command for role permissions

* Resolved merge conflicts in dev/course-channel-fix-4

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>
Co-authored-by: Wolfdragon24 <dragonbomber24@gmail.com>

* Update rolesPermOverride.js

double equals updated to triple equals on line 156

* Course Command Fixing - Collection Null Value Error (#162)

* Accounting for non-channel returns associated to snowflakes

* Utilise cache directly as fetch falls back to a cache call anyway

* Dev/upgrade handbook url (#164)

* Upgraded handbook url in config.json to use 2024. Also fixed incorrect url links in the handbook.js command.

* Fixed eslint warnings

* Fixed bug for courses that do not yet have an offering term (Default: "None") (#165)

* Upgraded handbook url in config.json to use 2024. Also fixed incorrect url links in the handbook.js command.

* Fixed eslint warnings

* Fixed equivalent courses urls being listed

* Implementation of the Lunch Buddy feature (#167)

* update: checking if perms work

* Chron job set for every minute, basic embed added and structure for the locations and sub locations created

* Updated README

* Implemented area voting system

* Ran linting and prettier for current changes

* Appending location poll for given area, and vote counting for both area and locations

* Implemented functional voting system for area and location, creating thread upon completion of set

* Used await and cleaned up a bit of code, thread now adds all voters not only the ones who voted for the winning area

* Lint fix

* Removed promises and adjusted placement of vote function calls

* Adjusted thread users, append location vote pings

* Linting fixes

* Locations Update

* Adds "any" option and append additional vote info

* Appended code for live run timing

* Update to use config file

* Allow disabling of feature without editing code and disable

* Minor adjustment to readme and npm commands

* Appended clarifying comment regarding edge case of only any votes

---------

Co-authored-by: mi-mott <98304083+mi-mott@users.noreply.github.com>

* [DISC-107] Adding csesocLinks to get CSESoc related links (#170)

* completed csesocLinks command

* linting

* Refactor execute function to use arrow functions

* linting

* [DISC-109] Adding bot-status for events and member count (#169)

* Adding bot-status for events and member count

* Fixing lint errors

* Adding fixes to how member count is calculated

---------

Authored-by: Eric <eric.wu3@student.unsw.edu.au>

* Update dependency nodemailer to v6.9.9 [SECURITY] (#168)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency axios to v0.28.0 [SECURITY] (#166)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update dependency yaml to v2.2.2 [security] (#147)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency dotenv to v16 (#141)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update actions/checkout action to v4 (#157)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update dependency discordjs-button-pagination to v3 (#140)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Remove unused discord-tictactoe dependency and updated canvas (#173)

* fix(deps): update weekly patch updates (#142)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update dependency @discordjs/builders to v1 (#135)

* Update dependency @discordjs/builders to v1

* Update to project description choices to utilise object structure (Fix to erroring on dependency update)

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Wolfdragon24 <dragonbomber24@gmail.com>
Co-authored-by: Wolfdragon24 <31204305+Wolfdragon24@users.noreply.github.com>

* fix(deps): update dependency discord.js to v14 (#139)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update to fix v14 breaking changes (#176)

* chore(deps): update actions/setup-node action to v4 (#172)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Nitpick refactor for courses command (#126)

* I can finally sleep now

* Implementation of suggested modifications

* Modification to ensure correct regex form for case-insensitive match

---------

Co-authored-by: Wolfdragon24 <dragonbomber24@gmail.com>

* fix(deps): update dependency mathjs to v12 (#182)

* chore(deps): update docker-github-actions

* fix(deps): update dependency mathjs to v12

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update dependency axios to v1 (#181)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update dependency @discordjs/rest to v2 (#179)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency eslint-config-prettier to v9 (#175)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update dependency nodemon to v3 (#183)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update node.js to v20 (#171)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update dependency mathjs to v13 (#184)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* DISC-119-unielectives-review (#188)

* working unilectives review

* added warning for chartjs dependency

* changed to ephemeral reply

* removed unneccesary libraries for chartjs

* hopefully no npm package conflict dying

* npm packages should be fixed

* changed web scraper package for robustness

* linting

* fixed yaml npm issue

* JSCode docu

* linting

* revert config files to og

* package-json changes

---------

Co-authored-by: addison <h34312575s@gmail.com>

* [DISC-120] Update eslint dependency and nodejs to v20

* chore(deps): update dependency eslint to v9

* Update to eslint and babel/eslint-parser

* Update lock file

* Fixes for linting

* Modifications to ignore node modules and consider all other files for linting

* Force update of node to version 20

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Wolfdragon24 <dragonbomber24@gmail.com>

* [DISC-120] Update to prettier and corresponding eslint plugin

* chore(deps): update dependency prettier to v3

* Update prettier config to use auto end of line setting

* Linting and prettifying

* Prettier fixes and running format

* Prettier fix

* Fix by consolidating updates to prettier and eslint plugin

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Wolfdragon24 <dragonbomber24@gmail.com>

* chore(deps): lock file maintenance (#186)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update weekly minor updates (#143)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [DISC-120] Fix to renovate.json file (#190)

* [DISC-120] Declare file type for requiring data (#192)

* [DISC-120] Adjust data type for file (#193)

* Declare file type for requiring data

* Use json as opposed to js data file

* [DISC-120] Move to using fs for configuration (#194)

* Declare file type for requiring data

* Use json as opposed to js data file

* Replace require to use reading file with fs

* Move file to config

* Fix spelling error

* Append setup command for puppeteer browser

* Downloading dependencies and requirements for puppeteer

* Modification to installation order

* Affirm installation

* Revert prior changes and set to use alternate folder for chromium instance

* Manually ignore puppeteer config file in eslint

* Attempt fix to eslint hanging

* [DISC-117] Adding travelguides command (#187)

* initial travelguide add subcommand

* fixing formatting

* fixing syntax error

* added get function

* linting

* completed travelguide command

* linting

* adding deletion confirmation

* linting

* migrating travelguide.json to postgres

* linting

* linting

---------

Co-authored-by: Jessica Xu <jessica.xu3@student.unsw.edu.au>

* Modify location and method for chromium install

* Alter setup to use chromium base

* Update to puppeteer version

* Replace secondary node image with puppeteer

* Fix capitalisation inconsistency and assume permission set

* Reappend entrypoint permission modification

* Reset user from image setup

* Attempt return to puppeteer user after setup

* [DISC-110] Adding Course Chats 1-year "Subscription" (#191)

* Added database implementation of user roles when assigned and removed

* Added time checking function for expired user_roles and added time assigned column to user_roles table

* Added on ready file with cron.js to perform daily check of old_roles

* Adding new package cron for scheduling

* fixing lint issues

* Fixing prettier issues

* Package changes

* Restoring develop package lock.json and fixing db_ready

* Moving guild and roles out of for loop to remove redundant fetching

---------

Co-authored-by: imagine-hussain <93496985+imagine-hussain@users.noreply.github.com>
Co-authored-by: tunein <z5371683@ad.unsw.edu.au>
Co-authored-by: zcDay1 <113964162+zcDay1@users.noreply.github.com>
Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>
Co-authored-by: Jared L <48422312+lhjt@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: abiramen <7523422+abiramen@users.noreply.github.com>
Co-authored-by: Bigbugman <101852152+Bigbugman@users.noreply.github.com>
Co-authored-by: Abraham Assariparambil Earnest <44077482+abe123442@users.noreply.github.com>
Co-authored-by: mi-mott <98304083+mi-mott@users.noreply.github.com>
Co-authored-by: chlowoee <98923921+chlowoee@users.noreply.github.com>
Co-authored-by: ericwu2205 <143063143+ericwu2205@users.noreply.github.com>
Co-authored-by: XenocidePC <34413724+XenocidePC@users.noreply.github.com>
Co-authored-by: h34312575s <134785889+h34312575s@users.noreply.github.com>
Co-authored-by: addison <h34312575s@gmail.com>
Co-authored-by: Jessica Xu <jessica.xu3@student.unsw.edu.au>
  • Loading branch information
17 people authored Jul 18, 2024
1 parent a93bd73 commit 3bf3a61
Show file tree
Hide file tree
Showing 51 changed files with 6,121 additions and 2,774 deletions.
48 changes: 0 additions & 48 deletions .eslintrc.json

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/setup-node@v3
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- run: npm ci
- run: npm run format:check
- run: npm run lint
Expand All @@ -25,7 +25,7 @@ jobs:
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
Expand Down Expand Up @@ -59,12 +59,12 @@ jobs:
name: production (projects-bot)
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: csesoc/deployment
token: ${{ secrets.GH_TOKEN }}
- name: Install yq - portable yaml processor
uses: mikefarah/yq@v4.27.5
uses: mikefarah/yq@v4.44.2
- name: Determine file to update
id: get_manifest
env:
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build layer template for an eventual TS migration
FROM node:16.17.0-slim as builder
FROM node:20.15.0-slim AS builder
ENV NODE_ENV=production

# Set working directory
Expand All @@ -9,9 +9,11 @@ WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev

FROM node:16.17.0-slim
FROM ghcr.io/puppeteer/puppeteer:22.12.1
ENV NODE_ENV=production

USER root

# Set working directory
WORKDIR /app

Expand All @@ -23,5 +25,7 @@ COPY . .

RUN chmod +x entrypoint.sh

USER pptruser

# Run bot
ENTRYPOINT [ "./entrypoint.sh" ]
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
- `DISCORD_TOKEN` with the token of the bot
- `APP_ID` with the ID of the bot application
- Install dependencies with `npm install`
- Register slash commands with `node deploy-commands.js`
- Register slash commands with `npm run deploy` or `node deploy-commands.js`
- Ensure a PostgreSQL database is setup according to "config/database.yml"
- Start the bot with `node index.js`

## Running the bot with Nodemon

- Nodemon has been installed, this addition allows for continuous integration with and hot reloads the bot upon saving.
- Run the bot with Nodemon using `npm run server`
12 changes: 6 additions & 6 deletions commands/admin-standup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed, MessageButton, Permissions } = require("discord.js");
const { EmbedBuilder, ButtonBuilder, Permissions } = require("discord.js");
const paginationEmbed = require("discordjs-button-pagination");

module.exports = {
Expand Down Expand Up @@ -104,7 +104,7 @@ module.exports = {
if (notDone.length == 0) {
standupEmbeded.forEach((el) => {
embedList.push(
new MessageEmbed()
new EmbedBuilder()
.setTitle("Standups (" + role.name + ")")
.setDescription(
el + "\n\n" + "_Everyone has done their standup_\n",
Expand All @@ -114,7 +114,7 @@ module.exports = {
} else {
standupEmbeded.forEach((el) => {
embedList.push(
new MessageEmbed()
new EmbedBuilder()
.setTitle("Standups (" + role.name + ")")
.setDescription(
el +
Expand All @@ -127,7 +127,7 @@ module.exports = {
}

if (thisTeamStandups.length == 0) {
const embed = new MessageEmbed()
const embed = new EmbedBuilder()
.setTitle("Standups (" + role.name + ")")
.setDescription(
"No standups recorded\n\n" +
Expand All @@ -138,11 +138,11 @@ module.exports = {
}

const buttonList = [
new MessageButton()
new ButtonBuilder()
.setCustomId("previousbtn")
.setLabel("Previous")
.setStyle("DANGER"),
new MessageButton().setCustomId("nextbtn").setLabel("Next").setStyle("SUCCESS"),
new ButtonBuilder().setCustomId("nextbtn").setLabel("Next").setStyle("SUCCESS"),
];

paginationEmbed(interaction, embedList, buttonList);
Expand Down
12 changes: 6 additions & 6 deletions commands/anonymouspost.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { SlashCommandBuilder } = require("@discordjs/builders");
const { allowedChannels } = require("../config/anon_channel.json");
const paginationEmbed = require("discordjs-button-pagination");
const fs = require("fs");
const { Util, MessageEmbed, MessageButton, Permissions } = require("discord.js");
const { Util, EmbedBuilder, ButtonBuilder, Permissions } = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("anonymouspost")
Expand Down Expand Up @@ -223,7 +223,7 @@ module.exports = {
} else if (interaction.options.getSubcommand() === "whitelist") {
// No allowed roles
if (allowedChannels.length == 0) {
const embed = new MessageEmbed()
const embed = new EmbedBuilder()
.setTitle("Allowed Channels")
.setDescription("No allowed channels");
return await interaction.reply({ embeds: [embed] });
Expand All @@ -239,7 +239,7 @@ module.exports = {
}

if (channels.length == 0) {
const embed = new MessageEmbed()
const embed = new EmbedBuilder()
.setTitle("Allowed Channels")
.setDescription("No allowed channels");
return await interaction.reply({ embeds: [embed] });
Expand All @@ -250,18 +250,18 @@ module.exports = {
const embedList = [];
for (let i = 0; i < channels.length; i += channelsPerPage) {
embedList.push(
new MessageEmbed()
new EmbedBuilder()
.setTitle("Allowed Channels")
.setDescription(channels.slice(i, i + channelsPerPage).join("\n")),
);
}

const buttonList = [
new MessageButton()
new ButtonBuilder()
.setCustomId("previousbtn")
.setLabel("Previous")
.setStyle("DANGER"),
new MessageButton().setCustomId("nextbtn").setLabel("Next").setStyle("SUCCESS"),
new ButtonBuilder().setCustomId("nextbtn").setLabel("Next").setStyle("SUCCESS"),
];

paginationEmbed(interaction, embedList, buttonList);
Expand Down
4 changes: 2 additions & 2 deletions commands/coinFlip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder().setName("coinflip").setDescription("Tosses a coin 💰"),
Expand All @@ -13,7 +13,7 @@ module.exports = {
: 'http://assets.stickpng.com/thumbs/5a521f522f93c7a8d5137fc7.png';
*/
const img = coinNum === 0 ? "attachment://heads.png" : "attachment://tails.png";
const embed = new MessageEmbed().setTitle(`it's ${coin}!`).setImage(img);
const embed = new EmbedBuilder().setTitle(`it's ${coin}!`).setImage(img);
if (coinNum == 0) {
return await interaction.reply({
embeds: [embed],
Expand Down
50 changes: 33 additions & 17 deletions commands/course.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { ChannelType } = require("discord.js");

const COMMAND_JOIN = "join";
const COMMAND_LEAVE = "leave";
Expand Down Expand Up @@ -35,20 +36,26 @@ const get_real_course_name = (course) => {
};

const is_valid_course = (course) => {
const reg_comp_course = /^comp\d{4}$/;
const reg_math_course = /^math\d{4}$/;
const reg_binf_course = /^binf\d{4}$/;
const reg_engg_course = /^engg\d{4}$/;
const reg_seng_course = /^seng\d{4}$/;
const reg_desn_course = /^desn\d{4}$/;
const reg_valid_course = /^[a-zA-Z]{4}\d{4}$/;

return reg_valid_course.test(course);
};

const is_supported_course = (course) => {
const reg_comp_course = /^comp\d{4}$/i;
const reg_math_course = /^math\d{4}$/i;
const reg_binf_course = /^binf\d{4}$/i;
const reg_engg_course = /^engg\d{4}$/i;
const reg_seng_course = /^seng\d{4}$/i;
const reg_desn_course = /^desn\d{4}$/i;

return (
reg_comp_course.test(course.toLowerCase()) ||
reg_math_course.test(course.toLowerCase()) ||
reg_binf_course.test(course.toLowerCase()) ||
reg_engg_course.test(course.toLowerCase()) ||
reg_seng_course.test(course.toLowerCase()) ||
reg_desn_course.test(course.toLowerCase())
reg_comp_course.test(course) ||
reg_math_course.test(course) ||
reg_binf_course.test(course) ||
reg_engg_course.test(course) ||
reg_seng_course.test(course) ||
reg_desn_course.test(course)
);
};

Expand Down Expand Up @@ -87,20 +94,20 @@ module.exports = {
const input_course = await interaction.options.getString("course").toLowerCase();
const course = get_real_course_name(input_course);

const other_courses = /^[a-zA-Z]{4}\d{4}$/;
const is_valid = is_valid_course(course);
const is_supported = is_supported_course(course);

const course_with_alias =
course != input_course
? `${course} (same course chat as ${input_course})`
: `${course}`;

if (!is_valid && other_courses.test(course.toLowerCase())) {
if (!is_supported && is_valid) {
return await interaction.reply({
content: `❌ | Course chats for other faculties are not supported.`,
ephemeral: true,
});
} else if (!is_valid) {
} else if (!is_supported) {
return await interaction.reply({
content: `❌ | You are not allowed to join this channel using this command.`,
ephemeral: true,
Expand All @@ -120,9 +127,14 @@ module.exports = {
ephemeral: true,
});
}
// // Add it to the existing database to track.
/** @type {DBuser} */
const userDB = global.userDB;
await userDB.add_user_role(interaction.user.id, role.name);

// If they don't, let's add the role to them
await interaction.member.roles.add(role);

return await interaction.reply({
content: `✅ | Added you to the chat for \`${course_with_alias}\`.`,
ephemeral: true,
Expand All @@ -138,7 +150,7 @@ module.exports = {
const input_course = await interaction.options.getString("course");
const course = get_real_course_name(input_course);

if (!is_valid_course(course)) {
if (!is_supported_course(course)) {
return await interaction.reply({
content: `❌ | Not a valid course.`,
ephemeral: true,
Expand All @@ -155,7 +167,7 @@ module.exports = {
content: `❌ | The course chat for \`${course}\` does not exist.`,
ephemeral: true,
});
} else if (channel.type !== "GUILD_TEXT") {
} else if (channel.type !== ChannelType.GuildText) {
return await interaction.reply({
content: `❌ | The course chat for \`${course}\` is not a text channel.`,
ephemeral: true,
Expand Down Expand Up @@ -183,6 +195,10 @@ module.exports = {
in_overwrites(permissions, role.id)
) {
// If they do remove the role
/** @type {DBuser} */
const userDB = global.userDB;
userDB.remove_user_role(interaction.user.id, role.name);

await interaction.member.roles.remove(role);
return await interaction.reply({
content: `✅ | Removed you from the role and chat for \`${course}\`.`,
Expand Down
Loading

0 comments on commit 3bf3a61

Please sign in to comment.