https://github.com/purr/telegram-dictionary
A Telegram bot that works in inline mode to lookup definitions of words in public dictionaries.
https://github.com/purr/telegram-dictionary
aiogram dictionary telegram
Last synced: 6 days ago
JSON representation
A Telegram bot that works in inline mode to lookup definitions of words in public dictionaries.
- Host: GitHub
- URL: https://github.com/purr/telegram-dictionary
- Owner: purr
- License: mit
- Created: 2025-03-20T21:22:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-20T22:34:22.000Z (over 1 year ago)
- Last Synced: 2025-03-28T05:29:25.545Z (over 1 year ago)
- Topics: aiogram, dictionary, telegram
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Telegram Dictionary Bot 📚
This bot provides dictionary definitions for words directly in Telegram chats using inline queries.
## Features
- Fast inline query lookups for word definitions
- Multiple dictionary sources (Primary API, WordNet, Urban Dictionary)
- Detailed word information including:
- Definitions
- Examples
- Synonyms and antonyms
- Pronunciations
- Audio links where available
- Fallback to WordNet when words aren't found in the primary API
- Urban Dictionary results for slang and colloquial meanings
## Requirements
- Python 3.7+
- NLTK with WordNet corpus
- Aiogram 3.x
- Requests
## NLTK Data Setup
This bot uses NLTK's WordNet corpus as a fallback dictionary. You need to download the WordNet data before running the bot:
```python
import nltk
nltk.download('wordnet')
```
You can run this in a Python interpreter, or add it to a setup script. The data is downloaded once and stored locally.
## Configuration
Create a `.env` file in the root directory with the following variables:
```
BOT_TOKEN=your_telegram_bot_token
```
## Installation
1. Clone this repository
2. Install requirements: `pip install -r requirements.txt`
3. Download NLTK data: `python -c "import nltk; nltk.download('wordnet')"`
4. Create a `.env` file with your Telegram bot token
5. Run the bot: `python run.py`
## Usage
In any Telegram chat, type `@YourBotUsername word` to look up definitions for "word".
The bot will display:
1. Dictionary definition (if available)
2. Detailed information (if significantly different from basic definition)
3. Urban Dictionary results (if available)
## How It Works
1. The bot monitors inline queries sent to it 📡
2. When a user types `@your_bot_name` followed by a word, it triggers an inline query
3. The bot waits for the user to finish typing (using a debounce technique) ⌨️
4. It then looks up the word in the Free Dictionary API 🔎
5. If a definition is found, it formats and returns it as an inline result ✅
6. If no definition is found in the primary dictionary, it falls back to WordNet 📚
7. If found in WordNet, it displays multiple definitions with synonyms and examples
8. If no definition is found in any dictionary, it notifies the user ❌
## Project Structure
- `bot.py`: Main bot implementation using aiogram
- `dictionary_service.py`: Service for dictionary lookups and formatting
- `config.py`: Configuration settings
- `run.py`: Script to run the bot with dependency checking
- `requirements.txt`: List of required Python packages
- `.env.example`: Example environment variables file
## License
This project is licensed under the MIT License - see the LICENSE file for details. 📜
## Acknowledgements
- [Free Dictionary API](https://dictionaryapi.dev/) for providing free dictionary data
- [NLTK WordNet](https://www.nltk.org/howto/wordnet.html) for comprehensive lexical database
- [aiogram](https://docs.aiogram.dev/) for the Telegram Bot framework
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request. 🤝