module Lambdabot.Compat.PackedNick
( PackedNick
, packNick
, unpackNick
) where
import Lambdabot.Nick
import qualified Data.ByteString.Char8 as BS
type PackedNick = BS.ByteString
upckStr :: String -> String -> Nick
upckStr def str | null ac = Nick def str
| otherwise = Nick bc (tail ac)
where (bc, ac) = break (==':') str
pckStr :: Nick -> String
pckStr nck = nTag nck ++ ':' : nName nck
packNick :: Nick -> BS.ByteString
packNick = BS.pack . pckStr
unpackNick :: BS.ByteString -> Nick
unpackNick = upckStr "freenode" . BS.unpack