Skip to main content

Topluyo Bot Python kütüphanesi - WebSocket tabanlı bot istemcisi

Project description

TopluyoBOTPY 🤖

Topluyo Bot Python kütüphanesi – WebSocket tabanlı asenkron bot istemcisi

PyPI version Python 3.8+ MIT License


📋 İçerik


💻 Kurulum

PyPI'den (Önerilen)

pip install topluyobot

Geliştirme İçin

git clone https://github.com/yourusername/TopluyoBOTPY.git
cd TopluyoBOTPY
pip install -e .

Gereksinimler:

  • Python 3.8+
  • aiohttp >= 3.9.0
  • websockets >= 12.0

🚀 Hızlı Başlangıç

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()

📩 Mesaj Türleri

Bot aşağıdaki mesaj türlerini işleyebilir:

1. Direkt Mesaj (message/send)

@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}")

2. Kanal Postu (post/add)

if data.get("action") == "post/add":
    channel_id = data["channel_id"]
    user_id = data["user_id"]
    message = data["message"]

3. Bot Mention (post/mention)

if data.get("action") == "post/mention":
    user_id = data["user_id"]
    message = data["message"]
    print(f"Bot mentioned by {user_id}")

4. Bumote Formu (post/bumote)

if data.get("action") == "post/bumote":
    form = data["message"]["form"]
    submit = data["message"]["submit"]

5. Grup Olayları

# 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"]

6. Turbo Transfer (turbo/transfer)

if data.get("action") == "turbo/transfer":
    qty = data["message"]["quantity"]
    note = data["message"]["message"]

📚 API Referansı

TopluyoBOT

__init__(token: str)

Botu token ile oluşturur.

bot = TopluyoBOT("your_token")

@bot.on(event: str)

Event listener kaydeder.

Desteklenen eventler:

  • connected – Bağlantı başarılı
  • close – Bağlantı kapandı
  • auth_problem – Token geçersiz
  • error – Hata oluştu
  • message – Mesaj alındı
@bot.on("connected")
def handler():
    pass

@bot.on("error")
def handler(err):
    print(f"Error: {err}")

bot.run()

Botu başlatır (bloklayıcı).

bot.run()  # Ctrl+C ile durdur

bot.post_sync(method: str, params: dict)

API'ye senkron POST isteği gönderir.

response = bot.post_sync("messages.send", {
    "user_id": "12345",
    "message": "Merhaba!"
})

await bot.post_async(method: str, params: dict)

API'ye asenkron POST isteği gönderir.

response = await bot.post_async("messages.send", {
    "user_id": "12345",
    "message": "Merhaba!"
})

💡 Örnekler

Örnek 1: Echo Bot

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()

Örnek 2: Olay Yöneticisi

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()

Örnek 3: Mesaj Türlerine Göre İşlem

Detaylı örnek için example.py dosyasına bakın.


🔧 Geliştiriciler İçin

Kütüphane Yapısı

topluyobot/
├── __init__.py       # Ana exports
├── bot.py            # TopluyoBOT sınıfı
├── py.typed          # PEP 561 type hints
└── ...

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:
    pass

Test Etme

pip install pytest pytest-asyncio
pytest

Derleme

pip install build
python -m build

📝 Lisans

MIT License – Detaylar için LICENSE dosyasını okuyun.


📧 İletişim


🤝 Katkıda Bulunma

Pull request'ler hoş karşılanır! Büyük değişiklikler için önce bir issue açın.

  1. Fork et
  2. Feature branch oluştur (git checkout -b feature/AmazingFeature)
  3. Commit et (git commit -m 'Add some AmazingFeature')
  4. Push et (git push origin feature/AmazingFeature)
  5. Pull Request aç

Türkçe Dokümantasyon | English Docs (gelecek)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

topluyobot-1.0.4.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

topluyobot-1.0.4-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file topluyobot-1.0.4.tar.gz.

File metadata

  • Download URL: topluyobot-1.0.4.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for topluyobot-1.0.4.tar.gz
Algorithm Hash digest
SHA256 27ffeb81cb723c83996e11ca340d3e1e1303fa7897b6394225bb3be294b9ca3e
MD5 d9937b9c33eacbae391053e3fff6255f
BLAKE2b-256 6222b9089c0cc9a9695d124936c131b0632798d254170b25ae1130f26bf29734

See more details on using hashes here.

File details

Details for the file topluyobot-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: topluyobot-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for topluyobot-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 db1c798e7140016ddcd173bb09d737c407994ba4944a7673bf352dfb9a4b928f
MD5 465626b1604b404d25f8a994f70e39bb
BLAKE2b-256 125be1b7093a2dbb56cb321dff379c985a09e10fa8413339ff77f9d36a7ba431

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page