diff --git a/commands/other/timer.js b/commands/other/timer.js index 04bde3a9..cc5298a0 100644 --- a/commands/other/timer.js +++ b/commands/other/timer.js @@ -18,12 +18,18 @@ module.exports = class TimerCommand extends Command { } ] }); + + this.timers = new Map(); } async run(msg, { time }) { + if (this.timers.has(msg.channel.id)) return msg.reply('Only one timer can be set per channel.'); const display = time > 59 ? `${time / 60} minutes` : `${time} seconds`; - await msg.say(`🕰️ Set a timer for **${display}**.`); - await delay(time * 1000); - return msg.say(`🕰️ Your **${display}** timer is finished ${msg.author}!`); + const timeout = setTimeout(async () => { + await msg.say(`🕰️ Your **${display}** timer is finished ${msg.author}!`); + this.timers.delete(msg.channel.id); + }, time * 1000); + this.timers.set(msg.channel.id, timeout); + return msg.say(`🕰️ Set a timer for **${display}**.`); } }; diff --git a/commands/util/shutdown.js b/commands/util/shutdown.js index 3735bd51..976d5661 100644 --- a/commands/util/shutdown.js +++ b/commands/util/shutdown.js @@ -25,13 +25,23 @@ module.exports = class ShutdownCommand extends Command { } async run(msg, { code }) { - if (this.client.games.size > 0) { - await msg.reply(`There are currently **${this.client.games.size}** games going on. Are you sure?`); - const verification = await verify(msg.channel, msg.author); - if (!verification) return msg.say('Aborted restart.'); - } - if (this.client.phone.size > 0) { - await msg.reply(`There are currently **${this.client.phone.size}** phone calls going on. Are you sure?`); + const games = this.client.games.size; + const calls = this.client.phone.size; + const timers = this.client.registry.commands.get('timer').timers.size; + if (games > 0 || calls > 0 || timers > 0) { + let currentString = ''; + if (games > 0) { + currentString += `${games} games`; + if ((calls > 0 && timers < 1) || (calls < 1 && timers > 0)) currentString += ' and '; + else if (calls > 0 && timers > 0) currentString += ', '; + } + if (calls > 0) { + currentString += `${calls} phone calls`; + if (games < 1 && timers > 0) currentString += ' and '; + if (timers > 0) currentString += ', and'; + } + if (timers > 0) currentString += `${timers} timers`; + await msg.reply(`There are currently ${currentString}. Are you sure?`); const verification = await verify(msg.channel, msg.author); if (!verification) return msg.say('Aborted restart.'); } diff --git a/package.json b/package.json index 74f9b639..5b4ed83c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.29.1", + "version": "119.29.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {