module Lambdabot.Plugin.Novelty.BF (bfPlugin) where
import Lambdabot.Config.Novelty
import Lambdabot.Plugin
import Lambdabot.Util.Process
import Data.Char
import Text.Regex.TDFA
bfPlugin :: Module ()
bfPlugin = newModule
{ moduleCmds = return
[ (command "bf")
{ help = say "bf <expr>. Evaluate a brainf*ck expression"
, process = \msg -> do
bf <- getConfig bfBinary
ios80 (run bf msg scrub)
}
]
}
scrub :: String -> String
scrub = unlines . take 6 . map (' ':) . filter (not.null) . map cleanit . lines
cleanit :: String -> String
cleanit s | s =~ terminated = "Terminated\n"
| otherwise = filter printable s
where terminated = "waitForProc"
printable x = 31 < ord x && ord x < 127