add checkRoles

This commit is contained in:
2023-06-16 17:38:48 +02:00
parent e211fa3c03
commit 4f92a7b8e9
2 changed files with 12 additions and 33 deletions
+12 -29
View File
@@ -2,51 +2,34 @@ import {
type CommandInteraction,
SlashCommandBuilder, EmbedBuilder, PermissionsBitField
} from 'discord.js'
import { execute, obj2role } from '../db'
import { execute, role2obj } from '../db'
module.exports = {
data: new SlashCommandBuilder()
.setName('checkroles')
.setDescription('Prints all role permissions'),
.setDescription('Prints all roles permissions'),
async execute (interaction: CommandInteraction) {
const role = interaction.options.get('role')?.value
if (role === undefined) {
await interaction.reply({ content: 'Cannot find role', ephemeral: true })
return
}
if ((interaction.memberPermissions?.has(PermissionsBitField.Flags.ManageRoles, true)) !== true) {
await interaction.reply({ content: 'I am sorry dave, I cannot do that\nYou don\'t have the permission to manage roles on this server', ephemeral: true })
return
}
// Set Role
await execute('DELETE FROM permissions WHERE guild=$guild AND role=$role',
{
$guild: interaction.guildId,
$role: role
})
const permissions = {
create: Boolean(interaction.options.get('create_permission')?.value),
delete: Boolean(interaction.options.get('delete_permission')?.value)
}
await execute('INSERT INTO permissions (guild, role, permissions) VALUES($guild, $role, $permissions)',
{
$guild: interaction.guildId,
$role: role,
$permissions: obj2role(permissions)
})
const permissionList = await execute('SELECT * FROM permissions') as Array<{ guild: string, role: string, permissions: number }>
const statusUpdate = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Role updated successfully')
.addFields(
{ name: 'Role', value: `<@&${role.toString()}>` },
.setTitle('List of roles')
.setTimestamp()
permissionList.forEach(e => {
const permissions = role2obj(e.permissions)
statusUpdate.addFields(
{ name: 'Role', value: `<@&${e.role.toString()}>` },
{ name: 'Can add goobs', value: permissions.create ? '🟩' : '🟥', inline: true },
{ name: 'Can delete goobs', value: permissions.delete ? '🟩' : '🟥', inline: true }
)
.setTimestamp()
})
await interaction.reply({ embeds: [statusUpdate], ephemeral: true })
}
}
-4
View File
@@ -132,9 +132,5 @@ module.exports = {
$last_message: reply.id
}
)
// interaction.user is the object representing the User who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
// await interaction.reply(`This command was run by ${interaction.user.username}`)
}
}