Skip to content

Commit 2f2ae9e

Browse files
committed
feat: Initial Commit
Adds a very basic express server that will post a message with the leetcode problem of the day to the recurse center zulip instance
1 parent 91c1ddb commit 2f2ae9e

File tree

7 files changed

+873
-0
lines changed

7 files changed

+873
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
zuliprc

bot.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import zulipInit from 'zulip-js';
2+
3+
import { request } from 'graphql-request';
4+
import cron from 'node-cron';
5+
6+
import { dailyCodingQuestions, problemListByCategory, questionOfTheDay } from './queries.js';
7+
8+
const baseUrl = 'https://leetcode.com';
9+
10+
const zulipClient = await zulipInit({ zuliprc: 'zuliprc' });
11+
12+
class LeetCodeBot {
13+
static async run () {
14+
// Schedule the task to run every day at 10:00 AM
15+
cron.schedule('0 10 * * *', async () => {
16+
console.log('Getting leetcode questions for today');
17+
18+
try {
19+
const data = (await request(`${baseUrl}/graphql`, questionOfTheDay)).activeDailyCodingChallengeQuestion;
20+
21+
const message = `${new Date().toLocaleDateString('en-US', { weekday: 'long', day: 'numeric', month: 'short' })}
22+
### [${data.question.title}](${baseUrl}${data.link})
23+
> (${data.question.difficulty}) | ${data.question.topicTags.map((tag) => tag.name).join(', ')}`;
24+
25+
await this.postMessageToZulip(message);
26+
} catch (error) {
27+
console.log('Error fetching the problem of the day:', error);
28+
}
29+
});
30+
}
31+
32+
static async postMessageToZulip (message) {
33+
let params = {
34+
to: 'Daily LeetCode',
35+
type: 'stream',
36+
topic: "Daily Leetcode Problem",
37+
content: message,
38+
};
39+
40+
try {
41+
console.log(await zulipClient.messages.send(params));
42+
} catch (error) {
43+
console.error('Error posting message:', error);
44+
}
45+
}
46+
}
47+
48+
49+
export default LeetCodeBot;

0 commit comments

Comments
 (0)