joshuaskelly / twitch-observer

Turn Twitch chatter into Python events
MIT License
26 stars 6 forks source link
python twitch twitch-bot

twitch-observer

Turn Twitch chatter into Python events.

twitch-observer

License: GPL v3 Python 2 Python 3 PyPI version Build Status Documentation Status

twitchobserver makes interacting with Twitch chat super easy. It is built and tuned for realtime applications. You can make chatbots chat. You can build Twitch Plays video games.

Features

Installation

$ pip install twitchobserver

Usage

from twitchobserver import Observer

observer = Observer('Nick', 'oauth:abcdefghijklmnopqrstuvwxyz0123')
observer.start()
observer.join_channel('channel')
observer.send_message('Hello and goodbye', 'channel')
observer.leave_channel('channel')

Documentation

API documentation can be found over on ReadtheDocs.org.

Tests

$ python -m unittest discover -s tests

Examples

Echo bot

Whenever a message is sent, echo it back. The Observer is created as a context manager object which will implicitly handle calling start() and stop().

import time
from twitchobserver import Observer

with Observer('Nick', 'oauth:abcdefghijklmnopqrstuvwxyz0123') as observer:
    observer.join_channel('channel')

    while True:
        try:
            for event in observer.get_events():
                if event.type == 'TWITCHCHATMESSAGE':
                    observer.send_message(event.message, event.channel)

            time.sleep(1)

        except KeyboardInterrupt:
            observer.leave_channel('channel')
            break

More examples can be found in the Cookbook.

Contributors

Joshua Skelton Felix Siebeneicker Kovalchuk Evgeny
Joshua Skelton Felix Siebeneicker Kovalchuk Evgeny

Changelog

For a detailed history of changes made to the twitchobserver see the changelog.

License

MIT

See the license document for the full text.