2025-05-05 22:25:01 +02:00
# SnekBot: Your Instant Chat Companion
2025-02-01 15:58:18 +01:00
2025-05-05 22:25:01 +02:00
## Create Your Own Bot in Minutes
2025-02-01 15:58:18 +01:00
2025-05-05 22:25:01 +02:00
### Overview
SnekBot is designed for rapid deployment and customization, providing a fully asynchronous and production-ready chat bot solution. It is built to handle network issues effectively, ensuring a reliable user experience.
2025-02-01 15:58:18 +01:00
2025-05-05 22:13:45 +02:00
### Prerequisites
2025-05-05 22:25:01 +02:00
- Python 3.8 or higher
- Basic understanding of Python programming
2025-02-01 15:58:18 +01:00
2025-05-05 22:25:01 +02:00
### Installation Instructions
2025-02-01 15:58:18 +01:00
2025-05-05 22:25:01 +02:00
#### 1. Prepare Your Environment
2025-05-05 22:13:45 +02:00
```bash
2025-05-05 22:25:01 +02:00
# For Ubuntu/Debian users:
2025-05-05 22:13:45 +02:00
sudo apt install python3 python3-venv python3-pip -y
2025-02-01 15:58:18 +01:00
2025-05-05 22:25:01 +02:00
# Create a virtual environment for your bot
2025-05-05 22:13:45 +02:00
python3 -m venv venv
source venv/bin/activate
```
2025-02-01 15:58:18 +01:00
2025-05-05 22:25:01 +02:00
#### 2. Install SnekBot
2025-05-05 22:13:45 +02:00
```bash
pip install git+https://molodetz.nl/retoor/snekbot.git
```
2025-02-01 15:58:18 +01:00
2025-05-05 22:25:01 +02:00
### Bot Development
To create your bot, use the following template:
2025-02-01 15:58:18 +01:00
```python
2025-02-10 14:16:55 +01:00
import asyncio
2025-02-01 15:58:18 +01:00
from snekbot.bot import Bot
2025-05-05 22:25:01 +02:00
class CustomSnekBot(Bot):
2025-02-10 14:16:55 +01:00
async def on_join(self, channel_uid):
await self.send_message(
2025-04-24 21:03:12 +02:00
channel_uid,
2025-05-05 22:25:01 +02:00
"Hello! I am here to assist you."
2025-02-10 14:16:55 +01:00
)
2025-02-01 15:58:18 +01:00
2025-02-10 14:16:55 +01:00
async def on_message(self, sender_username, sender_nick, channel_uid, message):
message = message.lower()
if "hello" in message:
2025-05-05 22:25:01 +02:00
await self.send_message(channel_uid, f"Greetings, {sender_nick}!")
2025-02-01 15:58:18 +01:00
elif "bye" in message:
2025-05-05 22:25:01 +02:00
await self.send_message(channel_uid, f"Goodbye, {sender_nick}!")
2025-02-01 15:58:18 +01:00
2025-05-05 22:25:01 +02:00
# Initialize your bot
bot = CustomSnekBot(
2025-05-05 22:13:45 +02:00
url="wss://your-snek-instance.com/rpc.ws",
2025-05-05 22:25:01 +02:00
username="your_bot_username",
password="your_secure_password"
2025-04-24 21:03:12 +02:00
)
2025-02-01 15:58:18 +01:00
asyncio.run(bot.run())
```
2025-05-05 22:25:01 +02:00
### Running Your Bot
2025-02-01 15:58:18 +01:00
```bash
2025-05-05 22:25:01 +02:00
python your_bot_script.py
2025-02-01 15:58:18 +01:00
```
2025-02-10 14:16:55 +01:00
2025-05-05 22:25:01 +02:00
### Event Handlers
You can override the following event handlers:
- `on_join` : Triggered when the bot joins a channel
- `on_leave` : Triggered when the bot leaves a channel
- `on_ping` : Responds to ping messages
- `on_mention` : Handles direct mentions
- `on_message` : Processes incoming messages
2025-05-05 22:13:45 +02:00
2025-05-05 22:25:01 +02:00
### Additional Information
- For detailed logging, include `logging.basicConfig(level=logging.DEBUG)` in your code.
- The bot is designed to automatically reconnect in case of connection drops.
- Feel free to customize the bot to meet your specific requirements.
2025-02-10 14:16:55 +01:00
2025-05-05 22:25:01 +02:00
### Contribution Guidelines
Contributions are welcome. Please submit pull requests for any enhancements or bug fixes.
2025-02-10 14:16:55 +01:00
2025-05-05 22:13:45 +02:00
### License
2025-05-05 22:25:01 +02:00
This project is licensed under the MIT License.