Archived
0
0
Fork 0

feat(commands): added running in

This commit is contained in:
Daryl Ronningen 2021-06-20 04:43:21 -07:00
parent c03ed1fde8
commit 727ac245ff
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
2 changed files with 23 additions and 4 deletions

View file

@ -25,7 +25,7 @@ import { Validator } from 'jsonschema';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { Client, Collection } from 'discord.js'; import { Client, Collection } from 'discord.js';
import { debug, error, fatal, info, verbose } from '@utils/logger'; import { debug, error, fatal, info, verbose } from '@utils/logger';
import { ELoggingScope } from '@utils/types'; import { ECommandRunIn, ELoggingScope } from '@utils/types';
import { Defaults } from '@utils/defaults'; import { Defaults } from '@utils/defaults';
import { walkDir } from '@utils/utils'; import { walkDir } from '@utils/utils';
@ -68,7 +68,7 @@ const client = new Client({
intents: ['GUILDS', 'GUILD_MESSAGES'], intents: ['GUILDS', 'GUILD_MESSAGES'],
}); });
client.on('message', (msg) => { client.on('message', async (msg) => {
if(!isBotReady) return; if(!isBotReady) return;
if(msg.author.bot) return; if(msg.author.bot) return;
@ -80,7 +80,18 @@ client.on('message', (msg) => {
const findCommand = commands.find((com) => com.options.name === command); const findCommand = commands.find((com) => com.options.name === command);
if(!findCommand) return; if(!findCommand) return;
else findCommand.run(msg, ...args);
if((findCommand.options.runIn === ECommandRunIn.DM) && msg.channel.type !== 'dm') {
await msg.reply('You can only run this command in DMs!');
return;
}
if((findCommand.options.runIn === ECommandRunIn.Server) && msg.channel.type !== 'text') {
await msg.reply('You can only run this command in a server!');
return;
}
findCommand.run(msg, ...args);
}); });
client.on('ready', async () => { client.on('ready', async () => {
@ -89,7 +100,7 @@ client.on('ready', async () => {
try { try {
const files = await walkDir(`${__dirname}/commands`); const files = await walkDir(`${__dirname}/commands`);
files?.forEach(async (file) => { files?.forEach((file) => {
if(file.endsWith('js')) { if(file.endsWith('js')) {
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const fileCommand = require(file).default; const fileCommand = require(file).default;

View file

@ -22,11 +22,19 @@ export enum ELoggingScope {
Query = 'QUERY', Query = 'QUERY',
} }
export enum ECommandRunIn {
DM,
Server,
Both,
}
// Interfaces // Interfaces
export interface ICommandOptions { export interface ICommandOptions {
name: string; name: string;
shortDescription: string; shortDescription: string;
extendedDescription: string; extendedDescription: string;
group: string;
runIn: ECommandRunIn;
} }
// Type Aliases // Type Aliases