diff options
author | tv <tv@krebsco.de> | 2019-01-23 00:02:42 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2019-01-23 00:57:36 +0100 |
commit | d40815fd56bf1895af89b72b1171675a2e0ae5f7 (patch) | |
tree | 83b96a701f16b13915836c3a6c94463732a9f6d8 /src/Reaktor/Utils.hs | |
parent | a00da57346c195b1b15d1c6aca2891483901aae6 (diff) |
src: use more simple functionsv0.1.0
Diffstat (limited to 'src/Reaktor/Utils.hs')
-rw-r--r-- | src/Reaktor/Utils.hs | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/src/Reaktor/Utils.hs b/src/Reaktor/Utils.hs deleted file mode 100644 index a31cd15..0000000 --- a/src/Reaktor/Utils.hs +++ /dev/null @@ -1,37 +0,0 @@ -module Reaktor.Utils where - -import qualified Data.ByteString.Char8.Extended as BS -import Data.Char (chr) -import Data.Char (isDigit) -import Reaktor.Internal -import System.Random (getStdRandom, randomR) - - -nextNick :: Nickname -> Nickname -nextNick nick_ = nick' - where - splitNick s = - (prefix, maybe 0 fst (BS.readInt suffix)) - where - prefix = BS.take (BS.length s - BS.length suffix) s - suffix = BS.reverse . BS.takeWhile isDigit . BS.reverse $ s - (nickPrefix, nickSuffix) = splitNick nick_ - nick' = nickPrefix <> (BS.pack . show $ nickSuffix + 1) - - -randomNick :: IO Nickname -randomNick = do - h_chr <- getRandomChar nickhead - t_len <- getStdRandom (randomR (4,8)) :: IO Int - t_str <- mapM (const $ getRandomChar nicktail) [1..t_len] - return $ BS.pack (h_chr:t_str) - where - getRandomChar cs = (cs!!) <$> getStdRandom (randomR (0, length cs - 1)) - - nickhead = letters <> specials - nicktail = letters <> digits <> specials <> minus - - letters = map chr $ [0x41..0x5A] <> [0x61..0x7A] - digits = map chr $ [0x30..0x39] - specials = map chr $ [0x5B..0x60] <> [0x7B..0x7D] - minus = map chr $ [0x2D] |