diff --git a/home-manager/roles/taskwarrior.nix b/home-manager/roles/taskwarrior.nix index f0555459..3a3961c5 100644 --- a/home-manager/roles/taskwarrior.nix +++ b/home-manager/roles/taskwarrior.nix @@ -35,6 +35,29 @@ ${pkgs.coreutils}/bin/tail -n 1 | ${pkgs.coreutils}/bin/tee >(${pkgs.netcat}/bin/nc 127.0.0.1 6545) ''; }; + "modify-done-habitica-points" = { + target = ".task/hooks/on-modify.habitica-points"; + executable = true; + source = "${pkgs.writeHaskellScript + { + name = "habitica-points"; + bins = [ pkgs.curl pkgs.jq pkgs.libnotify ]; + imports = [ "Data.Aeson" ]; + } '' + + data Task = Task { status :: Text } deriving (Generic, FromJSON) + + main = do + oldTask <- getLine + newTask <- getLine + let oldStatus = maybe "unknown" status (decode (encodeUtf8 oldTask)) + newStatus = maybe "unknown" status (decode (encodeUtf8 newTask)) + when (oldStatus /= "done" && newStatus == "completed") $ do + result :: String <- curl "-XPOST" "-H" "x-api-user: dbd97aba-8b6b-4649-9dd4-dad284333925" "-H" "x-api-key: ${pkgs.privateValue "" "habitica-token"}" "https://habitica.com/api/v3/tasks/6e95cccd-06e1-466c-b871-643dff31423c/score/up" |> jq "-c" ".data._tmp" |> captureTrim <&> decodeUtf8 + notify_send "Task Completed!" result + putTextLn oldTask + ''}/bin/habitica-points"; + }; }; programs.taskwarrior = { enable = true; @@ -69,3 +92,4 @@ ''; }; } + diff --git a/overlays/writeHaskellScript.nix b/overlays/writeHaskellScript.nix index c2c74e93..3205da9f 100644 --- a/overlays/writeHaskellScript.nix +++ b/overlays/writeHaskellScript.nix @@ -51,6 +51,8 @@ in libraries = builtins.attrValues pkgs.myHaskellScriptPackages; } '' {-# LANGUAGE DeriveDataTypeable #-} + {-# LANGUAGE DeriveGeneric #-} + {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE OverloadedStrings #-} diff --git a/private b/private index 12317ad7..102e6914 160000 --- a/private +++ b/private @@ -1 +1 @@ -Subproject commit 12317ad7803d716fc9b8b2e2c01a92774410b7e4 +Subproject commit 102e6914fbdfd3ea069bcce521a4142b2a995372