Debian Codegraph @

src/Lambdabot/Plugin/Novelty/Filter.hs

raw
1 -- | GNU Talk Filters
2 -- needs: http://www.hyperrealm.com/main.php?s=talkfilters
3 -- Edward Kmett 2006
4
5 module Lambdabot.Plugin.Novelty.Filter (filterPlugin) where
6
7 import Lambdabot.Plugin
8 import Lambdabot.Util
9
10 import Control.Applicative
11 import Data.Maybe
12 import System.Directory (findExecutable)
13 import System.Process
14
15 -- State consists of a map from filter name to executable path
16
17 filterPlugin :: Module [(String, FilePath, String)]
18 filterPlugin = newModule
19 { moduleDefState = catMaybes <$> sequence
20 [ do
21 mbPath <- io (findExecutable name)
22 return $! do
23 path <- mbPath
24 Just (name, path, descr)
25 | (name, descr) <- filters
26 ]
27
28 , moduleCmds = do
29 activeFilters <- readMS
30 return
31 [ (command name)
32 { help = say descr
33 , process = \s -> do
34 case words s of
35 [] -> say ("usage: " ++ name ++ " <phrase>")
36 t -> ios80 (runFilter path (unwords t))
37 }
38 | (name, path, descr) <- activeFilters
39 ]
40 }
41
42 filters :: [(String, String)]
43 filters =
44 [ ("austro", "austro <phrase>. Talk like Ahhhnold")
45 , ("b1ff", "b1ff <phrase>. B1ff of usenet yore")
46 , ("brooklyn", "brooklyn <phrase>. Yo")
47 , ("chef", "chef <phrase>. Bork bork bork")
48 , ("cockney", "cockney <phrase>. Londoner accent")
49 , ("drawl", "drawl <phrase>. Southern drawl")
50 , ("dubya", "dubya <phrase>. Presidential filter")
51 , ("fudd", "fudd <phrase>. Fudd, Elmer")
52 , ("funetak", "funetak <phrase>. Southern drawl")
53 , ("jethro", "jethro <phrase>. Now listen to a story 'bout a man named Jed...")
54 , ("jive", "jive <phrase>. Slap ma fro")
55 , ("kraut", "kraut <phrase>. German accent")
56 , ("pansy", "pansy <phrase>. Effeminate male")
57 , ("pirate", "pirate <phrase>. Talk like a pirate")
58 , ("postmodern", "postmodern <phrase>. Feminazi")
59 , ("redneck", "redneck <phrase>. Deep south")
60 , ("valspeak", "valley <phrase>. Like, ya know?")
61 , ("warez", "warez <phrase>. H4x0r")
62 ]
63
64 runFilter :: String -> String -> IO String
65 runFilter f s = do
66 out <- readProcess f [] s
67 return $ result out
68 where result [] = "Couldn't run the filter."
69 result xs = unlines . filter (not . all (==' ')) . lines $ xs