Skip to content

Telegram bot written in Kotlin to search Minecraft items craft recipes

License

Notifications You must be signed in to change notification settings

grigoryevorg/craftifyer-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Craftifyer Bot

Telegram bot for finding and displaying Minecraft crafting recipes. Automatically extracts recipe information from Minecraft Wiki and sends screenshots of crafting tables to users.

Features

  • Search crafting recipes by item name
  • Support for English and Russian languages
  • Automatic screenshot generation from Minecraft Wiki
  • Caching for improved performance
  • Handles various item name formats

Requirements

  • Java 17+ and Maven 3.6+ (for local build)
  • OR Docker and Docker Compose (recommended)
  • Telegram Bot Token from @BotFather

Installation

Using Docker (Recommended)

Docker setup includes Chrome and all dependencies, ensuring platform-independent deployment.

git clone https://github.com/allenvox/craftifyer-bot.git
cd craftifyer-bot

Create .env file:

cp .env.example .env
# Edit .env and add your TELEGRAM_BOT_TOKEN

Build and run:

docker compose up -d

View logs:

docker compose logs -f

Stop:

docker compose down

Local Installation

git clone https://github.com/allenvox/craftifyer-bot.git
cd craftifyer-bot
mvn clean package

Set environment variable:

export TELEGRAM_BOT_TOKEN="your_bot_token_here"

Run:

java -jar target/craftifyer-bot-1.0-SNAPSHOT.jar

Usage

Commands:

  • /start - Start bot
  • /help - Show help
  • /craft <item name> - Get crafting recipe

Examples:

/craft iron trapdoor
/craft diamond sword
/craft факел

You can also send item name directly without /craft command.

Architecture

src/main/kotlin/com/craftifyer/bot/
├── config/          # Configuration and constants
│   ├── BotConfig.kt
│   └── Messages.kt
├── handlers/        # Command handlers
│   └── CommandHandler.kt
├── services/        # Business logic
│   ├── RecipeService.kt    # Main recipe service
│   ├── WikiScraper.kt      # Web scraping with Selenium
│   └── CacheService.kt      # Screenshot caching
├── utils/           # Utilities
│   ├── LanguageDetector.kt
│   └── ItemNameNormalizer.kt
└── Main.kt          # Entry point

Data Flow

  1. User sends /craft <item> or item name
  2. CommandHandlerRecipeService.getRecipeImageFile()
  3. RecipeService checks CacheService for cached screenshot
  4. If not cached, WikiScraper:
    • Detects language via LanguageDetector
    • Generates name variants via ItemNameNormalizer
    • Loads wiki page with Selenium
    • Finds crafting recipe table
    • Takes screenshot of the table element
  5. Screenshot saved to cache via CacheService
  6. CommandHandler sends screenshot to user via Telegram API

Components

  • RecipeService: Coordinates cache and scraper, handles recipe retrieval
  • WikiScraper: Manages Selenium WebDriver, scrapes Minecraft Wiki pages
  • CacheService: Two-level caching (memory + disk), auto-cleanup of old files
  • CommandHandler: Processes Telegram commands and messages
  • LanguageDetector: Detects Cyrillic characters for Russian language support
  • ItemNameNormalizer: Normalizes item names, generates search variants

Configuration

Settings in BotConfig.kt:

  • PAGE_LOAD_TIMEOUT_MS - Page load timeout (default: 3000ms)
  • CACHE_TTL_DAYS - Cache TTL (default: 7 days)
  • WIKI_BASE_URL_EN / WIKI_BASE_URL_RU - Wiki URLs

About

Telegram bot written in Kotlin to search Minecraft items craft recipes

Topics

Resources

License

Stars

Watchers

Forks