-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetDaily.js
More file actions
76 lines (64 loc) · 2.22 KB
/
getDaily.js
File metadata and controls
76 lines (64 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//require('dotenv').config();
const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js');
const axios = require('axios');
module.exports = {
data: new SlashCommandBuilder()
.setName('daily')
.setDescription('Show the daily problem')
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
async execute(interaction) {
await postDailyChallenge(interaction);
},
};
async function getDailyLeetCodeChallenge() {
try {
const response = await axios.post('https://leetcode.com/graphql', {
query: `
query questionOfToday {
activeDailyCodingChallengeQuestion {
date
link
question {
title
difficulty
topicTags {
name
}
}
}
}
`
});
return response.data.data.activeDailyCodingChallengeQuestion;
} catch (error) {
console.error('Error fetching LeetCode challenge:', error);
return null;
}
}
async function postDailyChallenge(interaction) {
const challenge = await getDailyLeetCodeChallenge();
if (!challenge) {
await interaction.reply('⚠️ Failed to fetch the daily LeetCode challenge.');
return;
}
const { title, difficulty, topicTags } = challenge.question;
const link = `https://leetcode.com${challenge.link}`;
const color = {
Easy: 0x008000,
Medium: 0xFFD700,
Hard: 0xFF0000
}[difficulty] || '❓';
const tags = topicTags.map(tag => tag.name).join(', ');
const Embed = new EmbedBuilder()
.setColor(color)
.setTitle(`🌟 ${title} 🌟`)
.setDescription(difficulty)
.setFields(
{name: '🔗 URL', value: link},
{name: '🏷️ Topics', value: tags}
)
const channel = interaction.client.channels.cache.get("1352311704050204793");
await channel.send(`<@&1357169483059429447>`);
await channel.send({ embeds: [Embed] });
console.log("Daily Updated.");
}