Make shutdown command aware of timers

This commit is contained in:
Dragon Fire
2020-10-05 18:20:23 -04:00
parent 1fbce27727
commit 55e8030d5a
3 changed files with 27 additions and 11 deletions
+9 -3
View File
@@ -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}**.`);
}
};
+17 -7
View File
@@ -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.');
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "119.29.1",
"version": "119.29.2",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {