nu_plugin_twitch 0.1.1

A Nu Shell plugin to interact with Twitch IRC and API, making scripting easier.
Documentation
const SOUNDS_DEFS = [(path self | path dirname) "play-sounds.toml"] | path join;
const SOUNDS_ROOT = [(path self | path dirname) "sounds"] | path join;

def sound-path [$sound: string] {
    let $sound_path = [$SOUNDS_ROOT $sound] | path join;

    if ($sound_path | path dirname) != $SOUNDS_ROOT {
        error make {
            msg: $"trying to escape ($SOUNDS_ROOT)",
            label: {
                text: "path here",
                span: (metadata $sound).span
            }
        }
    } else if not ($sound_path | path exists) {
        error make {
            msg: $"file not found ($sound_path)",
            label: {
                text: "path here",
                span: (metadata $sound).span
            }
        }
    } else {
        return $sound_path
    }
}

def play-sound [$sound: string] {
    sound meta (sound-path $sound) | sound play (sound-path $sound) -d $in.duration;
}

def main [channel: string] {
    let sounds = open $SOUNDS_DEFS | get sounds;
    twitch chat $channel | par-each {|msg|
        $sounds | par-each {|sound|
            if $msg.message =~ $sound.command {
                play-sound $sound.play
            }
        };
        $msg
    }
}