2022-06-16 09:53:26 +09:00
|
|
|
## Hacking
|
|
|
|
|
2022-07-24 19:18:19 +09:00
|
|
|
By default anonstream has two private APIs it exposes through two UNIX
|
|
|
|
sockets: the control socket `control.sock` and the event socket
|
|
|
|
`event.sock`. If the platform you are on does not support UNIX sockets,
|
|
|
|
they can be disabled in the config.
|
2022-06-16 09:53:26 +09:00
|
|
|
|
|
|
|
### Control socket
|
|
|
|
|
|
|
|
The control socket allows reading and modifying internal state, e.g.
|
|
|
|
setting the title or changing a user's name. Currently the control
|
2022-07-24 19:18:19 +09:00
|
|
|
socket has checks to see if what you're doing is sane, but they're non-
|
2022-06-16 09:53:26 +09:00
|
|
|
comprehensive; you could craft commands that lead to undefined
|
|
|
|
behaviour. If you have `socat`, you can use the control socket
|
|
|
|
interactively like this:
|
|
|
|
```sh
|
2022-07-24 19:18:19 +09:00
|
|
|
socat READLINE UNIX-CONNECT:control.sock
|
2022-06-16 09:53:26 +09:00
|
|
|
```
|
2022-07-24 19:18:19 +09:00
|
|
|
If you have it, you can use `rlwrap` to get line editing that's a bit
|
|
|
|
nicer:
|
2022-06-16 09:53:26 +09:00
|
|
|
```sh
|
2022-07-24 19:18:19 +09:00
|
|
|
rlwrap socat STDIN UNIX-CONNECT:control.sock
|
2022-06-16 09:53:26 +09:00
|
|
|
```
|
|
|
|
Once connected, type "help" and press enter to get a list of commands.
|
|
|
|
|
|
|
|
### Event socket
|
|
|
|
|
|
|
|
The event socket is a read-only socket that sends out internal events as
|
|
|
|
they happen. Currently the only supported event is a chat message being
|
|
|
|
added. The intended use is to hook into other applications that depend
|
2022-07-24 19:18:19 +09:00
|
|
|
on chat, e.g. text-to-speech or Twitch Plays Pokémon.
|
2022-06-16 09:53:26 +09:00
|
|
|
|
|
|
|
View events like this:
|
|
|
|
```sh
|
2022-06-26 13:12:32 +09:00
|
|
|
socat -u UNIX-CONNECT:event.sock STDOUT
|
2022-06-16 09:53:26 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
#### Examples
|
|
|
|
|
|
|
|
If you have `jq` you can view prettified events like this:
|
|
|
|
```sh
|
2022-06-26 13:12:32 +09:00
|
|
|
socat -u UNIX-CONNECT:event.sock STDOUT | jq
|
2022-06-16 09:53:26 +09:00
|
|
|
```
|
|
|
|
(On older versions of `jq` you have to say `jq .` when reading from
|
|
|
|
stdin.)
|
|
|
|
|
|
|
|
Use this to get each new chat message on a new line:
|
|
|
|
```sh
|
2022-06-26 13:12:32 +09:00
|
|
|
socat -u UNIX-CONNECT:event.sock STDOUT | jq 'select(.type == "message") | .event.nomarkup'
|
2022-06-16 09:53:26 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
##### Text-to-speech
|
|
|
|
|
|
|
|
This command will take each new chat message with the prefix "!say ",
|
|
|
|
strip the prefix, and synthesize the rest of the message as speech using
|
|
|
|
`espeak`:
|
|
|
|
```sh
|
2022-06-26 13:12:32 +09:00
|
|
|
socat -u UNIX-CONNECT:event.sock STDOUT \
|
2022-06-16 09:53:26 +09:00
|
|
|
| jq --unbuffered 'select(.type == "message") | .event.nomarkup' \
|
|
|
|
| grep -E --line-buffered '^"!say ' \
|
|
|
|
| sed -Eu 's/^"!say /"/' \
|
|
|
|
| jq -r --unbuffered \
|
|
|
|
| espeak
|
|
|
|
```
|