diff --git a/packages/scripts/default.nix b/packages/scripts/default.nix index bfdd258..4fa80de 100644 --- a/packages/scripts/default.nix +++ b/packages/scripts/default.nix @@ -128,11 +128,7 @@ in rec { packages = [ pkgs.curl pkgs.gnused pkgs.pandoc pkgs.man ]; }; - playlist = wrapScript { - name = "pls"; - script = ./playlist.sh; - packages = [ pkgs.curl pkgs.jq ]; - }; + playlist = import ./pls.nix { inherit pkgs; }; favicon = wrapScript { packages = [ pkgs.imagemagick ]; diff --git a/packages/scripts/playlist.sh b/packages/scripts/playlist.sh deleted file mode 100755 index 240c74d..0000000 --- a/packages/scripts/playlist.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -send_irc() { - echo " - USER $USER $(hostname) tolmoon $USER - NICK musikkritiker - JOIN #the_playlist - PRIVMSG #the_playlist :$* - QUIT - " | nc irc.freenode.net 6667 >/dev/null -} - -good="what a banger -ooh i love this song -this is top notch stuff! -nice! -noice! -yesss! -cool song! -i like this -that just sounds awesome! -that's a good song! -👍" - -bad="how can anyone listen to this? -(╯°□°)╯ ┻━┻ -skip this! -next, please! i'm suffering! -that's just bad music -nope -that sucks! -👎" - -endpoint=prism.r:8001 - -case "$1" in - good|like|cool|nice|noice|top|yass|yes|+) - send_irc "$(echo "$good" | shuf -n1)" & - curl -sS -XPOST "$endpoint/good" - ;; - skip|next|bad|sucks|no|nope|flop|-) - send_irc "$(echo "$bad" | shuf -n1)" & - curl -sS -XPOST "$endpoint/skip" - ;; - *) - curl -sS -XGET "$endpoint/current" | jq - ;; -esac -wait diff --git a/packages/scripts/pls.nix b/packages/scripts/pls.nix new file mode 100755 index 0000000..22e8763 --- /dev/null +++ b/packages/scripts/pls.nix @@ -0,0 +1,61 @@ +{ pkgs }: +let + inherit (pkgs) lib; + + irc = { + host = "irc.hackint.org"; + port = 6697; + tls = true; + channel = "#the_playlist"; + nick = "musikkritiker"; + }; + + playlistAPI = "prism.r:8001"; + + sendIRC = pkgs.writers.writeDash "send-irc" '' + ${pkgs.nur.repos.mic92.untilport}/bin/untilport ${irc.host} ${toString irc.port} && \ + ${pkgs.nur.repos.mic92.irc-announce}/bin/irc-announce \ + ${irc.host} ${toString irc.port} ${irc.nick} ${lib.escapeShellArg irc.channel} ${toString (if irc.tls then 1 else 0)} \ + "$*" + ''; + + messages.good = [ + "what a banger" + "ooh i love this song" + "this is top notch stuff!" + "nice!" + "noice!" + "yesss!" + "cool song!" + "i like this" + "that just sounds awesome!" + "that's a good song!" + "👍" + ]; + messages.bad = [ + "how can anyone listen to this?" + "(╯°□°)╯ ┻━┻" + "skip this!" + "next, please! i'm suffering!" + "that's just bad music" + "nope" + "that sucks!" + "👎" + ]; +in +pkgs.writers.writeDashBin "pls" '' + case "$1" in + good|like|cool|nice|noice|top|yass|yes|+) + # ${sendIRC} "$(echo "${lib.concatStringsSep "\n" messages.good}" | shuf -n1)" & + ${pkgs.curl}/bin/curl -sS -XPOST "${playlistAPI}/good" + ;; + skip|next|bad|sucks|no|nope|flop|-) + # ${sendIRC} "$(echo "${lib.concatStringsSep "\n" messages.bad}" | shuf -n1)" & + ${pkgs.curl}/bin/curl -sS -XPOST "${playlistAPI}/skip" + ;; + *) + ${pkgs.curl}/bin/curl -sS -XGET "${playlistAPI}/current" | ${pkgs.jq}/bin/jq + ;; + esac + wait +''