Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.run = (client, message, args) => {
- //thanks to opal for quite a bit of this code
- var initialvalue = args[0];
- var unit = args[1];
- var tounit = args[2];
- var convert = {
- "second": 1,
- "minute": 60,
- "hour": 3600,
- "day": 86400,
- "week": 604800,
- "month": 2628000,
- "year": 31540000,
- "seconds": 1,
- "minutes": 60,
- "hours": 3600,
- "days": 86400,
- "weeks": 604800,
- "months": 2628000,
- "years": 31540000,
- "s": 1,
- "m": 60,
- "h": 3600,
- "d": 86400,
- "w": 604800,
- "mo": 2628000,
- "y": 31540000
- };
- if (!args[0]) return message.reply("Please provide an initial unit for me to convert into seconds.");
- var preset = 0;
- if (args[0].endsWith("s") || args[0].endsWith("m") || args[0].endsWith("h") || args[0].endsWith("d") || args[0].endsWith("w") || args[0].endsWith("mo") || args[0].endsWith("y")) preset = 1;
- if (args[0].endsWith("s") || args[0].endsWith("m") || args[0].endsWith("h") || args[0].endsWith("d") || args[0].endsWith("w") || args[0].endsWith("y")) unit = initialvalue[initialvalue.length -1];
- if (args[0].endsWith("s") || args[0].endsWith("m") || args[0].endsWith("h") || args[0].endsWith("d") || args[0].endsWith("w") || args[0].endsWith("y")) initialvalue = initialvalue.substring(0, initialvalue.length - 1);
- if (args[0].endsWith("mo")) unit = "month"
- if (args[0].endsWith("mo")) initialvalue = initialvalue.substring(0, initialvalue.length - 2);
- if (preset !== 1 && !args[1]) return message.reply("Please tell me what unit of time you just gave me.");
- if (!convert[unit]) return message.reply("The unit you provided is invalid!");
- if (preset == 1 && !args[2]) tounit = args[1];
- if (!tounit) tounit = "second";
- if (!convert[tounit]) return message.reply("The unit you provided to convert to is invalid!")
- var toseconds = initialvalue * convert[unit];
- var finalconversion = toseconds / convert[tounit];
- var plural = 0;
- var displaytounit = tounit
- if (finalconversion > 1) plural = 1
- if (tounit == "second" && plural == 1) displaytounit = "seconds"
- if (tounit == "minute" && plural == 1) displaytounit = "minutes"
- if (tounit == "hour" && plural == 1) displaytounit = "hours"
- if (tounit == "day" && plural == 1) displaytounit = "days"
- if (tounit == "week" && plural == 1) displaytounit = "weeks"
- if (tounit == "month" && plural == 1) displaytounit = "months"
- if (tounit == "year" && plural == 1) displaytounit = "years"
- if (tounit == "s" && plural == 1) displaytounit = "seconds"
- if (tounit == "m" && plural == 1) displaytounit = "minutes"
- if (tounit == "h" && plural == 1) displaytounit = "hours"
- if (tounit == "d" && plural == 1) displaytounit = "days"
- if (tounit == "w" && plural == 1) displaytounit = "weeks"
- if (tounit == "mo" && plural == 1) displaytounit = "months"
- if (tounit == "y" && plural == 1) displaytounit = "years"
- if (tounit == "second" && plural == 0) displaytounit = "second"
- if (tounit == "minute" && plural == 0) displaytounit = "minute"
- if (tounit == "hour" && plural == 0) displaytounit = "hour"
- if (tounit == "day" && plural == 0) displaytounit = "day"
- if (tounit == "week" && plural == 0) displaytounit = "week"
- if (tounit == "month" && plural == 0) displaytounit = "month"
- if (tounit == "year" && plural == 0) displaytounit = "year"
- if (tounit == "s" && plural == 0) displaytounit = "second"
- if (tounit == "m" && plural == 0) displaytounit = "minute"
- if (tounit == "h" && plural == 0) displaytounit = "hour"
- if (tounit == "d" && plural == 0) displaytounit = "day"
- if (tounit == "w" && plural == 0) displaytounit = "week"
- if (tounit == "mo" && plural == 0) displaytounit = "month"
- if (tounit == "y" && plural == 0) displaytounit = "year"
- message.reply(`${Math.floor(finalconversion)} ${displaytounit}.`);
- }
- exports.help = {
- name: "time",
- category: "User",
- description: "Converts time values to seconds.",
- usage: "time (value) (unit provided)"
- };
- exports.perms = {
- accesslevel: "0",
- allowedguilds: []
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement