Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. exports.run = (client, message, args) => {
  2.     //thanks to opal for quite a bit of this code
  3.     var initialvalue = args[0];
  4.     var unit = args[1];
  5.     var tounit = args[2];
  6.     var convert = {
  7.         "second": 1,
  8.         "minute": 60,
  9.         "hour": 3600,
  10.         "day": 86400,
  11.         "week": 604800,
  12.         "month": 2628000,
  13.         "year": 31540000,
  14.        
  15.         "seconds": 1,
  16.         "minutes": 60,
  17.         "hours": 3600,
  18.         "days": 86400,
  19.         "weeks": 604800,
  20.         "months": 2628000,
  21.         "years": 31540000,
  22.        
  23.         "s": 1,
  24.         "m": 60,
  25.         "h": 3600,
  26.         "d": 86400,
  27.         "w": 604800,
  28.         "mo": 2628000,
  29.         "y": 31540000
  30.     };
  31.     if (!args[0]) return message.reply("Please provide an initial unit for me to convert into seconds.");
  32.     var preset = 0;
  33.     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;
  34.     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];
  35.     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);
  36.     if (args[0].endsWith("mo")) unit = "month"
  37.     if (args[0].endsWith("mo")) initialvalue =  initialvalue.substring(0, initialvalue.length - 2);
  38.    
  39.     if (preset !== 1 && !args[1]) return message.reply("Please tell me what unit of time you just gave me.");
  40.    
  41.     if (!convert[unit]) return message.reply("The unit you provided is invalid!");
  42.     if (preset == 1 && !args[2]) tounit = args[1];
  43.     if (!tounit) tounit = "second";
  44.     if (!convert[tounit]) return message.reply("The unit you provided to convert to is invalid!")
  45.    
  46.     var toseconds = initialvalue * convert[unit];
  47.     var finalconversion = toseconds / convert[tounit];
  48.    
  49.     var plural = 0;
  50.     var displaytounit = tounit
  51.     if (finalconversion > 1) plural = 1
  52.     if (tounit == "second" && plural == 1) displaytounit = "seconds"
  53.     if (tounit == "minute" && plural == 1) displaytounit = "minutes"
  54.     if (tounit == "hour" && plural == 1) displaytounit = "hours"
  55.     if (tounit == "day" && plural == 1) displaytounit = "days"
  56.     if (tounit == "week" && plural == 1) displaytounit = "weeks"
  57.     if (tounit == "month" && plural == 1) displaytounit = "months"
  58.     if (tounit == "year" && plural == 1) displaytounit = "years"
  59.    
  60.     if (tounit == "s" && plural == 1) displaytounit = "seconds"
  61.     if (tounit == "m" && plural == 1) displaytounit = "minutes"
  62.     if (tounit == "h" && plural == 1) displaytounit = "hours"
  63.     if (tounit == "d" && plural == 1) displaytounit = "days"
  64.     if (tounit == "w" && plural == 1) displaytounit = "weeks"
  65.     if (tounit == "mo" && plural == 1) displaytounit = "months"
  66.     if (tounit == "y" && plural == 1) displaytounit = "years"
  67.    
  68.     if (tounit == "second" && plural == 0) displaytounit = "second"
  69.     if (tounit == "minute" && plural == 0) displaytounit = "minute"
  70.     if (tounit == "hour" && plural == 0) displaytounit = "hour"
  71.     if (tounit == "day" && plural == 0) displaytounit = "day"
  72.     if (tounit == "week" && plural == 0) displaytounit = "week"
  73.     if (tounit == "month" && plural == 0) displaytounit = "month"
  74.     if (tounit == "year" && plural == 0) displaytounit = "year"
  75.    
  76.     if (tounit == "s" && plural == 0) displaytounit = "second"
  77.     if (tounit == "m" && plural == 0) displaytounit = "minute"
  78.     if (tounit == "h" && plural == 0) displaytounit = "hour"
  79.     if (tounit == "d" && plural == 0) displaytounit = "day"
  80.     if (tounit == "w" && plural == 0) displaytounit = "week"
  81.     if (tounit == "mo" && plural == 0) displaytounit = "month"
  82.     if (tounit == "y" && plural == 0) displaytounit = "year"
  83.    
  84.     message.reply(`${Math.floor(finalconversion)} ${displaytounit}.`);
  85. }
  86. exports.help = {
  87.   name: "time",
  88.   category: "User",
  89.   description: "Converts time values to seconds.",
  90.   usage: "time (value) (unit provided)"
  91. };
  92. exports.perms = {
  93.     accesslevel: "0",
  94.     allowedguilds: []
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement