Crates.io | nu_plugin_twitch |
lib.rs | nu_plugin_twitch |
version | 0.1.1 |
created_at | 2025-07-30 21:39:37.760953+00 |
updated_at | 2025-08-10 09:30:51.229706+00 |
description | A Nu Shell plugin to interact with Twitch IRC and API, making scripting easier. |
homepage | https://sr.ht/~larandar/nu_plugin_twitch/ |
repository | https://git.sr.ht/~larandar/nu_plugin_twitch |
max_upload_size | |
id | 1774106 |
size | 239,840 |
A Nu Shell plugin to interact with Twitch IRC and API, making scripting easier.
The justfile
is full of simple examples, as well as some more advanced in the /examples/*.nu
files.
Archiving a chat is available via the
just archive-chat {{CHANNEL}}
command.
# First start archiving the chat for later use
twitch chat Larandar | into sqlite examples/archive.db -t Larandar
# Now let's get the number of messages of each user per minutes
open examples/archive.db | get Larandar | select sender timestamp |
insert minutes { $in.timestamp | format date "%Y-%m-%d %H:%M:00.000%Z" } |
group-by --to-table sender minutes |
move items messages | update messages { length } |
sort-by count
twitch auth
command to authenticate and store a profileuser
, broadcast
, is-live
)title
)twitch cmd
pipeline framework
--consume
: remove message from the output stream--cooldown
: take a duration
and execute once per cooldown per user--cooldown-is-global
: use a global cooldownconst SOUNDS_ROOT = [(pwd) "sounds"] | path join | path expand;
twitch chat CHANNEL | # Play a loud sound with a very long global cooldown and cosume the message
twitch cmd --cooldown 1day --cooldown-is-global --consume "!pipe" {|$msg, $args|
let $sound = ([$SOUNDS_ROOT "loud_pipe.mp3"] | path join | path expand);
sound meta $sound | sound play $sound -d $in.duration
} | # Parse the `bruh~ TTS msg` (using nu_plugin_audio_hook and piper1-gpl)
twitch cmd --lock tts "bruh~" {|$msg, $args|
let $sound = [$SOUNDS_ROOT "_tmp_tts.wav"] | path join;
python3 -m piper -m en_US-lessac-medium -f $sound -- ($args | str join " ");
sound play ([$SOUNDS_ROOT "bruh.mp3"] | path join) -d 1sec;
sound play $sound -d 15sec;
} | # Parse the `!sound tuturu` to play the tuturu.mp3 with a 1min cooldown per user
twitch cmd --cooldown 1min "!sound" {|$msg, $args|
let $sound = [$SOUNDS $"($args | str join '_').mp3"] | path join
if ($sound | path parent) != $SOUNDS {
# WARN: May need to timeout the user for trying hacking you
$"ARA ARA @($msg.sender), you naughty boy!!" | twitch say CHANNEL
} else {
if ($sound | path exists) {
$"@($msg.sender) not a sound LUL" | twitch say CHANNEL
} else {
sound meta $sound | sound play $sound -d $in.duration
}
}
}
twitch cmd
pipeline from file/dbtwitch cmd
running .nu
script instead of closures