Skip to content

Commit 6fa1497

Browse files
authored
Merge pull request #820 from tsoding/807
(#807) Initial %flip implementation
2 parents ca3611f + ffe4ba4 commit 6fa1497

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

HyperNerd.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ executable HyperNerd
108108
, Bot.Asciify
109109
, Free
110110
, OrgMode
111+
, Bot.Flip
111112

112113
-- LANGUAGE extensions used by modules in this package.
113114
other-extensions: OverloadedStrings

src/Bot/CustomCommand.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Bot.CustomCommand
1212
) where
1313

1414
import Bot.Expr
15+
import Bot.Flip
1516
import Bot.Replies
1617
import Command
1718
import Control.Monad
@@ -179,6 +180,8 @@ evalExpr vars (FunCallExpr "or" args) =
179180
fromMaybe "" $ listToMaybe $ dropWhile T.null $ map (evalExpr vars) args
180181
evalExpr vars (FunCallExpr "urlencode" args) =
181182
T.concat $ map (T.pack . URI.encode . T.unpack . evalExpr vars) args
183+
evalExpr vars (FunCallExpr "flip" args) =
184+
T.concat $ map (flipText . evalExpr vars) args
182185
evalExpr vars (FunCallExpr funame _) = fromMaybe "" $ M.lookup funame vars
183186

184187
expandVars :: M.Map T.Text T.Text -> [Expr] -> T.Text

src/Bot/Flip.hs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module Bot.Flip where
2+
3+
import qualified Data.Map as M
4+
import Data.Maybe
5+
import qualified Data.Text as T
6+
7+
-- https://github.com/doherty/Text-UpsideDown/blob/master/lib/Text/UpsideDown.pm
8+
-- http://www.fileformat.info/convert/text/upside-down-map.htm
9+
flipText :: T.Text -> T.Text
10+
flipText = T.map (\x -> fromMaybe x $ M.lookup x table) . T.reverse
11+
12+
table :: M.Map Char Char
13+
table =
14+
M.fromList
15+
[ ('\x0021', '\x00A1')
16+
, ('\x0022', '\x201E')
17+
, ('\x0026', '\x214B')
18+
, ('\x0027', '\x002C')
19+
, ('\x0028', '\x0029')
20+
, ('\x002E', '\x02D9')
21+
, ('\x0033', '\x0190')
22+
, ('\x0034', '\x152D')
23+
, ('\x0036', '\x0039')
24+
, ('\x0037', '\x2C62')
25+
, ('\x003B', '\x061B')
26+
, ('\x003C', '\x003E')
27+
, ('\x003F', '\x00BF')
28+
, ('\x0041', '\x2200')
29+
, ('\x0042', '\x10412')
30+
, ('\x0043', '\x2183')
31+
, ('\x0044', '\x25D6')
32+
, ('\x0045', '\x018E')
33+
, ('\x0046', '\x2132')
34+
, ('\x0047', '\x2141')
35+
, ('\x004A', '\x017F')
36+
, ('\x004B', '\x22CA')
37+
, ('\x004C', '\x2142')
38+
, ('\x004D', '\x0057')
39+
, ('\x004E', '\x1D0E')
40+
, ('\x0050', '\x0500')
41+
, ('\x0051', '\x038C')
42+
, ('\x0052', '\x1D1A')
43+
, ('\x0054', '\x22A5')
44+
, ('\x0055', '\x2229')
45+
, ('\x0056', '\x1D27')
46+
, ('\x0059', '\x2144')
47+
, ('\x005B', '\x005D')
48+
, ('\x005F', '\x203E')
49+
, ('\x0061', '\x0250')
50+
, ('\x0062', '\x0071')
51+
, ('\x0063', '\x0254')
52+
, ('\x0064', '\x0070')
53+
, ('\x0065', '\x01DD')
54+
, ('\x0066', '\x025F')
55+
, ('\x0067', '\x0183')
56+
, ('\x0068', '\x0265')
57+
, ('\x0069', '\x0131')
58+
, ('\x006A', '\x027E')
59+
, ('\x006B', '\x029E')
60+
, ('\x006C', '\x0283')
61+
, ('\x006D', '\x026F')
62+
, ('\x006E', '\x0075')
63+
, ('\x0072', '\x0279')
64+
, ('\x0074', '\x0287')
65+
, ('\x0076', '\x028C')
66+
, ('\x0077', '\x028D')
67+
, ('\x0079', '\x028E')
68+
, ('\x007B', '\x007D')
69+
, ('\x203F', '\x2040')
70+
, ('\x2045', '\x2046')
71+
, ('\x2234', '\x2235')
72+
]

0 commit comments

Comments
 (0)