Imangazaliev / syntax-highligter-bot

A Telegram bot for generating screenshots with highlighted code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syntax Highlighter Bot

A Telegram bot for generating screenshots with highlighted code.

How it works

There are two services - bot.py and screenshot-service.js.

  • bot.py - bot written in AIOgram
  • screenshot-service.js - a service for generating screenshots
  1. Bot requests the screenshot service to generate an image with code.
  2. Screenshot service in turn does:
    1. Highlights a code via highlight.js
    2. Load generated HTML and takes a screenshot via Puppeteer (headless Chrome driver)
    3. Saves generated screenshot to a directory and returns it's path.
  3. Bot sends generated image to a user.

Quick start

  1. Install dependencies:
# Python dependencies
$ poetry install
# JavaScript dependencies
$ npm i
  1. Copy .env.example to .env:
$ cp .env.example .env
  1. Specify a bot token in .env.
  2. Execute services:
# execute bot
$ poetry run bot.py
# execute bot (in another terminal)
$ node screenshot-service.js

If you are running a bot locally don't forget to start Telegram Bot API.

Development

For local development use Telegram Bot API.

Roadmap

  • Rate limiting
  • Use queue to limit the number of pages generated in parallel
  • Containerize

About

A Telegram bot for generating screenshots with highlighted code


Languages

Language:Python 44.8%Language:JavaScript 43.9%Language:CSS 5.2%Language:HTML 5.1%Language:Shell 1.0%