add delrole and checkperms commands
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
import {
|
||||||
|
type CommandInteraction,
|
||||||
|
SlashCommandBuilder, EmbedBuilder, type GuildMember
|
||||||
|
} from 'discord.js'
|
||||||
|
import { execute, role2obj } from '../db'
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('checkperms')
|
||||||
|
.addUserOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('user')
|
||||||
|
.setDescription('The user to check the roles of')
|
||||||
|
.setRequired(true))
|
||||||
|
.setDescription('Check permission of an user for goobot'),
|
||||||
|
async execute (interaction: CommandInteraction) {
|
||||||
|
if (interaction.guild === null) {
|
||||||
|
void interaction.reply({ content: 'I am sorry dave, I cannot do that\nCommand not available outside of guilds', ephemeral: true })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let member = interaction.member as GuildMember | null
|
||||||
|
if (interaction.options.get('user') !== undefined) member = interaction.options.getMember('user') as GuildMember | null
|
||||||
|
|
||||||
|
if (member === null) {
|
||||||
|
void interaction.reply({ content: 'Can`t find member', ephemeral: true })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const allPermissions = await execute('SELECT * FROM permissions WHERE guild=$guild', { $guild: interaction.guildId }) as Array<{ guild: string, role: string, permissions: number }>
|
||||||
|
console.log(allPermissions)
|
||||||
|
const userPermsBitField = allPermissions.reduce((acc, val) =>
|
||||||
|
member?.roles.cache.some(r => r.id === val.role.toString()) === true ? acc | val.permissions : acc
|
||||||
|
, 0)
|
||||||
|
|
||||||
|
const permissions = role2obj(userPermsBitField)
|
||||||
|
const statusUpdate = new EmbedBuilder()
|
||||||
|
.setColor(0x0099FF)
|
||||||
|
.setTitle('List of roles')
|
||||||
|
.setTimestamp()
|
||||||
|
.addFields(
|
||||||
|
{ name: 'User', value: `<@${member.id}>` },
|
||||||
|
{ name: 'Can add goobs', value: permissions.create ? '🟩' : '🟥', inline: true },
|
||||||
|
{ name: 'Can delete goobs', value: permissions.delete ? '🟩' : '🟥', inline: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [statusUpdate], ephemeral: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,11 @@ module.exports = {
|
|||||||
.setName('checkroles')
|
.setName('checkroles')
|
||||||
.setDescription('Prints all roles permissions'),
|
.setDescription('Prints all roles permissions'),
|
||||||
async execute (interaction: CommandInteraction) {
|
async execute (interaction: CommandInteraction) {
|
||||||
|
if (interaction.guild === null) {
|
||||||
|
void interaction.reply({ content: 'I am sorry dave, I cannot do that\nCommand not available outside of guilds', ephemeral: true })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if ((interaction.memberPermissions?.has(PermissionsBitField.Flags.ManageRoles, true)) !== true) {
|
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 })
|
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
|
return
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import {
|
||||||
|
type CommandInteraction,
|
||||||
|
SlashCommandBuilder,
|
||||||
|
PermissionsBitField
|
||||||
|
} from 'discord.js'
|
||||||
|
import { execute } from '../db'
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('delrole')
|
||||||
|
.setDescription('Delete a role from the database')
|
||||||
|
.addRoleOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('role')
|
||||||
|
.setDescription('The role to delete')
|
||||||
|
.setRequired(true)
|
||||||
|
),
|
||||||
|
async execute (interaction: CommandInteraction) {
|
||||||
|
if (interaction.guild === null) {
|
||||||
|
void interaction.reply({ content: 'I am sorry dave, I cannot do that\nCommand not available outside of guilds', 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
|
||||||
|
}
|
||||||
|
|
||||||
|
await execute('DELETE FROM permissions WHERE role=$role AND guild=$guild', { $role: interaction.options.get('role')?.value, $guild: interaction.guildId })
|
||||||
|
|
||||||
|
await interaction.client.commands.get('checkroles')?.execute(interaction)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,11 +29,11 @@ module.exports = {
|
|||||||
|
|
||||||
const role = interaction.options.get('role')?.value
|
const role = interaction.options.get('role')?.value
|
||||||
if (role === undefined) {
|
if (role === undefined) {
|
||||||
await interaction.reply({ content: 'Cannot find role', ephemeral: true })
|
void interaction.reply({ content: 'Cannot find role', ephemeral: true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ((interaction.memberPermissions?.has(PermissionsBitField.Flags.ManageRoles, true)) !== true) {
|
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 })
|
void 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
|
return
|
||||||
}
|
}
|
||||||
// Set Role
|
// Set Role
|
||||||
|
|||||||
Reference in New Issue
Block a user