JaBa/commands/Economy/birthdate.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js");
class Birthdate extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "birthdate",
dirname: __dirname,
enabled: true,
guildOnly: false,
aliases: ["bd"],
2021-12-10 21:39:54 +05:00
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
const date = args[0];
if (!date) return message.error("economy/birthdate:MISSING_DATE");
const tArgs = date.split("/");
const [day, month, year] = tArgs;
if (!day || !month || !year) return message.error("economy/birthdate:INVALID_DATE");
// Gets the string of the date
const match = date.match(/\d+/g);
2021-12-30 20:03:36 +05:00
if (!match) return message.error("economy/birthdate:INVALID_DATE");
2021-12-10 21:39:54 +05:00
2021-12-26 19:29:37 +05:00
const tday = +match[0],
tmonth = +match[1] - 1;
2021-12-10 21:39:54 +05:00
let tyear = +match[2];
if (tyear < 100) tyear += tyear < 50 ? 2000 : 1900;
const d = new Date(tyear, tmonth, tday);
2021-12-30 20:03:36 +05:00
if (!(tday == d.getDate() && tmonth == d.getMonth() && tyear == d.getFullYear())) return message.error("economy/birthdate:INVALID_DATE");
2021-12-10 21:39:54 +05:00
if (d.getTime() > Date.now()) return message.error("economy/birthdate:DATE_TOO_HIGH");
2021-12-26 19:29:37 +05:00
if (d.getTime() < (Date.now() - 2.523e+12)) return message.error("economy/birthdate:DATE_TOO_LOW");
2021-12-10 21:39:54 +05:00
data.userData.birthdate = d;
data.userData.save();
2021-12-26 19:29:37 +05:00
message.success("economy/birthdate:SUCCESS", {
date: message.printDate(d)
});
2021-12-10 21:39:54 +05:00
}
};
module.exports = Birthdate;