mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 06:42:50 +02:00
Check for invalid timezones in time
This commit is contained in:
+9
-10
@@ -25,20 +25,19 @@ module.exports = class TimeCommand extends Command {
|
|||||||
|
|
||||||
run(msg, { timeZone }) {
|
run(msg, { timeZone }) {
|
||||||
let neopia = false;
|
let neopia = false;
|
||||||
if (timeZone === 'neopia/standard' || timeZone === 'neopia') {
|
if (timeZone === 'neopia') {
|
||||||
timeZone = 'america/vancouver';
|
timeZone = 'america/vancouver';
|
||||||
neopia = true;
|
neopia = true;
|
||||||
}
|
}
|
||||||
try {
|
if (!moment.tz.zone(timeZone)) {
|
||||||
const time = moment().tz(timeZone).format('hh:mm:ss A');
|
|
||||||
const location = neopia ? ['neopia'] : timeZone.split('/');
|
|
||||||
const main = firstUpperCase(location[0], /[_ ]/);
|
|
||||||
const sub = location[1] ? firstUpperCase(location[1], /[_ ]/) : null;
|
|
||||||
const subMain = location[2] ? firstUpperCase(location[2], /[_ ]/) : null;
|
|
||||||
const parens = sub ? ` (${subMain ? `${sub}, ` : ''}${main})` : '';
|
|
||||||
return msg.say(`The current time in ${subMain || sub || main}${parens} is ${time}.`);
|
|
||||||
} catch (err) {
|
|
||||||
return msg.reply('Invalid time zone. Refer to <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>.');
|
return msg.reply('Invalid time zone. Refer to <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>.');
|
||||||
}
|
}
|
||||||
|
const time = moment().tz(timeZone).format('hh:mm:ss A');
|
||||||
|
const location = neopia ? ['neopia'] : timeZone.split('/');
|
||||||
|
const main = firstUpperCase(location[0], /[_ ]/);
|
||||||
|
const sub = location[1] ? firstUpperCase(location[1], /[_ ]/) : null;
|
||||||
|
const subMain = location[2] ? firstUpperCase(location[2], /[_ ]/) : null;
|
||||||
|
const parens = sub ? ` (${subMain ? `${sub}, ` : ''}${main})` : '';
|
||||||
|
return msg.say(`The current time in ${subMain || sub || main}${parens} is ${time}.`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "91.8.4",
|
"version": "91.8.5",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user