-- | GNU Talk Filters -- needs: http://www.hyperrealm.com/main.php?s=talkfilters -- Edward Kmett 2006 module Lambdabot.Plugin.Novelty.Filter (filterPlugin) where import Lambdabot.Plugin import Lambdabot.Util import Control.Applicative import Data.Maybe import System.Directory (findExecutable) import System.Process -- State consists of a map from filter name to executable path filterPlugin :: Module [(String, FilePath, String)] filterPlugin = newModule { moduleDefState = catMaybes <$> sequence [ do mbPath <- io (findExecutable name) return $! do path <- mbPath Just (name, path, descr) | (name, descr) <- filters ] , moduleCmds = do activeFilters <- readMS return [ (command name) { help = say descr , process = \s -> do case words s of [] -> say ("usage: " ++ name ++ " ") t -> ios80 (runFilter path (unwords t)) } | (name, path, descr) <- activeFilters ] } filters :: [(String, String)] filters = [ ("austro", "austro . Talk like Ahhhnold") , ("b1ff", "b1ff . B1ff of usenet yore") , ("brooklyn", "brooklyn . Yo") , ("chef", "chef . Bork bork bork") , ("cockney", "cockney . Londoner accent") , ("drawl", "drawl . Southern drawl") , ("dubya", "dubya . Presidential filter") , ("fudd", "fudd . Fudd, Elmer") , ("funetak", "funetak . Southern drawl") , ("jethro", "jethro . Now listen to a story 'bout a man named Jed...") , ("jive", "jive . Slap ma fro") , ("kraut", "kraut . German accent") , ("pansy", "pansy . Effeminate male") , ("pirate", "pirate . Talk like a pirate") , ("postmodern", "postmodern . Feminazi") , ("redneck", "redneck . Deep south") , ("valspeak", "valley . Like, ya know?") , ("warez", "warez . H4x0r") ] runFilter :: String -> String -> IO String runFilter f s = do out <- readProcess f [] s return $ result out where result [] = "Couldn't run the filter." result xs = unlines . filter (not . all (==' ')) . lines $ xs