diff --git a/src/commands/admin.ts b/src/commands/admin.ts index 446efef..f0c769b 100644 --- a/src/commands/admin.ts +++ b/src/commands/admin.ts @@ -4,6 +4,7 @@ import { ButtonStyle, ChatInputCommandInteraction, Guild, + InteractionContextType, PermissionFlagsBits, SlashCommandBuilder, bold, @@ -19,7 +20,7 @@ export const help = new CommandHelpEntry('admin', 'Admin commands'); export const data = new SlashCommandBuilder() .setName('admin') .setDescription('Automatically run admin tasks') - .setDMPermission(false) + .setContexts(InteractionContextType.Guild) .setDefaultMemberPermissions( PermissionFlagsBits.ManageGuild | PermissionFlagsBits.ManageRoles | diff --git a/src/commands/announce.ts b/src/commands/announce.ts index 73166ff..224c5fa 100644 --- a/src/commands/announce.ts +++ b/src/commands/announce.ts @@ -2,6 +2,7 @@ import { BaseGuildTextChannel, ChannelType, ChatInputCommandInteraction, + InteractionContextType, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; @@ -10,7 +11,7 @@ import { CommandHelpEntry } from '../struct/CommandHelpEntry'; export const data = new SlashCommandBuilder() .setName('announce') .setDescription('Creates an announcement in the specified channel') - .setDMPermission(false) + .setContexts(InteractionContextType.Guild) .addChannelOption(option => { return option .setName('channel') diff --git a/src/commands/coghelp.ts b/src/commands/coghelp.ts index 5242e75..46c2274 100644 --- a/src/commands/coghelp.ts +++ b/src/commands/coghelp.ts @@ -8,8 +8,6 @@ import { CommandHelpEntry } from '../struct/CommandHelpEntry'; import { Jsoning } from 'jsoning'; import { Collection } from '@discordjs/collection'; -const db = new Jsoning('botfiles/cmnds.db.json'); - export const help = new CommandHelpEntry( 'coghelp', 'Shows general help or help for a specific command', @@ -24,7 +22,7 @@ export const data = new SlashCommandBuilder() .setName('command') .setDescription('The command to show help for') .setChoices( - ...Object.keys(db.all()).map(key => { + ...Object.keys(new Jsoning('botfiles/cmnds.db.json').all()).map(key => { return { name: key, value: key }; }) ) @@ -45,7 +43,10 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { .setColor(0x00ff00); const command = interaction.options.getString('command'); const fields = new Collection( - Object.values(db.all()).map(v => [v.name, CommandHelpEntry.fromJSON(v)]) + Object.values(new Jsoning('botfiles/cmnds.db.json').all()).map(v => [ + v.name, + CommandHelpEntry.fromJSON(v) + ]) ); if (!command) embed.setFields(...fields.map(v => v.toDiscordAPIEmbedField())); else if (fields.has(command)) diff --git a/src/commands/conf.ts b/src/commands/conf.ts index cff34f7..758ad2c 100644 --- a/src/commands/conf.ts +++ b/src/commands/conf.ts @@ -3,6 +3,7 @@ import { ChannelType, ChatInputCommandInteraction, EmbedBuilder, + InteractionContextType, NewsChannel, PermissionFlagsBits, SlashCommandBuilder, @@ -19,7 +20,7 @@ import { DENO_KV_URL, DatabaseKeys } from '../config'; export const data = new SlashCommandBuilder() .setName('conf') .setDescription('Configure DisCog for your server') - .setDMPermission(false) + .setContexts(InteractionContextType.Guild) .setDefaultMemberPermissions( PermissionFlagsBits.ManageGuild | PermissionFlagsBits.ViewAuditLog ) diff --git a/src/commands/dev.ts b/src/commands/dev.ts index 8e6d2cf..c449510 100644 --- a/src/commands/dev.ts +++ b/src/commands/dev.ts @@ -10,8 +10,6 @@ import { } from 'discord.js'; import Jsoning from 'jsoning'; -const db = new Jsoning('botfiles/dev.db.json'); - export const data = new SlashCommandBuilder() .setName('dev') .setDescription('Developer-only command') @@ -87,6 +85,7 @@ export const data = new SlashCommandBuilder() .setDMPermission(true); export const execute = async (interaction: ChatInputCommandInteraction) => { + const db = new Jsoning('botfiles/dev.db.json'); const whitelist = ((await db.get('whitelist')) as string[]) || []; const blacklist = ((await db.get('blacklist')) as string[]) || []; if (!whitelist.includes(interaction.user.id)) { diff --git a/src/commands/dm.ts b/src/commands/dm.ts index 68c113d..06c91d1 100644 --- a/src/commands/dm.ts +++ b/src/commands/dm.ts @@ -2,6 +2,7 @@ import { ChatInputCommandInteraction, EmbedBuilder, GuildMember, + InteractionContextType, PermissionFlagsBits, SlashCommandBuilder, userMention @@ -23,7 +24,7 @@ export const data = new SlashCommandBuilder() .setDescription('The message to send') .setRequired(true); }) - .setDMPermission(false) + .setContexts(InteractionContextType.Guild) .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild); export const help = new CommandHelpEntry( diff --git a/src/commands/info.ts b/src/commands/info.ts index 9a058e2..e20bae2 100644 --- a/src/commands/info.ts +++ b/src/commands/info.ts @@ -2,6 +2,7 @@ import { ChannelType, ChatInputCommandInteraction, EmbedBuilder, + InteractionContextType, SlashCommandBuilder, channelMention, inlineCode, @@ -19,7 +20,7 @@ export const data = new SlashCommandBuilder() .addSubcommand(subcommand => { return subcommand.setName('channel').setDescription('Channel info'); }) - .setDMPermission(false); + .setContexts(InteractionContextType.Guild); export const help = new CommandHelpEntry('info', 'Gets some info', [ 'channel', diff --git a/src/commands/poll.ts b/src/commands/poll.ts index 948e823..d2ef7db 100644 --- a/src/commands/poll.ts +++ b/src/commands/poll.ts @@ -2,6 +2,7 @@ import { BaseGuildTextChannel, ChatInputCommandInteraction, EmbedBuilder, + InteractionContextType, SlashCommandBuilder, userMention } from 'discord.js'; @@ -10,7 +11,8 @@ import { CommandHelpEntry } from '../struct/CommandHelpEntry'; export const data = new SlashCommandBuilder() .setName('poll') .setDescription('Create a poll') - .setDMPermission(false) + .setContexts(InteractionContextType.Guild) + // #region data .addStringOption(option => { return option diff --git a/src/commands/user.json.ts b/src/commands/user.json.ts index 4cafb3b..9671082 100644 --- a/src/commands/user.json.ts +++ b/src/commands/user.json.ts @@ -1,6 +1,9 @@ -import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js'; +import { + ApplicationCommandType, + ContextMenuCommandBuilder, + ContextMenuCommandType +} from 'discord.js'; export const data = new ContextMenuCommandBuilder() .setName('User JSON') - .setType(ApplicationCommandType.User) - .setDMPermission(true); + .setType(ApplicationCommandType.User as ContextMenuCommandType); diff --git a/src/commands/user.userinfo.ts b/src/commands/user.userinfo.ts index 5c4af30..c3899fc 100644 --- a/src/commands/user.userinfo.ts +++ b/src/commands/user.userinfo.ts @@ -1,6 +1,9 @@ -import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js'; +import { + ApplicationCommandType, + ContextMenuCommandBuilder, + ContextMenuCommandType +} from 'discord.js'; export const data = new ContextMenuCommandBuilder() .setName('User Info') - .setType(ApplicationCommandType.User) - .setDMPermission(true); + .setType(ApplicationCommandType.User as ContextMenuCommandType); diff --git a/src/index.ts b/src/index.ts index a4a6f6c..607a85a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -39,7 +39,6 @@ if (argv.includes('-d')) { logger.debug('Debug mode enabled.'); } -const db = await openKv(DENO_KV_URL); logger.debug('Loaded dev database.'); const client = new CommandClient({ @@ -180,7 +179,11 @@ client .on(Events.InteractionCreate, async interaction => { if (interaction.user.bot) return; try { - const blacklisted = (await db.get([DatabaseKeys.Blacklist]))?.value; + const blacklisted = ( + await ( + await openKv(DENO_KV_URL) + ).get([DatabaseKeys.Blacklist]) + )?.value; if ( (blacklisted ?? []).includes(interaction.user.id) && interaction.isCommand() @@ -191,7 +194,9 @@ client }); return; } - } catch (e) { logger.error(e); } + } catch (e) { + logger.error(e); + } if (interaction.isChatInputCommand()) { const command = client.commands.get(interaction.commandName); @@ -333,7 +338,9 @@ logger.info('Process setup complete.'); async function bdayInterval() { const today = new Date(); const allBirthdays: { id: string; data: BirthdayData }[] = []; - for await (const val of db.list({ prefix: [DatabaseKeys.Bday] })) + for await (const val of (await openKv(DENO_KV_URL)).list({ + prefix: [DatabaseKeys.Bday] + })) allBirthdays.push({ id: val.key[1].toString(), data: val.value as BirthdayData @@ -383,8 +390,9 @@ async function bdayInterval() { } async function sendError(e: Error) { - for (const devId of (await db.get([DatabaseKeys.Devs]))?.value ?? - []) { + for (const devId of ( + await (await openKv(DENO_KV_URL)).get([DatabaseKeys.Devs]) + )?.value ?? []) { client.users.fetch(devId).then(user => { const date = new Date(); user.send({