Kaydet (Commit) 61962e8c authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

Helix API support for macros

üst 66f090ba
......@@ -5,6 +5,7 @@
- Connecting to multiple channels and listening them
- Switching between channels
- Quitting channels
- Twitch Helix API
- **MACROS**
## Macros
......@@ -21,15 +22,21 @@ And then register with `Macros.macro`
def macro(*blabla):
...
```
The macro takes `publisher` (for publishing actions) and `message` (a `chatat.twitch.Message` object that holds message / author etc.)
The macro takes `handler` (for accessing services) and `message` (a `chatat.twitch.Message` object that holds message / author etc.)
```py
def on_gnu(publisher, message):
def on_gnu(handler, message):
lower_message = message.message.lower()
author = message.author
if "linux" in lower_message and "gnu" not in lower_message:
...
```
Send with `publisher`
Send with `handler.publisher`
```py
publisher.publish("outgoing", f"{author} dude; not linux, GNU/Linux")
handler.publisher.publish("outgoing", f"{author} dude; not linux, GNU/Linux")
```
### Helix API
Current version supports usage of Twitch Helix API with a little wrapper.
```
await handler.helix.get(endpoint, **params) -> JSON Response
await handler.helix.get("streams", game_id=33214) -> {...}
```
......@@ -26,7 +26,7 @@ class ChatInterface:
)
self.channel = None
self.macros = Macros(pubpen)
self.macros = Macros(pubpen, self.helix, loop)
self.pubpen.subscribe("message", self.macros.dispatch)
def __enter__(self):
......
......@@ -5,12 +5,14 @@ from chatat.twitch import Actions
class Macros:
macros = defaultdict(list)
def __init__(self, pubpen):
self.pubpen = pubpen
def __init__(self, pubpen, helix, loop):
self.publisher = pubpen
self.helix = helix
self.loop = loop
def dispatch(self, message):
for macro in self.macros[message.action]:
macro(self.pubpen, message)
macro(self, message)
@classmethod
def macro(cls, on_event):
......
......@@ -3,8 +3,8 @@ from chatat.twitch import Actions
@Macros.macro(Actions.PRIVMSG)
def on_gnu(publisher, message):
def on_gnu(handler, message):
lower_message = message.message.lower()
author = message.author
if "linux" in lower_message and "gnu" not in lower_message:
publisher.publish("outgoing", f"{author} dude; not linux, GNU/Linux")
handler.publisher.publish("outgoing", f"{author} dude; not linux, GNU/Linux")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment