Skip to content

RoastedBrotato/CalorieCountingBot

Repository files navigation

CalorieCountingBot

A Discord bot designed to help users track their daily calorie intake and nutritional information.

Features

  • 🍎 Track calories for different food items
  • πŸ“Š View nutritional information
  • πŸ“Έ AI-powered image recognition for food calorie estimation
  • πŸ” Enhanced analysis with text descriptions for better accuracy
  • πŸ“ Text-only estimation for foods without images
  • πŸ€– Google Gemini Vision integration for accurate food analysis
  • πŸ’¬ Interactive Discord commands
  • 🎯 Easy-to-use command system

Setup Instructions

Prerequisites

  • Python 3.8 or higher
  • Discord account
  • Discord server where you have permission to add bots
  • Google AI Studio account (for image recognition features)

Installation

  1. Clone/Download this repository

  2. Set up Python virtual environment

    python -m venv venv
    venv\Scripts\activate  # On Windows
    # source venv/bin/activate  # On macOS/Linux
  3. Install dependencies

    pip install -r requirements.txt
  4. Create a Discord Bot

  5. Configure environment variables

    • Edit the .env file
    • Replace your_bot_token_here with your actual bot token
    • Get a Gemini API key from Google AI Studio
    • Replace your_gemini_api_key_here with your actual Gemini API key
    DISCORD_TOKEN=your_actual_bot_token_here
    COMMAND_PREFIX=!
    GEMINI_API_KEY=your_actual_gemini_api_key_here
    
  6. Invite bot to your server

    • In Discord Developer Portal, go to "OAuth2" > "URL Generator"
    • Select "bot" scope
    • Select necessary permissions (Send Messages, Read Message History, etc.)
    • Use the generated URL to invite the bot to your server
  7. Run the bot

    python main.py

Available Commands

Basic Commands

  • !ping - Check if bot is responsive
  • !info - Display bot information
  • !addcalories <calories> [food_name] - Add calories for a food item
  • !today - View your calories for today with numbered entries
  • !history - View all your calorie entries for today
  • !remove <#> - Remove a specific calorie entry by number
  • !edit <#> <calories> [new_name] - Edit a calorie entry
  • !reset - Reset your calories for today (with confirmation)
  • !calorie-help - Show all calorie tracking commands
  • !help - Show all available commands

AI-Powered Food Analysis

  • !analyzeimage - Analyze food image for calorie estimation (attach image)
  • !analyzefood [description] - Enhanced analysis with measurements (e.g., "350g chicken and salad")
  • !estimate <description> - Text-only calorie estimation (no image needed)
  • !testapi - Test if Gemini AI is working properly

πŸ”₯ Quick Calorie Logging

After any AI analysis, the bot will add βœ… and ❌ reaction buttons:

  • React with βœ… to automatically add the estimated calories to your daily total
  • React with ❌ to decline adding the calories
  • No need to manually type !addcalories - just click the reaction!

Advanced Food Analysis Features

1. Image-Only Analysis (!analyzeimage)

Upload any food image to get:

  • πŸ”₯ Calorie estimation based on visible portion
  • πŸ“Š Nutritional breakdown (protein, carbs, fat, etc.)
  • 🎯 Confidence score for the analysis
  • πŸ“ Portion size estimation
  • πŸ’‘ Health notes and nutritional insights
  • βœ…/❌ Quick add buttons via reactions

2. Enhanced Image + Description Analysis (!analyzefood)

Get more accurate results by combining images with descriptions:

  • Upload an image and provide measurements
  • Example: !analyzefood 350g grilled chicken breast with 2 cups rice
  • Higher confidence scores due to specific measurements
  • Better portion size accuracy
  • βœ…/❌ Quick add buttons via reactions

3. Text-Only Estimation (!estimate)

Get calorie estimates without images:

  • Perfect for homemade meals or when you can't take photos
  • Example: !estimate 1 cup oatmeal with banana and honey
  • Includes nutritional breakdown and health insights

Example Usage

Basic Calorie Tracking

!addcalories 250 Apple
!addcalories 150 Banana
!today
!reset
!ping
!info

Daily Calorie Tracking Examples

View Today's Progress

!today

Result: Shows your total calories with numbered entries for easy reference Example Output:

πŸ“Š John's Calories Today
Total: 1,247 kcal

🍽️ Recent Foods
1. 09:00 Oatmeal with berries - 180 kcal
2. 12:15 Caesar salad - 250 kcal
3. 14:30 Grilled chicken - 300 kcal

View Full History

!history

Result: Shows ALL your calorie entries for today (not limited to 10)

Remove Specific Entry

!remove 2

Result: Removes entry #2 (Caesar salad) and updates your daily total

Edit Specific Entry

!edit 3 350 Grilled chicken breast
!edit 1 200

Result: Updates entry #3 to 350 calories and changes name, or just updates calories

Add Calories Manually

!addcalories 300 Grilled chicken

Result: Adds 300 calories and shows your updated daily total

Reset Daily Progress

!reset

Result: Clears today's calories with confirmation prompt

AI Food Analysis Examples

Image Analysis

  1. Upload a photo of your meal β†’ !analyzeimage
  2. Get instant calorie estimate β†’ "Grilled chicken breast: ~300 calories"
  3. View nutritional breakdown β†’ Protein: 45g, Carbs: 0g, Fat: 8g
  4. Add to your log β†’ React with βœ… to add calories automatically

Enhanced Analysis (Image + Description)

  1. Upload photo + description β†’ !analyzefood 350g salmon with vegetables
  2. Get enhanced accuracy β†’ Higher confidence due to specific measurements
  3. Better nutritional info β†’ More precise calculations based on weight
  4. Quick logging β†’ React with βœ… to add to daily total

Text-Only Analysis

  1. Describe your food β†’ !estimate 2 slices whole wheat toast with peanut butter
  2. Get instant estimate β†’ "Whole wheat toast with peanut butter: ~320 calories"
  3. No image needed β†’ Perfect for quick logging

Project Structure

CalorieCountingBot/
β”œβ”€β”€ main.py              # Main bot file
β”œβ”€β”€ config.py            # Configuration settings
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ .env                # Environment variables (keep private!)
β”œβ”€β”€ .gitignore          # Git ignore file
β”œβ”€β”€ README.md           # This file
└── venv/               # Virtual environment

Development

To extend the bot with more features:

  1. Add new commands in main.py
  2. Update configuration in config.py
  3. Install additional dependencies in requirements.txt

Security Notes

  • Never commit your .env file to version control
  • Keep your Discord bot token private
  • Regularly rotate your bot token if needed

Troubleshooting

Common Issues

  1. Bot doesn't respond

    • Check if bot token is correct in .env
    • Ensure bot has necessary permissions in Discord server
    • Check if bot is online in Discord
  2. Import errors

    • Make sure virtual environment is activated
    • Install all dependencies: pip install -r requirements.txt
  3. Permission errors

    • Ensure bot has "Send Messages" and "Read Message History" permissions
    • Check channel-specific permissions

Contributing

Feel free to contribute by:

  • Adding new features
  • Fixing bugs
  • Improving documentation
  • Suggesting enhancements

License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages