Skip to content

Telegram bot that helps you stay on track. Sending notifications about new daily Leetcode tasks right to your personal messages in a convenient time

License

Notifications You must be signed in to change notification settings

dartkron/leetcodeBot

Repository files navigation

Maintainability Test Coverage

Telegram bot for Leetcode daily tasks

BOT URL: https://t.me/MyLeetCodeDailybot

I've found it useful for me to see actual daily task in Telegram. Also want to have notificator about daily task =)

Currently status:

Bot running in Yandex.Cloud Functions (serverless)

Since there is generous free tier and it's stable enough.

Can use YDB for caching.

Expect following tables structure:

CREATE TABLE `dailyQuestion`
(
    `id` Uint64,
    `content` String,
    `difficulty` Uint8,
    `hints` String,
    `questionId` Uint64,
    `title` String,
    `titleSlug` String,
    PRIMARY KEY (`id`)
);

CREATE TABLE `users`
(
    `id` Uint64,
    `chat_id` Uint64,
    `firstName` String,
    `lastName` String,
    `sendingHour` Uint8,
    `subscribed` Bool,
    `username` String,
    PRIMARY KEY (`id`)
);

Awaits YDB_DATABASE and YDB_ENDPOINT environment variables. If database connection will fail or variables will not set, bot will connect LeetCode API for question data.

Features

  1. Can reply with today task.
  2. Can send task hints if they are set.
  3. Can send task difficulty.
  4. Subscribe/Unsubscribe user buttons/commands.
  5. Once per hour reminder serverless function send new task to all users who subscribed for this hour. Reminder require SENDING_TOKEN environment variable with Telegram API token. And it's all on the current stage.

Plan to add:

  1. Possibly get authorization token from subscriber, to show progress, may be show suggestions =).

Using Leetcode graphQl API

Most likely it's a proof of concept. Only recieving of tasks if coded for now. Example:

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/dartkron/leetcodeBot/v3/pkg/leetcodeclient"
)

func main() {
	leetcodeClient := leetcodeclient.NewLeetCodeGraphQlClient()
	loc, _ := time.LoadLocation("UTC")
	now := time.Date(2021, time.September, 26, 0, 0, 0, 0, loc)
	ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second*time.Duration(5))
	defer cancelFunc()
	task, err := leetcodeClient.GetDailyTask(ctx, now)
	if err != nil {
		fmt.Println("Got error from LeetcodeClient", err)
	}
	fmt.Println(task)
}

Continuous delivery

Here you can see very basic example of continuous delivery to two Yandex.Cloud functions. See .github/workflows/deploy.yml for details.

Python version

Version 1.0 was made with Python, you can find it in versions history.

About

Telegram bot that helps you stay on track. Sending notifications about new daily Leetcode tasks right to your personal messages in a convenient time

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published