Add zip timezones

This commit is contained in:
Dragon Fire
2021-04-24 14:30:56 -04:00
parent 65beca4226
commit 33e9249144
2 changed files with 12 additions and 5 deletions
+2 -1
View File
@@ -88,7 +88,8 @@
"valid-url": "^1.0.9",
"wavefile": "^11.0.0",
"winston": "^3.3.3",
"ytdl-core": "^4.5.0"
"ytdl-core": "^4.5.0",
"zip-to-timezone": "^1.1.5"
},
"optionalDependencies": {
"bufferutil": "^4.0.3",
+6
View File
@@ -1,5 +1,6 @@
const { ArgumentType } = require('discord.js-commando');
const cityTimezones = require('city-timezones');
const { ZipToTz } = require('zip-to-timezone');
const moment = require('moment-timezone');
module.exports = class TimezoneType extends ArgumentType {
@@ -11,10 +12,15 @@ module.exports = class TimezoneType extends ArgumentType {
value = value.replaceAll(' ', '_').toLowerCase();
const directZone = moment.tz.zone(value);
if (directZone) return true;
try {
const zipZone = new ZipToTz().full(value);
return zipZone;
} catch {
const cityZone = cityTimezones.lookupViaCity(value);
if (cityZone.length) return true;
const provZone = cityTimezones.findFromCityStateProvince(value);
if (provZone.length) return true;
}
return false;
}