Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Past Time #10

Merged
merged 7 commits into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions commands/events/addEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ const eventObj = {
venue: "",
};

// A function for checking if the date or time has been already passed or not
function checkSchedule(args) {

const decidedDay = args[1];
const decidedTime = args[3];
const curDay = new Date().toLocaleDateString(undefined, {timeZone: "Asia/Kolkata"});
const curTime = new Date().toLocaleTimeString("en-US", {
hour12: false,
hour: "numeric",
minute: "numeric",
timeZone: "Asia/Kolkata",
});

if (Date.parse(decidedDay) < Date.parse(curDay)) {
return false;
}

if (Date.parse(decidedDay) === Date.parse(curDay) && decidedTime < curTime) {
return false;
}

return true;

}

const compute = (args) => {
args = args.filter((elem) => elem !== "");
args = args.map((elem) => elem.toLowerCase());
Expand Down Expand Up @@ -52,8 +77,7 @@ module.exports = {
name: "!addevent",
permission: "*",
description: "Add an event",
usage:
" ```!addevent\n\nFormat:\ndate: DD/MM/YYYY\ntime: HH:MM (24 hr)\ntitle: ...\nvenue: ...```",
usage: " ```!addevent\n\nFormat:\ndate: DD/MM/YYYY\ntime: HH:MM (24 hr)\ntitle: ...\nvenue: ...```",
execute: async (message, args) => {
if (!message.member.hasPermission("ADMINISTRATOR")) {
message.channel.send("You do not have permission to run this command.");
Expand All @@ -67,6 +91,13 @@ module.exports = {
return;
}

if (checkSchedule(args) === false) {
message.channel.send(
"Scheduled Date or Time has already passed, Try creating a valid event"
);
return;
}

let str = "";

await mongo().then(async (mongoose) => {
Expand All @@ -89,4 +120,4 @@ module.exports = {

message.channel.send(str);
},
};
};