Updated guild application accept

This commit is contained in:
2024-01-13 16:48:39 +01:00
parent 5a1db24030
commit ed1001fc78

View File

@@ -10,6 +10,7 @@ import {
waitingListMessage, waitingListMessage,
hypixelGuildID, hypixelGuildID,
} from "../../../config/options.json" } from "../../../config/options.json"
import colorLog from "../../utils/functions/colors"
import mongoose from "mongoose" import mongoose from "mongoose"
import guildapp from "../../schemas/guildAppSchema" import guildapp from "../../schemas/guildAppSchema"
import waitingList from "../../schemas/waitinglistSchema" import waitingList from "../../schemas/waitinglistSchema"
@@ -88,53 +89,6 @@ export = {
await applicant.roles.add(waitingListRole) await applicant.roles.add(waitingListRole)
await guildapp.findOneAndDelete({ userID: applicantId }) await guildapp.findOneAndDelete({ userID: applicantId })
// update waiting list
const channel = guild.channels.cache.get(
waitingListChannel,
) as TextChannel
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: <t:${timestamp}:R>`,
})
}
await wlmessage.edit({
embeds: [
{
title: wlembed.title!,
description: wlembed.description!,
color: wlembed.color!,
footer: {
text: "Last updated by " + user.username,
icon_url: user.avatarURL() || undefined,
},
thumbnail: wlembed.thumbnail!,
fields: fields,
timestamp: new Date().toISOString(),
},
],
})
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
{ {
@@ -152,5 +106,56 @@ export = {
}, },
], ],
}) })
if (process.env.NODE_ENV === "dev") return
try {
const channel = guild.channels.cache.get(
waitingListChannel,
) as TextChannel
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: <t:${timestamp}:R>`,
})
}
await wlmessage.edit({
embeds: [
{
title: wlembed.title!,
description: wlembed.description!,
color: wlembed.color!,
footer: {
text: "Last updated by " + user.username,
icon_url: user.avatarURL() || undefined,
},
thumbnail: wlembed.thumbnail!,
fields: fields,
timestamp: new Date().toISOString(),
},
],
})
} catch (err) {
console.log(colorLog("Error while trying to update waiting list.", "red"))
}
}, },
} as Button } as Button