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 @@ ...@@ -5,6 +5,7 @@
- Connecting to multiple channels and listening them - Connecting to multiple channels and listening them
- Switching between channels - Switching between channels
- Quitting channels - Quitting channels
- Twitch Helix API
- **MACROS** - **MACROS**
## Macros ## Macros
...@@ -21,15 +22,21 @@ And then register with `Macros.macro` ...@@ -21,15 +22,21 @@ And then register with `Macros.macro`
def macro(*blabla): 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 ```py
def on_gnu(publisher, message): def on_gnu(handler, message):
lower_message = message.message.lower() lower_message = message.message.lower()
author = message.author author = message.author
if "linux" in lower_message and "gnu" not in lower_message: if "linux" in lower_message and "gnu" not in lower_message:
... ...
``` ```
Send with `publisher` Send with `handler.publisher`
```py ```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: ...@@ -26,7 +26,7 @@ class ChatInterface:
) )
self.channel = None self.channel = None
self.macros = Macros(pubpen) self.macros = Macros(pubpen, self.helix, loop)
self.pubpen.subscribe("message", self.macros.dispatch) self.pubpen.subscribe("message", self.macros.dispatch)
def __enter__(self): def __enter__(self):
......
...@@ -5,12 +5,14 @@ from chatat.twitch import Actions ...@@ -5,12 +5,14 @@ from chatat.twitch import Actions
class Macros: class Macros:
macros = defaultdict(list) macros = defaultdict(list)
def __init__(self, pubpen): def __init__(self, pubpen, helix, loop):
self.pubpen = pubpen self.publisher = pubpen
self.helix = helix
self.loop = loop
def dispatch(self, message): def dispatch(self, message):
for macro in self.macros[message.action]: for macro in self.macros[message.action]:
macro(self.pubpen, message) macro(self, message)
@classmethod @classmethod
def macro(cls, on_event): def macro(cls, on_event):
......
...@@ -3,8 +3,8 @@ from chatat.twitch import Actions ...@@ -3,8 +3,8 @@ from chatat.twitch import Actions
@Macros.macro(Actions.PRIVMSG) @Macros.macro(Actions.PRIVMSG)
def on_gnu(publisher, message): def on_gnu(handler, message):
lower_message = message.message.lower() lower_message = message.message.lower()
author = message.author author = message.author
if "linux" in lower_message and "gnu" not in lower_message: 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