changes for making bot public

This commit is contained in:
2023-06-16 23:06:27 +02:00
parent ec64d26496
commit 2551d8e996
10 changed files with 61 additions and 1 deletions
+1
View File
@@ -5,6 +5,7 @@ import {
import { getMemberPermissionsRaw } from '../db' import { getMemberPermissionsRaw } from '../db'
module.exports = { module.exports = {
global: false,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('checkperms') .setName('checkperms')
.addUserOption((option) => .addUserOption((option) =>
+1
View File
@@ -5,6 +5,7 @@ import {
import { execute, type PermsNumbers } from '../db' import { execute, type PermsNumbers } from '../db'
module.exports = { module.exports = {
global: false,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('checkroles') .setName('checkroles')
.setDescription('Prints all roles in the database'), .setDescription('Prints all roles in the database'),
+1
View File
@@ -6,6 +6,7 @@ import {
import { execute } from '../db' import { execute } from '../db'
module.exports = { module.exports = {
global: false,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('delrole') .setName('delrole')
.setDescription('Delete a role from the database') .setDescription('Delete a role from the database')
+1
View File
@@ -7,6 +7,7 @@ import { execute, insertGoob } from '../db'
import { owner_id } from '../config.json' import { owner_id } from '../config.json'
module.exports = { module.exports = {
global: false,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('forceload') .setName('forceload')
.setDescription('Add a message in and its attachements to the database') .setDescription('Add a message in and its attachements to the database')
+1
View File
@@ -5,6 +5,7 @@ import {
import { checkMemberPermissions, deleteGoob, execute } from '../db' import { checkMemberPermissions, deleteGoob, execute } from '../db'
module.exports = { module.exports = {
global: true,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('goob') .setName('goob')
.setDescription('meow').addIntegerOption(option => .setDescription('meow').addIntegerOption(option =>
+1
View File
@@ -8,6 +8,7 @@ import { owner_id } from '../config.json'
import db, { checkMemberPermissions, execute, insertGoob } from '../db' import db, { checkMemberPermissions, execute, insertGoob } from '../db'
module.exports = { module.exports = {
global: false,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('load') .setName('load')
.setDescription('Loads all past goobers from this channel'), .setDescription('Loads all past goobers from this channel'),
+6
View File
@@ -3,8 +3,10 @@ import {
SlashCommandBuilder, PermissionsBitField SlashCommandBuilder, PermissionsBitField
} from 'discord.js' } from 'discord.js'
import { execute } from '../db' import { execute } from '../db'
import { discord_guild_id } from '../config.json'
module.exports = { module.exports = {
global: false,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('setrole') .setName('setrole')
.setDescription('Adds permissions to a discord role') .setDescription('Adds permissions to a discord role')
@@ -37,6 +39,10 @@ module.exports = {
void interaction.reply({ content: 'Cannot find role', ephemeral: true }) void interaction.reply({ content: 'Cannot find role', ephemeral: true })
return return
} }
if (interaction.guildId !== discord_guild_id) {
void interaction.reply({ content: 'I am sorry dave, I\'m afraid I cannot do that\nRole settings are only available in main guild', ephemeral: true })
return
}
if ((interaction.memberPermissions?.has(PermissionsBitField.Flags.ManageRoles, true)) !== true) { if ((interaction.memberPermissions?.has(PermissionsBitField.Flags.ManageRoles, true)) !== true) {
void interaction.reply({ content: 'I am sorry dave, I\'m afraid 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\'m afraid I cannot do that\nYou don\'t have the permission to manage roles on this server', ephemeral: true })
return return
+1
View File
@@ -7,6 +7,7 @@ import { owner_id } from '../config.json'
import db, { execute } from '../db' import db, { execute } from '../db'
module.exports = { module.exports = {
global: false,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('sync') .setName('sync')
.setDescription('Synchronise all past and future goobers from this channel'), .setDescription('Synchronise all past and future goobers from this channel'),
+1 -1
View File
@@ -34,7 +34,7 @@ export async function getMemberPermissionsRaw (member: GuildMember): Promise<Per
read: acc.read + val.read, read: acc.read + val.read,
delete: acc.delete + val.delete delete: acc.delete + val.delete
} }
}, { create: 0, read: 0, delete: 0 }) }, { create: 0, read: 1, delete: 0 })
return userPerms return userPerms
} }
+47
View File
@@ -0,0 +1,47 @@
import { REST, Routes } from 'discord.js'
import { discord_app_id, discord_token } from './config.json'
import path from 'path'
import fs from 'fs'
import { type SlashCommand } from './@types/discordjs'
const commands = [] as SlashCommand[]
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(__dirname, 'commands')
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'))
const promises = [] as Array<Promise<void>>
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file)
promises.push(import(filePath).then(({ default: command, global }) => {
if (global === true) return
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON())
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`)
}
}))
// Set a new item in the Collection with the key as the command name and the value as the exported module
}
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(discord_token)
// and deploy your commands!
void Promise.all(promises).then(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`)
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(discord_app_id),
{ body: commands }
)
console.log(`Successfully reloaded ${(data as string[]).length} application (/) commands.`)
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error)
}
})