Skip to main content

Async ready traQ Bot library

Project description

aiotraq-bot

Async ready traQ Bot library written in Python.

PyPI - Version GitHub license CI

Requirements

aiotraq-bot は以下のライブラリを使用しています。

Installation

pip install aiotraq-bot

Usage

TraqHttpBot を使って http bot を作成することができます。

traQ->BOTサーバーへのイベント受け取り部分を補助します。 BOTサーバー->traQへのイベント送信は aiotraq 等を利用してください。

import os
from aiotraq_bot import TraqHttpBot

bot = TraqHttpBot(verification_token=os.getenv("BOT_VERIFICATION_TOKEN"))

@bot.event()
async def on_message(payload: MessageCreatedPayload):
    print(payload)

if __name__ == "__main__":
  bot.run()

Event handler の登録

イベントの登録は @bot.event() デコレータを使って行うことができます。 event の引数として対象のイベントを指定するか、関数の型ヒントを使って指定することができます。

MESSAGE_CREATED イベントを型ヒントを使って指定する場合

@bot.event()
async def on_message(payload: MessageCreatedPayload):
    print(payload)

MESSAGE_CREATEDイベントを引数を用いて指定する場合

@bot.event("MESSAGE_CREATED")
async def on_message(payload):
    print(payload)

Acknowledgements

This project is inspired by python-traq-bot.

License

This project is licensed under the terms of the MIT license.

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

aiotraq_bot-0.1.2.tar.gz (7.5 kB view hashes)

Uploaded Source

Built Distribution

aiotraq_bot-0.1.2-py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 3

Supported by

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