From 91ce3d41aefa1d5c31c892cb90fd77ef2430b324 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Wed, 15 Mar 2023 15:14:09 +0700 Subject: [PATCH] fix the extremely sus invalid timezone ploblem --- commands/time.js | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/commands/time.js b/commands/time.js index 2edb2a5..b1931f4 100644 --- a/commands/time.js +++ b/commands/time.js @@ -8,34 +8,30 @@ module.exports = { trusted: 0, execute (bot, username, sender, prefix, args, config, hash, ownerhash, selector) { const timezone = args.join(' ') + + if (!moment.tz.names().map((zone) => zone.toLowerCase()).includes(timezone.toLowerCase())) { + throw new SyntaxError('Invalid timezone') + } + const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A') const component = [{ text: 'The current date and time for the timezone ', color: 'white' }, { text: timezone, color: 'aqua' }, { text: ' is: ', color: 'white' }, { text: momented, color: 'green' }] - if (timezone.toLowerCase() === 'asia/bangkok' || timezone.toLowerCase() === 'utc' || timezone.toLowerCase() === 'america/new_york') { - bot.tellraw(selector, component) - } else if (momented === moment().format('dddd, MMMM Do, YYYY, hh:mm:ss A')) { - throw new SyntaxError('Invalid timezone') - } else { - bot.tellraw(selector, component) - } + + bot.tellraw(selector, component) }, discordExecute (bot, username, sender, prefix, args, channeldc, message, config) { const timezone = args.join(' ') + + if (!moment.tz.names().map((zone) => zone.toLowerCase()).includes(timezone.toLowerCase())) { + throw new SyntaxError('Invalid timezone') + } + const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A') const description = `The current date and time for the timezone ${timezone} is: ${momented}` - if (timezone.toLowerCase() === 'asia/bangkok' || timezone.toLowerCase() === 'utc' || timezone.toLowerCase() === 'america/new_york') { - const Embed = new EmbedBuilder() - .setColor(config.discord.embedsColors.normal) - .setTitle('Time') - .setDescription(description) - channeldc.send({ embeds: [Embed] }) - } else if (momented === moment().format('dddd, MMMM Do, YYYY, hh:mm:ss A')) { - throw new SyntaxError('Invalid timezone') - } else { - const Embed = new EmbedBuilder() - .setColor(config.discord.embedsColors.normal) - .setTitle('Time') - .setDescription(description) - channeldc.send({ embeds: [Embed] }) - } + + const Embed = new EmbedBuilder() + .setColor(config.discord.embedsColors.normal) + .setTitle('Time') + .setDescription(description) + channeldc.send({ embeds: [Embed] }) } }