Skip to main content

A Twitch bot framework with event subscription and alert handling capabilities

Project description

Pool Guy 🏊‍♂️

A lightweight Twitch bot framework.

Python Version License

Features

  • EventSub websocket handling
  • Priority queue for EventSub notifications
  • Bot command and ratelimit decorators
  • Framework to support multiple storage backends

Limitations:

Quick Setup

Install from pypi:

pip install poolguy

Install directly from git:

pip install git+https://github.com/s4w3d0ff/pool-guy.git

Simple Command Bot:

import asyncio
import logging
from poolguy import CommandBot, Alert, command, rate_limit

logger = logging.getLogger(__name__)


class ExampleBot(CommandBot):
    @command(name="hi", aliases=["hello"])
    @rate_limit(calls=1, period=10, warn_cooldown=5)
    async def hi(self, user, channel, args):
        await self.send_chat(f"Hi, @{user['username']}", channel["broadcaster_id"])

    async def my_loop(self):
        logger.warning(f'my_loop started')
        while self.ws._running:
            await asyncio.sleep(10)
            logger.info(f"loop")
        logger.warning(f'my_loop stopped')

    async def after_login(self):
        await self.add_task(self.my_loop)


class ChannelChatMessageAlert(Alert):
    """channel.chat.message"""
    queue_skip = True
    store = False
    priority = 3

    async def process(self):
        logger.debug(f'{self.data}')
        await self.bot.command_check(self.data)
        logger.info(f'[Chat] {self.data["chatter_user_name"]}: {self.data["message"]["text"]}')


if __name__ == '__main__':
    import os
    from rich.logging import RichHandler
    logging.basicConfig(
        format="%(message)s",
        datefmt="%X",
        level=logging.INFO,
        handlers=[RichHandler(rich_tracebacks=True)]
    )
    bot = ExampleBot(
        client_id=os.getenv("CLIENT_ID"),
        client_secret=os.getenv("CLIENT_SECRET"),
        redirect_uri="http://localhost:5000/callback",
        scopes=[
            "user:read:chat",
            "user:write:chat"
        ],
        channels={
            "channel.chat.message": None
        }, 
        storage="json",
        browser={
            "chrome": "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
        },
        max_retries=30,
        retry_delay=10,
        alert_objs={
            "channel.chat.message": ChannelChatMessageAlert
        }
    )
    asyncio.run(bot.start())
    

More fleshed out example: https://github.com/s4w3d0ff/deezbot

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

poolguy-0.1.8.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

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

poolguy-0.1.8-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file poolguy-0.1.8.tar.gz.

File metadata

  • Download URL: poolguy-0.1.8.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for poolguy-0.1.8.tar.gz
Algorithm Hash digest
SHA256 b4d5914bab414d91dac684f8715426a416bd013ffc41df286e581a92ff95c377
MD5 391ee32197546a00b21a2fe15d7caf87
BLAKE2b-256 27333a092fe47658abb48bf039f62b07db1acabaf35a7bd7e8f0a2ced09f39eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for poolguy-0.1.8.tar.gz:

Publisher: python-publish.yml on s4w3d0ff/pool-guy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file poolguy-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: poolguy-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for poolguy-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0e599e3d255b356ea227608506f3dd12b53d9a801011dd11d0cf004bf2f9fcc2
MD5 60e901d872872d861d0ec3dffd1d0a4b
BLAKE2b-256 03ce35837907a9bde90426b1baa4826c19b24a13251e31165ab9278fe5ea0acb

See more details on using hashes here.

Provenance

The following attestation bundles were made for poolguy-0.1.8-py3-none-any.whl:

Publisher: python-publish.yml on s4w3d0ff/pool-guy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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