djs-commander
Advanced tools
Comparing version 0.0.45 to 0.0.46
@@ -186,3 +186,4 @@ "use strict"; | ||
commands: localCommands, | ||
testServer | ||
testServer, | ||
logger | ||
}) { | ||
@@ -204,3 +205,8 @@ const applicationCommands = yield getAppCommands(client, testServer); | ||
yield applicationCommands.delete(existingCommand.id); | ||
console.log(`\u{1F5D1} Deleted command "${name}".`); | ||
let message = `\u{1F5D1} Deleted command "${name}".`; | ||
if (logger) { | ||
logger.info(message); | ||
} else { | ||
console.log(message); | ||
} | ||
continue; | ||
@@ -213,7 +219,17 @@ } | ||
}); | ||
console.log(`\u{1F501} Edited command "${name}".`); | ||
let message = `\u{1F501} Edited command "${name}".`; | ||
if (logger) { | ||
logger.info(message); | ||
} else { | ||
console.log(message); | ||
} | ||
} | ||
} else { | ||
if (localCommand.deleted) { | ||
console.log(`\u23E9 Skipping registering command "${name}" as it's set to delete.`); | ||
let message2 = `\u23E9 Skipping registering command "${name}" as it's set to delete.`; | ||
if (logger) { | ||
logger.info(message2); | ||
} else { | ||
console.log(message2); | ||
} | ||
continue; | ||
@@ -230,3 +246,8 @@ } | ||
}); | ||
console.log(`\u{1F44D} Registered command "${name}."`); | ||
let message = `\u2705 Registered command "${name}".`; | ||
if (logger) { | ||
logger.info(message); | ||
} else { | ||
console.log(message); | ||
} | ||
} | ||
@@ -244,6 +265,9 @@ } | ||
validationsPath, | ||
testServer | ||
testServer, | ||
logger | ||
}) { | ||
if (!client) | ||
throw new Error('Property "client" is required when instantiating CommandHandler.'); | ||
throw new Error( | ||
'Property "client" is required when instantiating CommandHandler.' | ||
); | ||
this._client = client; | ||
@@ -256,2 +280,3 @@ this._commandsPath = commandsPath; | ||
this._validationFuncs = []; | ||
this._logger = logger; | ||
if (this._validationsPath && !commandsPath) { | ||
@@ -282,3 +307,4 @@ throw new Error( | ||
commands: this._commands, | ||
testServer: this._testServer | ||
testServer: this._testServer, | ||
logger: this._logger | ||
}); | ||
@@ -310,3 +336,5 @@ } | ||
if (typeof validationFunc !== "function") { | ||
throw new Error(`Validation file ${validationFilePath} must export a function by default.`); | ||
throw new Error( | ||
`Validation file ${validationFilePath} must export a function by default.` | ||
); | ||
} | ||
@@ -320,3 +348,5 @@ this._validationFuncs.push(validationFunc); | ||
return; | ||
const command = this._commands.find((cmd) => cmd.name === interaction.commandName); | ||
const command = this._commands.find( | ||
(cmd) => cmd.name === interaction.commandName | ||
); | ||
if (command) { | ||
@@ -326,3 +356,8 @@ if (this._validationFuncs.length) { | ||
for (const validationFunc of this._validationFuncs) { | ||
const cantRunCommand = yield validationFunc(interaction, command, this, this._client); | ||
const cantRunCommand = yield validationFunc( | ||
interaction, | ||
command, | ||
this, | ||
this._client | ||
); | ||
if (cantRunCommand) { | ||
@@ -329,0 +364,0 @@ canRun = false; |
import { Client, APIApplicationCommand } from 'discord.js'; | ||
import { Logger } from 'winston'; | ||
@@ -14,2 +15,3 @@ class CommandHandler { | ||
testServer?: string; | ||
logger?: Logger; | ||
} | ||
@@ -16,0 +18,0 @@ |
{ | ||
"name": "djs-commander", | ||
"version": "0.0.45", | ||
"description": "A command and event handler that works seemlessly with Discord.js", | ||
"version": "0.0.46", | ||
"description": "A command and event handler that works seamlessly with Discord.js", | ||
"types": "./index.d.ts", | ||
@@ -32,4 +32,5 @@ "exports": { | ||
"tsup": "^6.6.0", | ||
"typescript": "^4.9.5" | ||
"typescript": "^4.9.5", | ||
"winston": "^3.8.2" | ||
} | ||
} |
@@ -33,2 +33,3 @@ # DJS-Commander: A Library for Discord.js Projects | ||
const { CommandHandler } = require('djs-commander'); | ||
const winston = require('winston'); | ||
const path = require('path'); | ||
@@ -40,2 +41,9 @@ | ||
const logger = winston.createLogger({ | ||
// Optional highly customizable winston logger | ||
level: 'info', | ||
format: winston.format.json(), | ||
transports: [new winston.transports.Console()], | ||
}); | ||
new CommandHandler({ | ||
@@ -47,2 +55,3 @@ client, // Discord.js client object | ||
testServer: 'TEST_SERVER_ID', // To register guild-based commands (if not provided commands will be registered globally) | ||
logger: logger, // Changes the console output to match the specified logger configuration (if not provided logging will go through console.log) | ||
}); | ||
@@ -59,3 +68,3 @@ | ||
``` | ||
```shell | ||
commands/ | ||
@@ -96,3 +105,3 @@ ├── command1.js | ||
``` | ||
```shell | ||
events/ | ||
@@ -130,3 +139,3 @@ ├── ready/ | ||
``` | ||
```shell | ||
validations/ | ||
@@ -133,0 +142,0 @@ └── dev-only.js |
Sorry, the diff of this file is not supported yet
41422
868
159
4