From 4236ec3f3469d384411578e13fc3a6faba691ff2 Mon Sep 17 00:00:00 2001 From: Saalim Aqueel Date: Sun, 15 Oct 2023 05:06:32 +0530 Subject: [PATCH] Implemented reSubmit --- eligible_participants.pdf | Bin 1535 -> 1372 bytes eligible_participants_2023-10-14.xlsx | Bin 0 -> 16291 bytes src/index.js | 146 +++++++++++++++++++++----- 3 files changed, 117 insertions(+), 29 deletions(-) create mode 100644 eligible_participants_2023-10-14.xlsx diff --git a/eligible_participants.pdf b/eligible_participants.pdf index 00d1113daa04ac19db437238fa32c534d88ae10b..6b874c89782e3b51b71ef65aa4d7ced633ed3116 100644 GIT binary patch delta 537 zcmey*eTQqpV`d{`lZnri>W>EQ_Hr>4c>7uOGqdz_Tj_{A#f(JtJAOJPP8L_*bot}+*?ITu+mGXoyfo{*tJa9P zOi7)h^}AsE^iHOfQ)WJAbMhaUxa+QX`dMcW?}DwN4iV{J?~5E*&ZaZ};ro_*`I;4C zYgAVVvpC!cODeXwzrKT4Gm9;4|33pg>E*{)$o+WqnpN7=Dqiur$GeBwkN!XT#kfOq zwJ29=UP^IEQEFl?h?Sp|#bs!qU@&d#Kyn|IYgptaim=st(Gx&LD|iv&5jc6q!LU_JTuZP15* zyvKJ6cJ6Sw<0{}j?R$F8+d0OcPd*DOj5Ta~6ZB4g*?ZynNAspFR}i1Lq(DD%a+X`9 z+%o?8I|{T<7yc^BmHU2Cx$tz%l4;p*VpmRw&lvs`YY>G zf7;Z>EW2(0(nIs2)yBUe3F@rxRzB1WT08sY_MH}!Jg=@>w90p4FmLv;S@Oq^Z0^hG zXBE$qHLA#tTvYp_eXdWB=4P+@d$;nZL~^AR-`ShN**{OuE$n=hUi<#N zZlABa6~%qqu6%BHz*X6f&m~#^-gkWVy&(HedB$h=C)WZ!?`b{?y5i=bMWDv9N?v*Ri*Nh~U^a}0L2mzRR910 diff --git a/eligible_participants_2023-10-14.xlsx b/eligible_participants_2023-10-14.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..e52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&X)ELX? { ); } } + //------------------------------------ RESUBMIT_TASK_FOR_TODAY [EDIT] ---------------------------// + if (message.content.startsWith("!resubmit")) { + const resubmissionLink = message.content.slice("!resubmit".length).trim(); + + // Check if the resubmission link is in the correct format + if (!isValidLink(resubmissionLink)) { + message.reply( + "Invalid resubmission link format. Please check and try again." + ); + return; + } + + const userId = message.author.id; + const today = new Date(); + + // Retrieve the user's previous entry for the current day (if it exists) + const previousEntry = await User.findOne({ userId, entryDate: today }); + + if (previousEntry) { + // Update the previous entry with the new submission link + previousEntry.submissionFormat = getSubmissionFormat(resubmissionLink); + + // Update any other fields as needed + + // Save the updated entry + previousEntry.save(); + + // Inform the user that their resubmission has been recorded + message.reply("Your resubmission has been recorded!"); + } else { + // If no previous entry is found, create a new entry for the user for the current day + const user = await client.users.fetch(userId); + const username = user.username; + const entryDate = today; + const submissionFormat = getSubmissionFormat(resubmissionLink); + const streak = 1; + const eligibility = true; + + const newUser = new User({ + userId, + username, + entryDate, + submissionFormat, + streak, + eligibility, + lastSubmissionDate: entryDate, + }); + + // Save the new entry + newUser.save(); + + // Inform the user that their resubmission has been recorded + message.reply("Your resubmission has been recorded!"); + } + } + //---------------------------------- EXPORT_CHALLENGE_RECORD_SHEET ------------------------// - // if (message.content === "!export") { - // const eligibleParticipants = await User.find({ eligibility: true }); - - // // Define the data with proper column headers - // const data = eligibleParticipants.map((participant) => ({ - // "User ID": participant.userId, - // Username: participant.username, - // "Submission Format": participant.submissionFormat, - // Streak: participant.streak, - // })); - - // // Create an Excel sheet - // const ws = XLSX.utils.json_to_sheet(data); - - // // Create a workbook and add the worksheet - // const wb = XLSX.utils.book_new(); - // XLSX.utils.book_append_sheet(wb, ws, "Eligible Participants"); - - // // Write the workbook to a file - // XLSX.writeFile(wb, "eligible_participants.xlsx"); - - // // Send the Excel file to the user - // message.author.send({ - // files: ["eligible_participants.xlsx"], - // }); - // } + if (message.content === "!export") { const allParticipants = await User.find(); @@ -239,6 +271,62 @@ db.once("open", () => { }); } } + //---------------------------------- EXPORT_ELIGIBLE_XLSX -------------------------------// + if (message.content === "!export-eligible-xlsx") { + const eligibleParticipants = await User.find({ eligibility: true }); + + // Define the data with proper column headers + const data = eligibleParticipants.map((participant) => ({ + "User ID": participant.userId, + Username: participant.username, + "Submission Format": participant.submissionFormat, + Streak: participant.streak, + })); + + // Create an Excel sheet + const ws = XLSX.utils.json_to_sheet(data); + + // Create a workbook and add the worksheet + const wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, "Eligible Participants"); + + // Write the workbook to a file + XLSX.writeFile(wb, "eligible_participants.xlsx"); + + // Send the Excel file to the user + message.author.send({ + files: ["eligible_participants.xlsx"], + }); + } + //-------------------------------------- EXPORT_ELIGIBLE_PDF -----------------------------// + + if (message.content === "!export-eligible") { + const eligibleParticipants = await User.find({ eligibility: true }); + + // Create a PDF document + const doc = new PDFDocument(); + const stream = fs.createWriteStream("eligible_participants.pdf"); + + doc.pipe(stream); + + doc.fontSize(16).text("Eligible Participants", { align: "center" }); + doc.moveDown(); + + eligibleParticipants.forEach((participant) => { + doc.text(`User ID: ${participant.userId}`); + doc.text(`Username: ${participant.username}`); + doc.text(`Streak: ${participant.streak}`); + doc.moveDown(); + }); + + doc.end(); + + // Send the PDF file to the user + message.author.send({ + files: ["eligible_participants.pdf"], + }); + } + //---------------------------------------- CHECK_STREAK ---------------------------------// if (message.content === "!streak") { const userId = message.author.id; @@ -280,10 +368,10 @@ function isValidLink(link) { } // Implement logic to detect the submission format (Twitter, LinkedIn, etc.) function getSubmissionFormat(link) { - if (link.startsWith("https://twitter.com/")) { - return "Twitter"; - } else if (link.startsWith("https://www.linkedin.com/")) { + if (link.includes("linkedin.com/")) { return "LinkedIn"; + } else if (link.includes("twitter.com/")) { + return "Twitter"; } else { return "Unknown"; // Default to unknown format }