A Twitch bot framework with event subscription and alert handling capabilities
Project description
Pool Guy 🏊♂️
A lightweight Twitch bot framework.
Features
- EventSub websocket handling
- Priority queue for EventSub notifications
- Bot command and ratelimit decorators
- Framework to support multiple storage backends
Limitations:
- Conduit/shards are not implimented
- Only uses "OIDC authorization code grant flow" for oauth tokens
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4d5914bab414d91dac684f8715426a416bd013ffc41df286e581a92ff95c377
|
|
| MD5 |
391ee32197546a00b21a2fe15d7caf87
|
|
| BLAKE2b-256 |
27333a092fe47658abb48bf039f62b07db1acabaf35a7bd7e8f0a2ced09f39eb
|
Provenance
The following attestation bundles were made for poolguy-0.1.8.tar.gz:
Publisher:
python-publish.yml on s4w3d0ff/pool-guy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
poolguy-0.1.8.tar.gz -
Subject digest:
b4d5914bab414d91dac684f8715426a416bd013ffc41df286e581a92ff95c377 - Sigstore transparency entry: 191759255
- Sigstore integration time:
-
Permalink:
s4w3d0ff/pool-guy@48b59ae598f063e673cc3d2b64e6774125c90fa5 -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/s4w3d0ff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@48b59ae598f063e673cc3d2b64e6774125c90fa5 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e599e3d255b356ea227608506f3dd12b53d9a801011dd11d0cf004bf2f9fcc2
|
|
| MD5 |
60e901d872872d861d0ec3dffd1d0a4b
|
|
| BLAKE2b-256 |
03ce35837907a9bde90426b1baa4826c19b24a13251e31165ab9278fe5ea0acb
|
Provenance
The following attestation bundles were made for poolguy-0.1.8-py3-none-any.whl:
Publisher:
python-publish.yml on s4w3d0ff/pool-guy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
poolguy-0.1.8-py3-none-any.whl -
Subject digest:
0e599e3d255b356ea227608506f3dd12b53d9a801011dd11d0cf004bf2f9fcc2 - Sigstore transparency entry: 191759257
- Sigstore integration time:
-
Permalink:
s4w3d0ff/pool-guy@48b59ae598f063e673cc3d2b64e6774125c90fa5 -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/s4w3d0ff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@48b59ae598f063e673cc3d2b64e6774125c90fa5 -
Trigger Event:
release
-
Statement type: