chomens-bot-js/commands/time.js

45 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-08-14 05:51:45 -04:00
/* eslint-disable max-len */
2022-10-14 04:46:41 -04:00
const {MessageEmbed} = require('discord.js');
2022-08-14 05:51:45 -04:00
const moment = require('moment-timezone');
module.exports = {
name: 'time',
alias: [],
description: 'Shows the time',
usage: '<timezone>',
trusted: 0,
2022-11-16 06:41:30 -05:00
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
2022-08-14 05:51:45 -04:00
const timezone = args.join(' ');
2022-11-23 08:04:22 -05:00
const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A');
2022-11-07 08:08:29 -05:00
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'}];
2022-11-07 07:26:38 -05:00
if (timezone.toLowerCase() === 'asia/bangkok' || timezone.toLowerCase() === 'utc') {
2022-11-16 06:41:30 -05:00
bot.tellraw(selector, component);
2022-08-14 05:51:45 -04:00
return;
2022-11-07 07:26:38 -05:00
} else if (momented === moment().format('dddd, MMMM Do, YYYY, hh:mm:ss A')) {
2022-10-14 04:46:41 -04:00
throw new SyntaxError('Invalid timezone');
} else {
2022-11-16 06:41:30 -05:00
bot.tellraw(selector, component);
2022-10-14 04:46:41 -04:00
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) {
const timezone = args.join(' ');
2022-11-23 08:04:22 -05:00
const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A');
2022-10-14 04:46:41 -04:00
const description = `The current date and time for the timezone ${timezone} is: ${momented}`;
2022-11-07 07:26:38 -05:00
if (timezone.toLowerCase() === 'asia/bangkok' || timezone.toLowerCase() === 'utc') {
2022-10-14 04:46:41 -04:00
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Time')
.setDescription(description);
channeldc.send({embeds: [Embed]});
2022-08-14 05:51:45 -04:00
return;
2022-11-07 07:26:38 -05:00
} else if (momented === moment().format('dddd, MMMM Do, YYYY, hh:mm:ss A')) {
2022-08-14 05:51:45 -04:00
throw new SyntaxError('Invalid timezone');
} else {
2022-10-14 04:46:41 -04:00
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Time')
.setDescription(description);
channeldc.send({embeds: [Embed]});
2022-08-14 05:51:45 -04:00
}
},
};