add scheme evaluation
parent
be728dde67
commit
292c39cd9f
15
Anna.hs
15
Anna.hs
|
@ -5,6 +5,7 @@ import Data.Char (isSpace)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Directory
|
import System.Directory
|
||||||
|
import System.Process (readProcess)
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import qualified Network.Socket as N
|
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
|
"!tz" -> if "!tz" == last tokens
|
||||||
then timezone chn username
|
then timezone chn username
|
||||||
else timezone chn $ head $ tail tokens
|
else timezone chn $ head $ tail tokens
|
||||||
|
"!eval" -> evalScheme chn $ join $ intersperse " " $ tail tokens
|
||||||
"!rollcall" -> rollcall chn
|
"!rollcall" -> rollcall chn
|
||||||
"!anna" -> anna chn
|
"!anna" -> anna chn
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
|
@ -131,6 +133,19 @@ timezone chn username = do
|
||||||
else sendMessage chn $ username ++ " has not set their timezone. Use `echo '<timezone here>' > ~/.tz' to add your timezone."
|
else sendMessage chn $ username ++ " has not set their timezone. Use `echo '<timezone here>' > ~/.tz' to add your timezone."
|
||||||
where sanitize = T.unpack . T.replace (T.pack "\n") T.empty . T.pack
|
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 :: 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"
|
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
|
anna = rollcall
|
||||||
|
|
Loading…
Reference in New Issue