Compare commits

..

6 Commits

7 changed files with 60 additions and 97 deletions

View File

@ -2,6 +2,7 @@ import { Message } from '../../database.js';
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js'; import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js';
export const data = new ContextMenuCommandBuilder() export const data = new ContextMenuCommandBuilder()
.setDMPermission(false)
.setName('Register self roles') .setName('Register self roles')
.setType(ApplicationCommandType.Message); .setType(ApplicationCommandType.Message);
export async function execute(interaction) { export async function execute(interaction) {

View File

@ -0,0 +1,30 @@
import { Message } from '../../database.js';
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js';
export const data = new ContextMenuCommandBuilder()
.setDMPermission(false)
.setName('Register self roles')
.setType(ApplicationCommandType.Message);
export async function execute(interaction) {
const id = interaction.targetMessage.id;
try {
// Create database entry
await Message.create({ id });
// Reply successfully to acknowledge command
await interaction.reply({
content: `Successfully saved data from message! Add roles to it with reference ID '${id}'.`,
ephemeral: true,
});
console.info(`[INFO] New self roles on message with ID: '${id}'.`);
} catch (error) {
console.error(error);
// Reply failed to acknowledge command
await interaction.reply({
content: 'Failed to save data from message!',
ephemeral: true,
});
}
}

View File

@ -113,6 +113,7 @@ const addSelfRoles = async (interaction) => {
export const data = new SlashCommandBuilder() export const data = new SlashCommandBuilder()
.setName('self_roles') .setName('self_roles')
.setDMPermission(false)
.setDescription('Manages reactions for self roles.') .setDescription('Manages reactions for self roles.')
.addSubcommand(subcommand => .addSubcommand(subcommand =>
subcommand subcommand

View File

@ -1,41 +0,0 @@
import {
ActionRowBuilder,
ModalBuilder,
SlashCommandBuilder,
TextInputBuilder,
TextInputStyle
} from 'discord.js';
export const data = new SlashCommandBuilder()
.setName('login')
.setDescription('Opens a login pop-up.');
export async function modalSubmit(interaction) {
await interaction.reply({
content: 'Successfully submitted Form!',
ephemeral: true
});
}
export async function execute(interaction) {
const modal = new ModalBuilder()
.setCustomId('login-modal')
.setTitle('Login Form');
const user = new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('user')
.setLabel('Enter username:')
.setStyle(TextInputStyle.Short)
.setRequired(true)
);
const password = new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('password')
.setLabel('Enter password:')
.setStyle(TextInputStyle.Short)
.setRequired(true)
);
modal.addComponents(user, password);
await interaction.showModal(modal);
}

View File

@ -1,48 +0,0 @@
import {
ActionRowBuilder,
ComponentType,
RoleSelectMenuBuilder,
SlashCommandBuilder
} from 'discord.js';
export const data = new SlashCommandBuilder()
.setName('role_selector')
.setDMPermission(false)
.setDescription('Provides a role selector.');
export async function execute(interaction) {
const roles = await interaction.guild.roles.fetch();
const choices = roles
.filter((r) => r.name.startsWith('test'))
.map((r) => r.id);
const button = new RoleSelectMenuBuilder()
.setMinValues(1)
.setMaxValues(25)
.setCustomId('role')
.setDefaultRoles(choices)
.setPlaceholder('Select at least one role.');
const row = new ActionRowBuilder()
.addComponents(button);
const response = await interaction.reply({
components: [row],
ephemeral: true
});
const collector = response.createMessageComponentCollector({
componentType: ComponentType.RoleSelect,
time: 120_000
});
collector.on('collect', async (i) => {
const selection = roles
.filter((r) => i.values.includes(r.id))
.map((r) => r.name)
.join(', ');
await i.reply({
content: `You have selected: "${selection}".`,
ephemeral: true
});
});
}

View File

@ -35,9 +35,19 @@ export async function execute(reaction, user) {
// Fetch role from guild // Fetch role from guild
const guild = reaction.message.guild; const guild = reaction.message.guild;
const role = await guild.roles.fetch(rep.role); const role = await guild.roles.fetch(rep.role);
if (role === null) return; // Role not found
if (role === null) {
await user.send('Could not fetch role! Please contact server staff.');
return;
}
// Add role to user try {
await guild.members.addRole({ role, user }); // Add role to user
console.info(`[INFO] Added role with id '${role.id}' to user '${user.username}'.`); await guild.members.addRole({ role, user });
console.info(`[INFO] Added role with id '${role.id}' to user '${user.username}'.`);
} catch (error) {
// Missing permissions
console.error(error);
await user.send('Unable to assign role. Please contact server staff.');
}
} }

View File

@ -31,9 +31,19 @@ export async function execute(reaction, user) {
// Fetch role from guild // Fetch role from guild
const guild = reaction.message.guild; const guild = reaction.message.guild;
const role = await guild.roles.fetch(rep.role); const role = await guild.roles.fetch(rep.role);
if (role === null) return; // Role not found
if (role === null) {
await user.send('Could not fetch role! Please contact server staff.');
return;
}
// Add role to user try {
await guild.members.removeRole({ role, user }); // Remove role from user
console.info(`[INFO] Removed role with id '${role.id}' from user '${user.username}'.`); await guild.members.removeRole({ role, user });
console.info(`[INFO] Removed role with id '${role.id}' from user '${user.username}'.`);
} catch (error) {
// Missing permissions
console.error(error);
await user.send('Unable to retract role. Please contact server staff.');
}
} }