JaBa/commands/Economy/birthdate.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-01-04 02:18:28 +05:00
const Command = require("../../base/Command.js");
class Birthdate extends Command {
constructor(client) {
super(client, {
name: "birthdate",
dirname: __dirname,
enabled: true,
guildOnly: false,
aliases: ["bd"],
memberPermissions: [],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
async run(message, args, data) {
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");
const match = date.match(/\d+/g);
if (!match) return message.error("economy/birthdate:INVALID_DATE");
const tday = +match[0],
tmonth = +match[1] - 1;
let tyear = +match[2];
2022-01-07 23:56:34 +05:00
2022-01-04 02:18:28 +05:00
if (tyear < 100) tyear += tyear < 50 ? 2000 : 1900;
2022-01-07 23:56:34 +05:00
2022-01-04 02:18:28 +05:00
const d = new Date(tyear, tmonth, tday);
if (!(tday == d.getDate() && tmonth == d.getMonth() && tyear == d.getFullYear())) return message.error("economy/birthdate:INVALID_DATE");
if (d.getTime() > Date.now()) return message.error("economy/birthdate:DATE_TOO_HIGH");
if (d.getTime() < (Date.now() - 2.523e+12)) return message.error("economy/birthdate:DATE_TOO_LOW");
data.userData.birthdate = d;
data.userData.save();
message.success("economy/birthdate:SUCCESS", {
date: message.printDate(d)
});
}
};
module.exports = Birthdate;