A lightweight, reliable IRC bot that provides real-time weather information using the Open-Meteo API. Designed for 24/7 operation with robust error handling and efficient resource usage.
- Real-time weather data from Open-Meteo API (no API key required)
- Global city search with geocoding
- Colorized IRC output with weather icons
- SSL/TLS support for secure connections
- Automatic reconnection with exponential backoff
- Efficient resource usage with proper timeout handling
- Production-tested for 24/7 stability
- Current temperature (°C)
- Weather conditions (clear, cloudy, rain, snow, thunderstorm, etc.)
- Relative humidity (%)
- Wind speed (km/h)
!weather <city>- Get current weather for any city worldwide- Example:
!weather Belgrade - Example:
!weather New York
- Example:
!help- Display bot help information
- Python 3.7+
requestslibrary
- Clone the repository:
git clone https://github.com/MansionNET/weatherbot.git
cd weatherbot- Install dependencies:
pip install requests- Configure the bot:
Edit
weatherbot.pyand update:
self.server = "your.irc.server.com"
self.port = 6697 # or 6667 for non-SSL
self.nickname = "WeatherBot"
self.channels = ["#channel1", "#channel2"]- (Optional) For NickServ authentication, add:
self.password = "your_nickserv_password"And uncomment the NickServ identification lines in the connect() method.
python3 weatherbot.py- Create service file
/etc/systemd/system/weatherbot.service:
[Unit]
Description=MansionNet Weather Bot
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=youruser
WorkingDirectory=/path/to/weatherbot
ExecStart=/usr/bin/python3 /path/to/weatherbot/weatherbot.py
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target- Enable and start:
sudo systemctl enable weatherbot.service
sudo systemctl start weatherbot.service- Check status:
sudo systemctl status weatherbot.serviceThe bot uses SSL by default. To disable certificate verification (for self-signed certs):
self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE- Socket timeout: 1.0 second (prevents blocking)
- API request timeout: 5 seconds (for geocoding and weather data)
- Reconnection delay: 30 seconds (after errors)
- Colors: Modify the
TEXTvariable inget_weather()for different IRC color codes - Weather Icons: Customize the symbols (▸, ❋, ⟳) in the return string
- Channels: Add or remove channels in the
self.channelslist
This bot uses the free Open-Meteo API:
- No API key required
- No rate limiting for reasonable use
- Global coverage
- Real-time data updates
Geocoding provided by Open-Meteo's geocoding API.
- Non-blocking socket operations with timeout
- Automatic reconnection on connection loss
- Proper handling of IRC PING/PONG
- Buffer management for split messages
- Graceful handling of network timeouts
- Unicode decode error recovery
- API request failure fallbacks
- Connection closed detection
- Sleep intervals during idle periods (0.1s when no data)
- Socket timeouts prevent CPU spinning
- Efficient buffer processing
- Minimal memory footprint
- Check IRC server address and port
- Verify SSL/TLS requirements
- Check firewall rules for outbound connections
- Verify the bot is in the correct channels
- Check channel permissions (some channels may be +m or require voice)
- Review logs for error messages
- Ensure you're running the latest version with timeout fixes
- Check network stability
- Monitor system logs for connection issues
- Verify internet connectivity
- Check if Open-Meteo API is accessible
- Ensure DNS resolution is working
- Store NickServ passwords in environment variables or secrets management
- Use SSL/TLS for IRC connections when available
- Run the bot as a non-privileged user
- Monitor logs for unusual activity
- Use systemd status to check bot health
- Monitor CPU and memory usage
- Set up log rotation for long-term operation
- Consider external monitoring for uptime
<user> !weather London
<WeatherBot> London, United Kingdom 【Partly cloudy】 ▸ 12°C ❋ 78% ⟳ 15 km/h
<user> !weather Tokyo
<WeatherBot> Tokyo, Japan 【Clear sky】 ▸ 18°C ❋ 45% ⟳ 8 km/h
<user> !weather Belgrade
<WeatherBot> Belgrade, Serbia 【Overcast】 ▸ 5°C ❋ 82% ⟳ 12 km/h
Contributions are welcome! Please feel free to submit issues or pull requests.
- Follow PEP 8 style guidelines
- Add comments for complex logic
- Test thoroughly before submitting PRs
- Update README for new features
[Your chosen license - e.g., MIT, GPL, etc.]
- Weather data provided by Open-Meteo
- Built for the MansionNET IRC community
- Inspired by classic IRC bots and modern Python practices
- Fixed: Critical CPU spinning bug in main message loop
- Added: Socket timeout handling for non-blocking operations
- Added: API request timeouts (5 seconds)
- Improved: Connection error handling and reconnection logic
- Improved: Resource efficiency and stability for 24/7 operation
- Basic weather information functionality
- Multi-channel support
- IRC color formatting
- Open-Meteo API integration
For issues, questions, or suggestions:
- Open an issue on GitHub
- Contact on IRC: #lobby on irc.inthemansion.com port: 6697 or https://webirc.inthemansion.com/
Made with ☕ for the MansionNET community