e5f550c1b9f5600e10f6e95f321ae2ea32828c6e
SnekBot: Your Instant Chat Companion
Create Your Own Bot in Minutes
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.
Prerequisites
- Python 3.8 or higher
- Basic understanding of Python programming
Installation Instructions
1. Prepare Your Environment
# For Ubuntu/Debian users:
sudo apt install python3 python3-venv python3-pip -y
# Create a virtual environment for your bot
python3 -m venv venv
source venv/bin/activate
2. Install SnekBot
pip install git+https://molodetz.nl/retoor/snekbot.git
Bot Development
To create your bot, use the following template:
import asyncio
from snekbot.bot import Bot
class CustomSnekBot(Bot):
async def on_join(self, channel_uid):
await self.send_message(
channel_uid,
"Hello! I am here to assist you."
)
async def on_message(self, sender_username, sender_nick, channel_uid, message):
message = message.lower()
if "hello" in message:
await self.send_message(channel_uid, f"Greetings, {sender_nick}!")
elif "bye" in message:
await self.send_message(channel_uid, f"Goodbye, {sender_nick}!")
# Initialize your bot
bot = CustomSnekBot(
url="wss://your-snek-instance.com/rpc.ws",
username="your_bot_username",
password="your_secure_password"
)
asyncio.run(bot.run())
Running Your Bot
python your_bot_script.py
Event Handlers
You can override the following event handlers:
on_join: Triggered when the bot joins a channelon_leave: Triggered when the bot leaves a channelon_ping: Responds to ping messageson_mention: Handles direct mentionson_message: Processes incoming messages
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.
Contribution Guidelines
Contributions are welcome. Please submit pull requests for any enhancements or bug fixes.
License
This project is licensed under the MIT License.
Description
The snek bot API. Use this to create a snek bot withing minutes! With nice example. The tutorial of creating a snek bot is just a few lines and a code snippet!
304 KiB
Languages
Python
98.9%
Makefile
1.1%