diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2098a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..30e7ee1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/pred/go", + "program": "/home/pred/go/main.cpp", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bb879da --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/events/ready.js b/events/ready.js index 6746ed7..721ca27 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,5 +1,7 @@ import { EmbedBuilder, bold } from "discord.js"; import cron from 'node-cron' +import axios from "axios"; + export default async (client, lc = client.lc) => { console.log(`Logged in as ${client.user.tag}!`); @@ -29,4 +31,92 @@ export default async (client, lc = client.lc) => { scheduled: true, timezone: "Asia/Kolkata" }) -} \ No newline at end of file + + // New function to fetch upcoming contests + async function getUpcomingContests() { + try { + const response = await axios.post('https://leetcode.com/graphql', { + query: `{ + topTwoContests { + title + startTime + duration + } + }` + }, { + headers: { + 'Content-Type': 'application/json', + } + }); + + + return response.data.data.topTwoContests.map(contest => ({ + ...contest, + start_time: new Date(contest.startTime * 1000), + href: `https://leetcode.com/contest/${contest.title.toLowerCase().replace(/\s+/g, '-')}` + })); + } catch (error) { + console.error('Failed to fetch upcoming contests:', error); + return []; + } + } + + + // Function to schedule reminders for contests + async function scheduleContestReminders() { + const contests = await getUpcomingContests(); + // console.log("Working" , contests); + contests.forEach(contest => { + const reminderTime = new Date(contest.start_time.getTime() - 60 * 60 * 1000); // 1 hour before + const now = new Date(); + + + if (reminderTime > now) { + const delay = reminderTime.getTime() - now.getTime(); + console.log("Original Delay =>" , delay); + setTimeout(() => sendContestReminder(contest), delay); + console.log(`Scheduled reminder for ${contest.title} at ${reminderTime}`); + } + }); + } + + + // Function to send contest reminder + async function sendContestReminder(contest) { + + + const embed = new EmbedBuilder() + .setTitle(contest.title) + .setURL(contest.href) + .setColor(0xfea116) + .addFields( + { name: 'Start Time', value: contest.start_time.toUTCString(), inline: true }, + { name: 'Duration', value: `${contest.duration / 60} minutes`, inline: true }, + { name: 'Link', value: `[Join Contest](${contest.href})` } + ) + .setFooter({ text: 'Contest starts in 1 hour!' }); + + + for (const guild of client.guilds.cache.values()) { + for (const channel of guild.channels.cache.values()) { + // Type 0 => Text Channel + if (channel.type === 0) { + await channel.send({ + content: bold(`@everyone, Upcoming LeetCode Contest Reminder!`), + embeds: [embed] + }); + break; + } + } + } + + } + + + + // Refresh contest schedule every Friday + cron.schedule('0 0 * * 5', scheduleContestReminders, { + scheduled: true, + timezone: "UTC" + }); +}