diff --git a/Xiao.js b/Xiao.js index 3a9847e6..578dd122 100644 --- a/Xiao.js +++ b/Xiao.js @@ -188,6 +188,8 @@ client.on('warn', warn => client.logger.warn(warn)); client.on('commandRun', command => { if (command.uses === undefined) return; command.uses++; + if (command.lastRun === undefined) return; + command.lastRun = new Date(); }); client.on('commandError', (command, err) => client.logger.error(`[COMMAND:${command.name}]\n${err.stack}`)); diff --git a/commands/util-public/last-run.js b/commands/util-public/last-run.js new file mode 100644 index 00000000..fe253c1c --- /dev/null +++ b/commands/util-public/last-run.js @@ -0,0 +1,29 @@ +const Command = require('../../structures/Command'); +const moment = require('moment'); + +module.exports = class LastRunCommand extends Command { + constructor(client) { + super(client, { + name: 'last-run', + aliases: ['command-last-run', 'cmd-last-run', 'cmd-run', 'command-run'], + group: 'util-public', + memberName: 'last-run', + description: 'Responds with a command\'s most recent run date.', + guarded: true, + args: [ + { + key: 'command', + prompt: 'Which command would you like to view the last run date of?', + type: 'command' + } + ] + }); + } + + run(msg, { command }) { + if (command.lastRun === undefined) return msg.reply('That command\'s usage stats aren\'t being tracked.'); + if (!command.lastRun) return msg.reply(`The \`${command.name}\` command has not been run since last reboot.`); + const displayTime = moment.utc(command.lastRun).format('MM/DD/YYYY h:mm A'); + return msg.say(`The \`${command.name}\` command was last run on **${displayTime}**.`); + } +}; diff --git a/package.json b/package.json index f53918c3..48f7fe98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "128.4.0", + "version": "128.4.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/Command.js b/structures/Command.js index bfc29c22..514761eb 100644 --- a/structures/Command.js +++ b/structures/Command.js @@ -8,6 +8,7 @@ module.exports = class XiaoCommand extends Command { this.argsSingleQuotes = info.argsSingleQuotes || false; this.throttling = info.unknown ? null : info.throttling || { usages: 1, duration: 2 }; this.uses = 0; + this.lastRun = null; this.credit = info.credit || []; this.credit.push({ name: 'Dragon Fire',