From fb1729187c14f1060a1779c01b3b5dcae9314457 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Thu, 11 Feb 2021 19:03:16 -0700 Subject: [PATCH 1/4] Announce user join to course channels --- src/controllers/channel/course-selection.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/controllers/channel/course-selection.ts b/src/controllers/channel/course-selection.ts index 4d46a5c..bb791bb 100644 --- a/src/controllers/channel/course-selection.ts +++ b/src/controllers/channel/course-selection.ts @@ -1,8 +1,10 @@ import * as Discord from "discord.js"; import _ from "lodash"; import { Course } from "models/course"; +import { CourseImplementChannelType } from "models/implement/course"; import { Major } from "models/major"; import { CourseService } from "services/course"; +import { CourseImplementService } from "services/implement/course/implement"; import { MemberUpdateService } from "services/member-update"; import { CourseUtils } from "utils/course"; import { DiscordMessageUtils } from "utils/discord-message"; @@ -21,6 +23,19 @@ export class CourseSelectionChannelController extends ChannelController { } else { DiscordMessageUtils.sendMessage(message.channel, `Success! ${message.author}, I have added you to the following courses: ${validCourseNames.join(", ")}.`); } + + for(let course of result.validCourses) { + CourseImplementService.getCourseImplementIfExists(this.guildContext, course) + .then(implement => { + if(implement) { + const courseChannel = this.guildContext.guild.channels.resolve(implement.channelIds[CourseImplementChannelType.CHAT]) as Discord.TextChannel + courseChannel.send(`${message.author} has joined!`); + } + }) + .catch(err => { + console.error("Could not get course implement when announcing user course join:", err); + }) + } }) .catch(errorMessage => { DiscordMessageUtils.sendMessage(message.channel, `${errorMessage} Example usage: join cs1410`); From 05b7ba771332f03c77f17dda163682160fe19f8a Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Tue, 30 Mar 2021 13:45:33 -0600 Subject: [PATCH 2/4] Change welcome message --- src/controllers/channel/course-selection.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/channel/course-selection.ts b/src/controllers/channel/course-selection.ts index bb791bb..1145679 100644 --- a/src/controllers/channel/course-selection.ts +++ b/src/controllers/channel/course-selection.ts @@ -27,14 +27,14 @@ export class CourseSelectionChannelController extends ChannelController { for(let course of result.validCourses) { CourseImplementService.getCourseImplementIfExists(this.guildContext, course) .then(implement => { - if(implement) { - const courseChannel = this.guildContext.guild.channels.resolve(implement.channelIds[CourseImplementChannelType.CHAT]) as Discord.TextChannel - courseChannel.send(`${message.author} has joined!`); + if (implement) { + const courseChannel = this.guildContext.guild.channels.resolve(implement.channelIds[CourseImplementChannelType.CHAT]) as Discord.TextChannel; + courseChannel.send(`Welcome, ${message.author}!`); } }) .catch(err => { console.error("Could not get course implement when announcing user course join:", err); - }) + }); } }) .catch(errorMessage => { From 53af95063405f7214b49f0de0c3a3cfe7d01a5e5 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Tue, 30 Mar 2021 13:45:55 -0600 Subject: [PATCH 3/4] Remove "cs" from examples --- src/controllers/channel/course-selection.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/channel/course-selection.ts b/src/controllers/channel/course-selection.ts index 1145679..9e47bdd 100644 --- a/src/controllers/channel/course-selection.ts +++ b/src/controllers/channel/course-selection.ts @@ -38,7 +38,7 @@ export class CourseSelectionChannelController extends ChannelController { } }) .catch(errorMessage => { - DiscordMessageUtils.sendMessage(message.channel, `${errorMessage} Example usage: join cs1410`); + DiscordMessageUtils.sendMessage(message.channel, `${errorMessage} Example usage: join 1410`); // TODO: Better example. }); } else if (message.content.toLowerCase().startsWith("leave")) { @@ -52,7 +52,7 @@ export class CourseSelectionChannelController extends ChannelController { } }) .catch(errorMessage => { - DiscordMessageUtils.sendMessage(message.channel, `${errorMessage} Example usage: leave cs1410`); + DiscordMessageUtils.sendMessage(message.channel, `${errorMessage} Example usage: leave 1410`); // TODO: Better example. }); } else if (message.content.toLowerCase().startsWith("ta")) { @@ -70,12 +70,12 @@ export class CourseSelectionChannelController extends ChannelController { }); }) .catch(errorMessage => { - DiscordMessageUtils.sendMessage(message.channel, `${errorMessage} Example usage: ta cs1410`); + DiscordMessageUtils.sendMessage(message.channel, `${errorMessage} Example usage: ta 1410`); // TODO: Better example. }); } else { //TODO: Better example - DiscordMessageUtils.sendMessage(message.channel, `${message.author}, I'm not sure what you want to do. Make sure your request starts with 'join', 'leave', or 'ta'. For example: 'join cs1410'`); + DiscordMessageUtils.sendMessage(message.channel, `${message.author}, I'm not sure what you want to do. Make sure your request starts with 'join', 'leave', or 'ta'. For example: 'join 1410'`); } } From 28b32af063f5dde76b601c185a0cc44d791d6be2 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Tue, 30 Mar 2021 14:04:59 -0600 Subject: [PATCH 4/4] Only send welcome message if channel exists. --- src/controllers/channel/course-selection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/channel/course-selection.ts b/src/controllers/channel/course-selection.ts index 9e47bdd..6b065dd 100644 --- a/src/controllers/channel/course-selection.ts +++ b/src/controllers/channel/course-selection.ts @@ -29,7 +29,7 @@ export class CourseSelectionChannelController extends ChannelController { .then(implement => { if (implement) { const courseChannel = this.guildContext.guild.channels.resolve(implement.channelIds[CourseImplementChannelType.CHAT]) as Discord.TextChannel; - courseChannel.send(`Welcome, ${message.author}!`); + courseChannel?.send(`Welcome, ${message.author}!`); } }) .catch(err => {