| const { createEmbed } = require('../utils/embeds'); |
| const { Colors } = require('../config'); |
| const { stmts } = require('../database'); |
| const { logVerification } = require('./logger'); |
|
|
| |
| |
| |
| async function sendVerificationEmbed(client) { |
| const row = await stmts.getState('channel_✅・verify'); |
| if (!row) throw new Error('Verify channel not found in bot state.'); |
|
|
| const channel = await client.channels.fetch(row.value); |
| if (!channel) throw new Error('Could not fetch verify channel.'); |
|
|
| const embed = createEmbed({ |
| title: '✅ Verification', |
| description: [ |
| '> Welcome to **Wyvern Softworks**!', |
| '', |
| 'React with ✅ below to verify yourself and gain access to the server.', |
| '', |
| '```', |
| '• You will receive the Verified role', |
| '• Removing your reaction will remove the role', |
| '```', |
| ].join('\n'), |
| color: Colors.SUCCESS, |
| }); |
|
|
| const msg = await channel.send({ embeds: [embed] }); |
| await msg.react('✅'); |
|
|
| |
| await stmts.setState('verify_message_id', msg.id); |
| await stmts.setState('verify_channel_id', channel.id); |
|
|
| return msg; |
| } |
|
|
| |
| |
| |
| |
| async function handleVerifyReaction(reaction, user, client) { |
| |
| const channel = reaction.message.channel; |
| const isVerifyChannel = channel.name === '✅・verify'; |
| const isBotMessage = reaction.message.author?.id === client.user.id; |
|
|
| |
| const stateVal = await stmts.getState('verify_message_id'); |
| const verifyMsgId = stateVal; |
| const isStoredMsg = verifyMsgId && reaction.message.id === verifyMsgId; |
|
|
| if (!isVerifyChannel && !isStoredMsg) return false; |
| if (isVerifyChannel && !isBotMessage) return false; |
| if (reaction.emoji.name !== '✅') return false; |
|
|
| const guild = reaction.message.guild; |
| const member = await guild.members.fetch(user.id).catch(() => null); |
| if (!member) return false; |
|
|
| const role = guild.roles.cache.find(r => r.name === '@@ Verified'); |
| if (!role) return false; |
|
|
| await member.roles.add(role); |
| await logVerification(client, user, 'verified'); |
| return true; |
| } |
|
|
| |
| |
| |
| async function handleVerifyReactionRemove(reaction, user, client) { |
| const channel = reaction.message.channel; |
| const isVerifyChannel = channel.name === '✅・verify'; |
| const isBotMessage = reaction.message.author?.id === client.user.id; |
|
|
| const stateVal = await stmts.getState('verify_message_id'); |
| const verifyMsgId = stateVal; |
| const isStoredMsg = verifyMsgId && reaction.message.id === verifyMsgId; |
|
|
| if (!isVerifyChannel && !isStoredMsg) return false; |
| if (isVerifyChannel && !isBotMessage) return false; |
| if (reaction.emoji.name !== '✅') return false; |
|
|
| const guild = reaction.message.guild; |
| const member = await guild.members.fetch(user.id).catch(() => null); |
| if (!member) return false; |
|
|
| const role = guild.roles.cache.find(r => r.name === '@@ Verified'); |
| if (!role) return false; |
|
|
| await member.roles.remove(role); |
| await logVerification(client, user, 'unverified'); |
| return true; |
| } |
|
|
| module.exports = { sendVerificationEmbed, handleVerifyReaction, handleVerifyReactionRemove }; |
|
|