Skip to content

Commit

Permalink
added notification for tutors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Siniecki committed Nov 28, 2023
1 parent 501531a commit 30878d6
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/commands/queue/join.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ApplicationCommandOptionType, Message } from "discord.js";
import { Command } from "../../../typings";
import { GuildModel } from "../../models/guilds";
import { UserModel } from "../../models/users";
import {GuildModel} from "../../models/guilds";
import {UserModel} from "../../models/users";
import { SessionModel } from "../../models/sessions";
import { Queue } from "../../models/queues";
import { ArraySubDocumentType } from "@typegoose/typegoose";
import { Bot } from "../../bot";

const command: Command = {
name: "join",
Expand Down Expand Up @@ -89,9 +93,29 @@ const command: Command = {
await client.utils.embeds.SimpleEmbed(interaction, { title: "Coaching System", text: queueData.getJoinMessage(user.id), empheral: true });

// await client.utils.embeds.SimpleEmbed(interaction, "TODO", `Command \`${path.relative(process.cwd(), __filename)}\` is not Implemented Yet.`);

await informCoaches(client, queueData);
},
};

/**
* sends a private message to all coaches having an active session on the given queue
* @param queueData queue the user joined in
*/
async function informCoaches(client: Bot, queueData: ArraySubDocumentType<Queue>) {
const activeSessions = await SessionModel.find({ queue: queueData.id, active: true }).exec();
try {
for(const session of activeSessions) {
const user = await client.users.fetch(session.user);
const dmChannel = await user.createDM();
await client.utils.embeds.SimpleEmbed(dmChannel, { title: "Coaching System", text: `${user.displayName} has joined the queue: ${queueData.name}`, empheral: true });
}
} catch (error) {
console.log(error)
}
}


/**
* Exporting the Command using CommonJS
*/
Expand Down

0 comments on commit 30878d6

Please sign in to comment.