From 0963a01af22a0382f42253c79036b47bf51c4fcb Mon Sep 17 00:00:00 2001 From: Taken Date: Wed, 3 Jan 2024 21:58:31 +0100 Subject: [PATCH] Added waitinglist update to app accept --- config/options.json | 2 + .../buttons/guildapplicationaccept.ts | 62 ++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/config/options.json b/config/options.json index 0c215e2..8164574 100644 --- a/config/options.json +++ b/config/options.json @@ -10,5 +10,7 @@ "botLogChannel": "1174403585149243472", "guildLogChannel": "1183733282534326322", "errorLogChannel": "1191051275442339951", + "waitingListChannel": "1145773618291298384", + "waitingListMessage": "1146027645415473193", "instructionsgif": "https://cdn.discordapp.com/attachments/838716950723952640/1188211176300089384/4DMu513uNxbM.gif?ex=6599b2e4&is=65873de4&hm=e727c7a39aacbc47d6a5453f4b5f792a45679983c30d662cd258a311381b6df0&" } diff --git a/src/components/buttons/guildapplicationaccept.ts b/src/components/buttons/guildapplicationaccept.ts index 3ffbb84..99629a9 100644 --- a/src/components/buttons/guildapplicationaccept.ts +++ b/src/components/buttons/guildapplicationaccept.ts @@ -1,10 +1,21 @@ -import { ActionRowBuilder, ButtonStyle, ButtonBuilder } from "discord.js" -import { color } from "../../../config/options.json" +import { + ActionRowBuilder, + ButtonStyle, + ButtonBuilder, + GuildTextBasedChannel, +} from "discord.js" +import { + color, + waitingListChannel, + waitingListMessage, + hypixelGuildID, +} from "../../../config/options.json" import mongoose from "mongoose" import guildapp from "../../schemas/guildAppSchema" import waitingList from "../../schemas/waitinglistSchema" import { waitingListRole } from "../../../config/roles.json" import { Button } from "../../interfaces" +import { getGuild } from "../../utils/Hypixel" export = { name: "guildapplicationaccept", @@ -77,6 +88,53 @@ export = { await applicant.roles.add(waitingListRole) await guildapp.findOneAndDelete({ userID: applicantId }) + // update waiting list + const channel = guild.channels.cache.get( + waitingListChannel, + ) as GuildTextBasedChannel + const wlmessage = await channel!.messages.fetch(waitingListMessage) + + const wlembed = wlmessage.embeds[0] + const accepted = await waitingList.find() + + for (let i = 0; i < accepted.length; i++) { + const uuid = accepted[i].uuid + const guild = await getGuild(uuid) + + if (guild && guild._id === hypixelGuildID) { + await waitingList.findOneAndDelete({ uuid: uuid }) + continue + } + } + + const fields: { name: string; value: string }[] = [] + + for (let i = 0; i < accepted.length; i++) { + const timestamp = Math.floor(accepted[i].timestamp / 1000) + + fields.push({ + name: `${i + 1}. ${accepted[i].IGN}`, + value: `TS: `, + }) + } + + await wlmessage.edit({ + embeds: [ + { + title: wlembed.title!, + description: wlembed.description!, + color: wlembed.color!, + footer: { + text: "Last updated by " + user.username, + icon_url: user.avatarURL()!, + }, + thumbnail: wlembed.thumbnail!, + fields: fields, + timestamp: new Date().toISOString(), + }, + ], + }) + await interaction.editReply({ embeds: [ {