Skip to content

Commit 6c5ee02

Browse files
committed
Add cron job, update /help
1 parent 6c013d6 commit 6c5ee02

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/app.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dotenv/config';
22
import fetch from 'node-fetch';
3+
import { CronJob } from 'cron';
34
import { Client, GatewayIntentBits } from 'discord.js';
45
import { getProgressStats, getProgressList, getRanking, getDefaultLink, generateNewCodeShare } from './utils.js';
56

@@ -160,6 +161,9 @@ client.on('interactionCreate', async interaction => {
160161
const rankingDesc = "Take a look where you stand in comparison to other users using this bot.\n\n" +
161162
"When using this you will be presented with a choice of which difficulty leaderboard to view.";
162163

164+
const codeshareDesc = "Creates a codeshare link for multiple users to join.\n" +
165+
"Codeshare links expire 24 hours after creation, so Leetcode Tracker will also delete the message after 24 hours.";
166+
163167
return interaction.reply({
164168
embeds: [
165169
{
@@ -187,6 +191,10 @@ client.on('interactionCreate', async interaction => {
187191
{
188192
"name": `➡️ __**/ranking**__`,
189193
"value": rankingDesc
194+
},
195+
{
196+
"name": `➡️ __**/codeshare**__`,
197+
"value": codeshareDesc
190198
}
191199
]
192200
}
@@ -200,8 +208,10 @@ client.on('interactionCreate', async interaction => {
200208

201209
const codeShareLink = await generateNewCodeShare();
202210

211+
const expireTime = new Date(Date.now() + 24 * 60 * 60 * 1000);
212+
203213
interaction.editReply({
204-
content: "Here is a new codeshare link",
214+
content: `Here is a new codeshare link. It will expire in 24 hours (${expireTime.toLocaleString()} PST)`,
205215
components: [
206216
{
207217
"type": 1,
@@ -217,6 +227,15 @@ client.on('interactionCreate', async interaction => {
217227
}
218228
],
219229
fetchReply: true
230+
}).then(async msg => {
231+
// Schedule a cron job to delete the reply after 24 hours
232+
const job = new CronJob(expireTime, function() {
233+
msg.delete()
234+
.then(() => console.log(`Codeshare link deleted successfully: ${codeShareLink}`))
235+
.catch(console.error);
236+
});
237+
238+
job.start();
220239
});
221240
}
222241
});

0 commit comments

Comments
 (0)