Debian Codegraph @

src/Lambdabot/Plugin/Novelty/Elite.hs

raw
1 -- (c) Josef Svenningsson, 2005
2 -- Licence: No licence, public domain
3
4 -- Inspired by the following page:
5 -- http://www.microsoft.com/athome/security/children/kidtalk.mspx
6 module Lambdabot.Plugin.Novelty.Elite (elitePlugin) where
7
8 import Lambdabot.Plugin
9 import Lambdabot.Util
10
11 import Control.Arrow
12 import Control.Monad
13 import Data.Char
14 import Data.Maybe
15 import Text.Regex.TDFA
16
17 elitePlugin :: Module ()
18 elitePlugin = newModule
19 { moduleCmds = return
20 [ (command "elite")
21 { aliases = ["leet", "l33t", "1337"]
22 , help = say "elite <phrase>. Translate English to elitespeak"
23 , process = \args -> case words args of
24 [] -> say "Say again?"
25 wds -> do let instr = map toLower (unwords wds)
26 say =<< io (translateLine instr)
27 }
28 ]
29 }
30
31 translateLine :: String -> IO String
32 translateLine = fmap (dropWhile isSpace) . translate . (' ':)
33 -- extra space allows whole-word patterns to match at start
34
35 translate :: String -> IO String
36 translate [] = return []
37 translate str = do
38 let alts = [ (subst match',rest)
39 | (re, subst) <- ruleList
40 , mr <- maybeToList (matchM re str)
41 , null (mrBefore mr)
42 , let match' = mrMatch mr
43 rest = mrAfter mr
44 ]
45 (subst,rest) <- random alts
46 liftM (subst ++) (translate rest)
47
48 ruleList :: [(Regex, String -> String)]
49 ruleList = map (first makeRegex)
50 [ (".", id )
51 , (".", map toUpper )
52 , ("a", const "4" )
53 , ("b", const "8" )
54 , (" be ", const " b " )
55 , ("c", const "(" )
56 , ("ck", const "xx" )
57 , ("cks ", const "x " )
58 , ("cks ", const "x0rs " )
59 , ("cks ", const "x0rz " )
60 , (" cool ",const " kewl ")
61 , ("e", const "3" )
62 , ("elite", const "1337" )
63 , ("elite", const "leet" )
64 , ("f", const "ph" )
65 , (" for ", const " 4 " )
66 , ("g", const "9" )
67 , ("h", const "|-|" )
68 , ("k", const "x" )
69 , ("l", const "|" )
70 , ("l", const "1" )
71 , ("m", const "/\\/\\")
72 , ("o", const "0" )
73 , ("ph", const "f" )
74 , ("s", const "z" )
75 , ("s", const "$" )
76 , ("s", const "5" )
77 , ("s ", const "z0rz " )
78 , ("t", const "7" )
79 , ("t", const "+" )
80 , (" the ", const " teh " )
81 , (" to ", const " 2 " )
82 , (" to ", const " too " )
83 , (" to ", const " tu " )
84 , (" too ", const " to " )
85 , ("v", const "\\/" )
86 , ("w", const "\\/\\/")
87 , (" you ", const " u " )
88 , (" you ", const " yu " )
89 , (" you ", const " joo " )
90 , ("z", const "s" )
91 ]
92