This discord bot is generating a leet code question every Sunday at 02:00AM.
- Get problem set for getting total question count
- Generate randomNumber between 0 to total question number - 1
- Get question with skipping to randomNumber and limit 1.
- Get problem content with GET Content
- Get title information with GET Title
- Get hints with GET hints
(You can reach all these methods in section "Methods")
In step 3, we need to confirm that the question must be under 2000 characters and problem difficulty should be medium. If the generated question difficulty is hard or easy and character length is over than 2000 then regenarate the question.
- Check if question length grater than 2000 -> regenerate
- Check if problem difficulty is hard or easy -> regenerate
You have to create your own .env
DISCORD_TOKEN='DISCORD_TOKEN'
CLIENT_ID="CLIENT_ID"
GUILD_ID="GUILD_ID"
CHANNEL_ID="CHANNEL_ID"
- Getting Content
- GET Content
curl -X POST https://leetcode.com/graphql \
-H "Content-Type: application/json" \
-d '{
"operationName":"questionContent",
"query": "query questionContent($titleSlug: String!) { question(titleSlug: $titleSlug) { content mysqlSchemas dataSchemas } }",
"variables": {
"titleSlug": "container-with-most-water"
}
}'
- Getting Hint
- GET hints
curl -X POST https://leetcode.com/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "query questionHints($titleSlug: String!) { question(titleSlug: $titleSlug) { hints } }",
"variables": {
"titleSlug": "merge-intervals"
}
}'
- Getting Title
- GET Title
curl -X POST https://leetcode.com/graphql \
-H "Content-Type: application/json" \
-d '{
"operationName":"questionTitle",
"query": "query questionTitle($titleSlug: String!) { question(titleSlug: $titleSlug) { questionId questionFrontendId title titleSlug isPaidOnly difficulty likes dislikes categoryTitle } }",
"variables": {
"titleSlug": "merge-intervals"
}
}'
- Getting Problem set
- GET problem set
curl -X POST https://leetcode.com/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) {problemsetQuestionList: questionList( categorySlug: $categorySlug limit: $limit skip: $skip filters: $filters) { total: totalNum questions: data { acRate difficulty freqBar frontendQuestionId: questionFrontendId isFavor paidOnly: isPaidOnly status title titleSlug topicTags {name id slug } hasSolution hasVideoSolution}}}",
"variables": {
"categorySlug": "",
"skip": 10,
"limit": 1,
"filters": {}
},
"operationName": "problemsetQuestionList"
}'
- Store asked question for disabling reasking.
- Translate question with AI model different languages.