From ca9b54a399c9b159a10c1ee0e7e0236ca84fb9c9 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 11 Jun 2024 14:51:19 -0600 Subject: [PATCH] Guh --- commands.json | 4 ++-- index.js | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/commands.json b/commands.json index 5a7ed6e..276987f 100644 --- a/commands.json +++ b/commands.json @@ -141,13 +141,13 @@ "options": [ { "name": "start_date", - "description": "The start date for the CDR", + "description": "The start date for the CDR (mm/dd/yyyy)", "type": 3, "required": false }, { "name": "end_date", - "description": "The end date for the CDR", + "description": "The end date for the CDR (mm/dd/yyyy)", "type": 3, "required": false } diff --git a/index.js b/index.js index ce4d22c..5d8c8f2 100644 --- a/index.js +++ b/index.js @@ -1303,8 +1303,19 @@ dcClient.on('interactionCreate', async interaction => { break; case "cdr": // Get CDR records for the user // default to beginning of time - let startDate = interaction.options.get("start_date").value || new Date(0); - let endDate = interaction.options.get("end_date").value || new Date(); + let userStartDate = interaction.options.getString("start_date") // regex this to mm/dd/yyyy + let userEndDate = interaction.options.getString("end_date") // regex this to mm/dd/yyyy + // Check against regex + if (!userStartDate.match(/^\d{2}\/\d{2}\/\d{4}$/) || !userEndDate.match(/^\d{2}\/\d{2}\/\d{4}$/)) { + interaction.editReply({ + content: "Invalid date format, please use MM/DD/YYYY", + ephemeral: true + }); + break; + } + + let startDate = new Date(userStartDate) || new Date(0); + let endDate = new Date(userEndDate) || new Date(); await interaction.deferReply({ ephemeral: true });