From 9873e00fde5be6fccc472a4d905d0336bdbcce84 Mon Sep 17 00:00:00 2001 From: LunaUrsa <1836049+LunaUrsa@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:57:17 -0600 Subject: [PATCH] Bug fixing --- src/discord/events/guildMemberAdd.ts | 41 +++--- src/discord/utils/trust.ts | 196 +++++++++++++++------------ 2 files changed, 132 insertions(+), 105 deletions(-) diff --git a/src/discord/events/guildMemberAdd.ts b/src/discord/events/guildMemberAdd.ts index 45547be62..1dccfc198 100644 --- a/src/discord/events/guildMemberAdd.ts +++ b/src/discord/events/guildMemberAdd.ts @@ -11,23 +11,30 @@ export const guildMemberAdd: GuildMemberAddEvent = { name: 'guildMemberAdd', async execute(member) { await member.fetch(true); - const guildData = await db.discord_guilds.upsert({ - where: { - id: member.guild.id, - cooperative: true, - }, - create: { - id: member.guild.id, - }, - update: {}, - }); - - // log.debug(F, `guildData: ${JSON.stringify(guildData)}`); - - if (!guildData) return; - - if (member.guild.id !== env.DISCORD_GUILD_ID) return; - // await trust(member); + + try { + const guildData = await db.discord_guilds.upsert({ + where: { + id: member.guild.id, + }, + create: { + id: member.guild.id, + }, + update: {}, + }); + + // log.debug(F, `guildData: ${JSON.stringify(guildData)}`); + + if (!guildData) return; + + if (!guildData.cooperative) return; + + await trust(member); + } catch (err) { + log.error(F, `Error: ${err}`); + log.debug(F, `member: ${JSON.stringify(member)}`); + log.debug(F, `member.guild: ${JSON.stringify(member.guild)}`); + } }, }; diff --git a/src/discord/utils/trust.ts b/src/discord/utils/trust.ts index 465b8406e..97c27ddbc 100644 --- a/src/discord/utils/trust.ts +++ b/src/discord/utils/trust.ts @@ -56,103 +56,123 @@ export async function addedVerified( update: {}, }); - if (roleId === env.ROLE_VERIFIED && memberData.trusted === false) { + if (roleId === env.ROLE_VERIFIED && !memberData.trusted) { + if (newMember.joinedAt + && newMember.joinedAt < new Date(Date.now() - 1000 * 60 * 60 * 24)) { // log.debug(F, `${newMember.displayName} verified!`); - // let colorValue = 1; - - // log.debug(F, `member: ${member.roles.cache}`); - - // log.debug(`Verified button clicked by ${interaction.user.username}#${interaction.user.discriminator}`); - const channelTripbotLogs = await global.discordClient.channels.fetch(env.CHANNEL_BOTLOG) as TextChannel; - await channelTripbotLogs.send({ - content: `${newMember.user.username}#${newMember.user.discriminator} was verified!`, - }); - - // NOTE: Can be simplified with luxon - // const diff = Math.abs(Date.now() - Date.parse(newMember.user.createdAt.toString())); - // const years = Math.floor(diff / (1000 * 60 * 60 * 24 * 365)); - // const months = Math.floor(diff / (1000 * 60 * 60 * 24 * 30)); - // const weeks = Math.floor(diff / (1000 * 60 * 60 * 24 * 7)); - // const days = Math.floor(diff / (1000 * 60 * 60 * 24)); - // const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); - // const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); - // const seconds = Math.floor((diff % (1000 * 60)) / 1000); - - // if (years > 0) { - // colorValue = Colors.White; - // } else if (years === 0 && months > 0) { - // colorValue = Colors.Purple; - // } else if (months === 0 && weeks > 0) { - // colorValue = Colors.Blue; - // } else if (weeks === 0 && days > 0) { - // colorValue = Colors.Green; - // } else if (days === 0 && hours > 0) { - // colorValue = Colors.Yellow; - // } else if (hours === 0 && minutes > 0) { - // colorValue = Colors.Orange; - // } else if (minutes === 0 && seconds > 0) { - // colorValue = Colors.Red; - // } - // log.debug(F, `coloValue: ${colorValue}`); - // const channelStart = await newMember.client.channels.fetch(env.CHANNEL_START); - // const channelTechhelp = await newMember.client.channels.fetch(env.CHANNEL_HELPDESK); - // const channelBotspam = await newMember.client.channels.fetch(env.CHANNEL_BOTSPAM); - // const channelRules = await newMember.client.channels.fetch(env.CHANNEL_RULES); - // const channelTripsit = await member.client.channels.fetch(CHANNEL_TRIPSIT); - // const embed = embedTemplate() - // .setAuthor(null) - // .setColor(colorValue) - // .setThumbnail(newMember.user.displayAvatarURL()) - // .setFooter(null) - // .setDescription(stripIndents` - // **Please welcome ${newMember.toString()} to the guild!** - // Be safe, have fun, /report any issues!`); - - const greetingList = [ - `Welcome to the guild, ${newMember}!`, - `I'm proud to announce that ${newMember} has joined our guild!`, - `Please welcome ${newMember} to our guild!`, - `Hello, ${newMember}! Welcome to our guild!`, - `Welcome to the family, ${newMember}! We're so glad you're here.`, - `Welcome to the guild, ${newMember}!`, - `We're excited to have ${newMember} as part of our guild!`, - `Say hello to our newest member, ${newMember}!`, - `Let's give a warm welcome to ${newMember}!`, - `It's great to see you here, ${newMember}!`, - `Welcome aboard, ${newMember}!`, - `We're happy to have ${newMember} join us!`, - `Say hi to ${newMember}, our newest member!`, - `Join us in welcoming ${newMember} to our guild!`, - `A big welcome to ${newMember}!`, - ]; - - const greeting = greetingList[Math.floor(Math.random() * greetingList.length)]; - - const channelLounge = await newMember.client.channels.fetch(env.CHANNEL_LOUNGE) as TextChannel; - await channelLounge.send({ - content: stripIndents`**${greeting}** + // let colorValue = 1; + + // log.debug(F, `member: ${member.roles.cache}`); + + // log.debug(`Verified button clicked by ${interaction.user.username}#${interaction.user.discriminator}`); + const channelTripbotLogs = await global.discordClient.channels.fetch(env.CHANNEL_BOTLOG) as TextChannel; + await channelTripbotLogs.send({ + content: `${newMember.user.username}#${newMember.user.discriminator} was verified!`, + }); + + // NOTE: Can be simplified with luxon + // const diff = Math.abs(Date.now() - Date.parse(newMember.user.createdAt.toString())); + // const years = Math.floor(diff / (1000 * 60 * 60 * 24 * 365)); + // const months = Math.floor(diff / (1000 * 60 * 60 * 24 * 30)); + // const weeks = Math.floor(diff / (1000 * 60 * 60 * 24 * 7)); + // const days = Math.floor(diff / (1000 * 60 * 60 * 24)); + // const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); + // const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); + // const seconds = Math.floor((diff % (1000 * 60)) / 1000); + + // if (years > 0) { + // colorValue = Colors.White; + // } else if (years === 0 && months > 0) { + // colorValue = Colors.Purple; + // } else if (months === 0 && weeks > 0) { + // colorValue = Colors.Blue; + // } else if (weeks === 0 && days > 0) { + // colorValue = Colors.Green; + // } else if (days === 0 && hours > 0) { + // colorValue = Colors.Yellow; + // } else if (hours === 0 && minutes > 0) { + // colorValue = Colors.Orange; + // } else if (minutes === 0 && seconds > 0) { + // colorValue = Colors.Red; + // } + // log.debug(F, `coloValue: ${colorValue}`); + // const channelStart = await newMember.client.channels.fetch(env.CHANNEL_START); + // const channelTechhelp = await newMember.client.channels.fetch(env.CHANNEL_HELPDESK); + // const channelBotspam = await newMember.client.channels.fetch(env.CHANNEL_BOTSPAM); + // const channelRules = await newMember.client.channels.fetch(env.CHANNEL_RULES); + // const channelTripsit = await member.client.channels.fetch(CHANNEL_TRIPSIT); + // const embed = embedTemplate() + // .setAuthor(null) + // .setColor(colorValue) + // .setThumbnail(newMember.user.displayAvatarURL()) + // .setFooter(null) + // .setDescription(stripIndents` + // **Please welcome ${newMember.toString()} to the guild!** + // Be safe, have fun, /report any issues!`); + + const greetingList = [ + `Welcome to the guild, ${newMember}!`, + `I'm proud to announce that ${newMember} has joined our guild!`, + `Please welcome ${newMember} to our guild!`, + `Hello, ${newMember}! Welcome to our guild!`, + `Welcome to the family, ${newMember}! We're so glad you're here.`, + `Welcome to the guild, ${newMember}!`, + `We're excited to have ${newMember} as part of our guild!`, + `Say hello to our newest member, ${newMember}!`, + `Let's give a warm welcome to ${newMember}!`, + `It's great to see you here, ${newMember}!`, + `Welcome aboard, ${newMember}!`, + `We're happy to have ${newMember} join us!`, + `Say hi to ${newMember}, our newest member!`, + `Join us in welcoming ${newMember} to our guild!`, + `A big welcome to ${newMember}!`, + ]; + + const greeting = greetingList[Math.floor(Math.random() * greetingList.length)]; + + const channelLounge = await newMember.client.channels.fetch(env.CHANNEL_LOUNGE) as TextChannel; + await channelLounge.send({ + content: stripIndents`**${greeting}** Be safe, have fun, and don't forget to visit the for more information! *${await topic()}*`, - }); + }); - await db.members.upsert({ - where: { - id_guild_id: { + await db.members.upsert({ + where: { + id_guild_id: { + guild_id: newMember.guild.id, + id: newMember.id, + }, + }, + create: { guild_id: newMember.guild.id, id: newMember.id, + trusted: true, }, - }, - create: { - guild_id: newMember.guild.id, - id: newMember.id, - trusted: true, - }, - update: { - trusted: true, - }, - }); + update: { + trusted: true, + }, + }); + } else { + await db.members.upsert({ + where: { + id_guild_id: { + guild_id: newMember.guild.id, + id: newMember.id, + }, + }, + create: { + guild_id: newMember.guild.id, + id: newMember.id, + trusted: true, + }, + update: { + trusted: true, + }, + }); + } } }