1339
|
1 import Data.List
|
|
2 import Data.Char
|
|
3
|
|
4 standardURL = "http://esolangs.org/wiki/Main_Page"
|
|
5 standardMessage = "Welcome to the international hub for esoteric programming language design and deployment! For more information, check out our wiki: @. (For the other kind of esoterica, try #esoteric on irc.dal.net.)"
|
|
6
|
|
7 replace :: (Eq a) => [a] -> [a] -> [a] -> [a]
|
|
8 replace _ _ [] = []
|
|
9 replace old new (y:ys) =
|
|
10 case stripPrefix old (y:ys) of
|
|
11 Nothing -> y : replace old new ys
|
|
12 Just ys' -> new ++ replace old new ys'
|
|
13
|
|
14 applyGenTemplate :: String -> String -> String -> String -- nick url template -> result
|
|
15 applyGenTemplate nick url template = nick ++ ": " ++ replace "^" nick (replace "@" url template)
|
|
16
|
|
17 applyTemplate :: String -> String -> String -- nick template -> result
|
|
18 applyTemplate nick template = applyGenTemplate nick standardURL template
|
|
19
|
|
20
|
|
21
|
|
22 reversibles = "<([{}])>"
|
|
23
|
|
24 -- there is probably a better way to do this with guards or somesuch
|
|
25 reverseChar :: Char -> Maybe Int -> Char
|
|
26 reverseChar c Nothing = c
|
|
27 reverseChar c (Just a) = reversibles !! (length reversibles - 1 - a)
|
|
28
|
|
29 tidyReverse :: String -> String
|
|
30 tidyReverse [] = []
|
|
31 tidyReverse (c:cs) = (tidyReverse cs) ++ [reverseChar c (elemIndex c reversibles)]
|
|
32
|
|
33
|
|
34 makeWelcome :: (String -> String) -> String -> String -- filter nick -> result
|
|
35 makeWelcome f nick = applyTemplate nick (f standardMessage)
|
|
36
|
|
37
|
|
38 welcome = makeWelcome id
|
|
39 emoclew = makeWelcome tidyReverse
|
|
40 wELCOME = makeWelcome (map toUpper)
|
|
41 eMOCLEW = makeWelcome ((map toUpper) . tidyReverse)
|
|
42
|