diff --git a/Anna.hs b/Anna.hs index 9bc922b..3c17682 100644 --- a/Anna.hs +++ b/Anna.hs @@ -5,6 +5,7 @@ import Data.Char (isSpace) import qualified Data.Text as T import System.IO import System.Directory +import System.Process (readProcess) import Control.Monad import Control.Monad.IO.Class import qualified Network.Socket as N @@ -74,6 +75,7 @@ tokenDispatch (Just username) (Just chn) ts = if elem "PRIVMSG" ts "!tz" -> if "!tz" == last tokens then timezone chn username else timezone chn $ head $ tail tokens + "!eval" -> evalScheme chn $ join $ intersperse " " $ tail tokens "!rollcall" -> rollcall chn "!anna" -> anna chn _ -> return () @@ -131,6 +133,19 @@ timezone chn username = do else sendMessage chn $ username ++ " has not set their timezone. Use `echo '' > ~/.tz' to add your timezone." where sanitize = T.unpack . T.replace (T.pack "\n") T.empty . T.pack +evalScheme :: String -> String -> Net () +evalScheme chn form = do + liftIO $ putStrLn form + result <- liftIO $ (\s -> s ++ "\n") <$> readProcess "guile" ["-c", expr] "" + sendMessage chn result + where expr = "(use-modules (ice-9 sandbox) \ + \ (rnrs exceptions)) \ + \ (display (guard (ex (else 'error)) \ + \ (eval-in-sandbox (read (open-input-string \"" ++ form ++ "\")) \ + \ #:bindings all-pure-and-impure-bindings)))" + + + rollcall :: String -> Net () rollcall chn = sendMessage chn "Hello! I respond to !anna, !qotd, and !greets. My source code is available at https://git.tilde.town/opfez/anna2" anna = rollcall