Topluyo Bot Python kütüphanesi – WebSocket tabanlı asenkron bot istemcisi
pip install topluyobotgit clone https://github.com/Topluyo/TopluyoBOTPY.git
cd TopluyoBOTPY
pip install -e .Gereksinimler:
- Python 3.8+
- aiohttp >= 3.9.0
- websockets >= 12.0
from topluyobot import TopluyoBOT
# Botu oluştur
bot = TopluyoBOT("YOUR_BOT_TOKEN_HERE")
# Bağlantı başarılı
@bot.on("connected")
def on_connected():
print("✅ Bota bağlandı!")
# Mesaj al
@bot.on("message")
def on_message(data):
print(f"Mesaj alındı: {data}")
# Botu başlat
bot.run()Bot aşağıdaki mesaj türlerini işleyebilir:
@bot.on("message")
def handler(data):
if data.get("action") == "message/send":
user_id = data["user_id"]
text = data["message"]
print(f"DM from {user_id}: {text}")if data.get("action") == "post/add":
channel_id = data["channel_id"]
user_id = data["user_id"]
message = data["message"]if data.get("action") == "post/mention":
user_id = data["user_id"]
message = data["message"]
print(f"Bot mentioned by {user_id}")if data.get("action") == "post/bumote":
form = data["message"]["form"]
submit = data["message"]["submit"]# Grup katılma
if data.get("action") == "group/join":
group_id = data["group_id"]
# Grup ayrılma
elif data.get("action") == "group/leave":
group_id = data["group_id"]
# Grup atılma
elif data.get("action") == "group/kick":
group_id = data["group_id"]if data.get("action") == "turbo/transfer":
qty = data["message"]["quantity"]
note = data["message"]["message"]Botu token ile oluşturur.
bot = TopluyoBOT("your_token")Event listener kaydeder.
Desteklenen eventler:
connected– Bağlantı başarılıclose– Bağlantı kapandıauth_problem– Token geçersizerror– Hata oluştumessage– Mesaj alındı
@bot.on("connected")
def handler():
pass
@bot.on("error")
def handler(err):
print(f"Error: {err}")Botu başlatır (bloklayıcı).
bot.run() # Ctrl+C ile durdurAPI'ye senkron POST isteği gönderir.
response = bot.post_sync("messages.send", {
"user_id": "12345",
"message": "Merhaba!"
})API'ye asenkron POST isteği gönderir.
response = await bot.post_async("messages.send", {
"user_id": "12345",
"message": "Merhaba!"
})from topluyobot import TopluyoBOT, BotMessage
bot = TopluyoBOT("YOUR_TOKEN")
@bot.on("message")
def handle_message(data: BotMessage):
if data.get("action") == "message/send":
user_id = data["user_id"]
text = data["message"]
# Geri yanıt
bot.post_sync("messages.send", {
"user_id": user_id,
"message": f"Echo: {text}"
})
bot.run()from topluyobot import TopluyoBOT
bot = TopluyoBOT("YOUR_TOKEN")
@bot.on("connected")
def on_connected():
print("✅ Bağlandı")
@bot.on("close")
def on_close():
print("🔌 Bağlantı kapandı")
@bot.on("auth_problem")
def on_auth():
print("❌ Token geçersiz")
@bot.on("error")
def on_error(err):
print(f"⚠️ Hata: {err}")
@bot.on("message")
def on_msg(data):
print(f"📨 {data}")
bot.run()Detaylı örnek için example.py dosyasına bakın.
topluyobot/
├── __init__.py # Ana exports
├── bot.py # TopluyoBOT sınıfı
├── py.typed # PEP 561 type hints
└── ...
Kütüphane tam type hint desteğine sahiptir:
from topluyobot import TopluyoBOT, BotMessage
bot: TopluyoBOT = TopluyoBOT("token")
@bot.on("message")
def handler(data: BotMessage) -> None:
passpip install pytest pytest-asyncio
pytestpip install build
python -m buildMIT License – Detaylar için LICENSE dosyasını okuyun.
- Resmi Site: topluyo.com
- Email: info@topluyo.com
- Issues: GitHub Issues
Pull request'ler hoş karşılanır! Büyük değişiklikler için önce bir issue açın.
- Fork et
- Feature branch oluştur (
git checkout -b feature/AmazingFeature) - Commit et (
git commit -m 'Add some AmazingFeature') - Push et (
git push origin feature/AmazingFeature) - Pull Request aç
Türkçe Dokümantasyon | English Docs (gelecek)