Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions commands/verification/createverification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, MessageFlags } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('createverification')
.setDescription('Create a verification message in a specified channel')
.addChannelOption(option =>
option
.setName('channel')
.setDescription('The channel to create the verification message in')
.setRequired(true)
),
async execute(interaction) {
try {
if (!interaction.member.permissions.has('ManageGuild')) {
return interaction.reply({ content: `You don't have permission to use this command <a:myredmagicreaction:1313432136367472681>`, flags: MessageFlags.Ephemeral });
}

const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId('verify_button')
.setLabel('✅ Start Verification')
.setStyle('Success'),
);

const channel = interaction.options.getChannel('channel')

await channel.send({ content: 'Please click the button below to start the verification process.', components: [row] });
} catch (error) {
console.error('Error creating verification message:', error);
await interaction.reply({ content: 'There was an error creating the verification message.', flags: MessageFlags.Ephemeral });
}
}
}
3 changes: 2 additions & 1 deletion example-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"clientId": "client-id",
"forumChannelId": 12345678910,
"solvedTagId": 12345678910,
"logChannelId": "12345678910"
"logChannelId": "12345678910",
"verificationRoleId": "12345678910"
}
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits, MessageFlags, ChannelType, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const { token, clientId, forumChannelId, solvedTagId } = require('./config.json');
const { token, forumChannelId, solvedTagId } = require('./config.json');
const Fuse = require('fuse.js');

const { createVerificationModal, handleVerificationResponse } = require('./utils/user_verifications');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent] });

client.commands = new Collection();
Expand Down Expand Up @@ -215,6 +215,12 @@ client.on(Events.InteractionCreate, async interaction => {
console.error('Error closing thread:', err);
await interaction.reply({ content: 'There was an error closing the thread.', flags: MessageFlags.Ephemeral });
}
} else if (interaction.isButton() && interaction.customId === 'verify_button') {
await createVerificationModal(interaction);
return;
} else if (interaction.isModalSubmit() && interaction.customId.startsWith('verification_modal_')) {
await handleVerificationResponse(interaction);
return;
}

});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"discord.js": "^14.21.0",
"discord.js": "^14.25.1",
"fuse.js": "^7.1.0"
}
}
7 changes: 7 additions & 0 deletions utils/random_generators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
generateRandomInteger
};

function generateRandomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
52 changes: 52 additions & 0 deletions utils/user_verifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module.exports = {
createVerificationModal,
handleVerificationResponse
};

const { ModalBuilder, LabelBuilder, TextInputStyle, MessageFlags, TextInputBuilder } = require('discord.js');
const { generateRandomInteger } = require('./random_generators');
const config = require('../config.json');

async function createVerificationModal(interaction) {
try {
const integer1 = generateRandomInteger(1, 10);
const integer2 = generateRandomInteger(1, 10);
const correctAnswer = integer1 + integer2;

const modal = new ModalBuilder().setCustomId(`verification_modal_${correctAnswer}`).setTitle('Let\'s get verified!');

const user_input = new TextInputBuilder()
.setCustomId('verification_user_response')
.setStyle(TextInputStyle.Short)
.setPlaceholder('');

const label_modal = new LabelBuilder()
.setLabel(`Verification Question: What is ${integer1} + ${integer2}?`)
.setDescription('This helps us verify you are not a bot.')
.setTextInputComponent(user_input);

modal.addLabelComponents(label_modal);

await interaction.showModal(modal);
} catch (error) {
console.error('Error during verification:', error);
await interaction.reply({ content: 'There was an error during verification.', flags: MessageFlags.Ephemeral });
}
}

async function handleVerificationResponse(interaction) {
try {
const userResponse = interaction.fields.getTextInputValue('verification_user_response');
if (userResponse.trim() === interaction.customId.split('_').pop()) {
const member = await interaction.guild.members.fetch(interaction.user.id);
await member.roles.add(config.verificationRoleId);
await interaction.reply({ content: 'Verification successful! You have access to the server.', flags: MessageFlags.Ephemeral });
} else {
await interaction.reply({ content: 'Verification failed. Please try again.', flags: MessageFlags.Ephemeral });
}
} catch (error) {
console.error('Error processing verification modal:', error);
await interaction.reply({ content: 'There was an error processing your verification.', flags: MessageFlags.Ephemeral });
}
}