Compare commits

..

3 commits

Author SHA1 Message Date
cfad048b8e Log command args and allow users to opt out 2023-04-04 00:34:24 +02:00
fa3671efdf Update description 2023-04-04 00:30:30 +02:00
ffc51c5503 Load commands async 2023-04-04 00:26:52 +02:00
4 changed files with 37 additions and 9 deletions

View file

@ -4,7 +4,7 @@ import db from '../../models/index.js';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('optout') .setName('optout')
.setDescription('Opt out of the non commands features.'), .setDescription('Opt out of the non commands features and arguments logging (for debugging purposes)'),
category: 'utility', category: 'utility',
async execute(interaction, args, client) { async execute(interaction, args, client) {
const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } }); const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } });

View file

@ -27,7 +27,15 @@ export default {
if (!command) return; if (!command) return;
const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } });
if (isOptOut) {
console.log(`A user launched command \x1b[33m${commandName}\x1b[0m with slash`);
}
else {
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m with slash`); console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m with slash`);
}
// Owner only check // Owner only check
if (command.ownerOnly && interaction.user.id !== ownerId) { if (command.ownerOnly && interaction.user.id !== ownerId) {
@ -74,6 +82,10 @@ export default {
args[arg.name] = payload; args[arg.name] = payload;
}); });
if (!isOptOut) {
console.log(`\x1b[33m${commandName}\x1b[0m with args ${JSON.stringify(args)}`);
}
await command.execute(interaction, args, client); await command.execute(interaction, args, client);
} }
catch (error) { catch (error) {

View file

@ -290,7 +290,14 @@ export default {
const userTag = message.author.tag; const userTag = message.author.tag;
const userID = message.author.id; const userID = message.author.id;
const isOptOut = await db.optout.findOne({ where: { userID: message.author.id } });
if (isOptOut) {
console.log(`A user launched command \x1b[33m${commandName}\x1b[0m with prefix`);
}
else {
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m with prefix`); console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m with prefix`);
}
// Owner only check // Owner only check
if (command.ownerOnly && message.author.id !== ownerId) { if (command.ownerOnly && message.author.id !== ownerId) {
@ -394,6 +401,11 @@ export default {
args[payloadName] = payload; args[payloadName] = payload;
} }
if (!isOptOut) {
console.log(`\x1b[33m${commandName}\x1b[0m with args ${JSON.stringify(args)}`);
}
await command.execute(message, args, client); await command.execute(message, args, client);
} }
catch (error) { catch (error) {

View file

@ -18,15 +18,19 @@ const client = new Client({
// Load commands // Load commands
client.commands = new Collection(); client.commands = new Collection();
const categoryPath = fs.readdirSync(`${__dirname}/commands`); fs.readdir(`${__dirname}/commands`, (err, categoryPath) => {
categoryPath.forEach(category => { if (err) {
return console.error(err);
}
categoryPath.forEach(category => {
loadCommandFromDir(category); loadCommandFromDir(category);
});
}); });
// Load events // Load events
await loadEventFromDir('client', client); loadEventFromDir('client', client);
if (NODE_ENV !== 'development') { if (NODE_ENV !== 'development') {
await loadEventFromDir('process', process); loadEventFromDir('process', process);
} }
client.login(token); client.login(token);