Download src/systems/verification.js from APRKDEV/wsb-bot: direct link, hf CLI and curl.
- Browser
- Download file 3.54 kB
-
https://huggingface.co/spaces/APRKDEV/wsb-bot/resolve/c8f3880098432483b23491dd763585274d00f8c8/src/systems/verification.js
- Command line
-
hf download hf://spaces/APRKDEV/wsb-bot@c8f3880098432483b23491dd763585274d00f8c8/src/systems/verification.js
-
curl -L -o verification.js https://huggingface.co/spaces/APRKDEV/wsb-bot/resolve/c8f3880098432483b23491dd763585274d00f8c8/src/systems/verification.js
3.54 kB
| const { createEmbed } = require('../utils/embeds'); | |
| const { Colors } = require('../config'); | |
| const { stmts } = require('../database'); | |
| const { logVerification } = require('./logger'); | |
| /** | |
| * Send the verification embed to the ✅・verify channel. | |
| */ | |
| async function sendVerificationEmbed(client) { | |
| const row = stmts.getState.get('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('✅'); | |
| // Store the message ID so we can listen for reactions | |
| stmts.setState.run('verify_message_id', msg.id); | |
| stmts.setState.run('verify_channel_id', channel.id); | |
| return msg; | |
| } | |
| /** | |
| * Handle verification reaction add. | |
| * Works by checking channel name OR stored message ID (resilient to DB resets). | |
| */ | |
| async function handleVerifyReaction(reaction, user, client) { | |
| // Check if this is a reaction in the verify channel on a bot message | |
| const channel = reaction.message.channel; | |
| const isVerifyChannel = channel.name === '✅・verify'; | |
| const isBotMessage = reaction.message.author?.id === client.user.id; | |
| // Also check stored message ID as fallback | |
| const verifyMsgId = stmts.getState.get('verify_message_id')?.value; | |
| 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; | |
| } | |
| /** | |
| * Handle verification reaction remove. | |
| */ | |
| 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 verifyMsgId = stmts.getState.get('verify_message_id')?.value; | |
| 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 }; | |