module Irc.UserInfo
( UserInfo(..)
, renderUserInfo
, parseUserInfo
, uiNick
) where
import Data.Text (Text)
import qualified Data.Text as Text
import Irc.Identifier
import Data.Monoid ((<>))
import Control.Lens
data UserInfo = UserInfo
{ userNick :: !Identifier
, userName :: !Text
, userHost :: !Text
}
deriving (Read, Show)
uiNick :: Lens' UserInfo Identifier
uiNick f ui@UserInfo{userNick = n} = (\n' -> ui{userNick = n'}) <$> f n
renderUserInfo :: UserInfo -> Text
renderUserInfo (UserInfo a b c)
= idText a
<> (if Text.null b then "" else "!" <> b)
<> (if Text.null c then "" else "@" <> c)
parseUserInfo :: Text -> UserInfo
parseUserInfo x = UserInfo
{ userNick = mkId nick
, userName = Text.drop 1 user
, userHost = Text.drop 1 host
}
where
(nickuser,host) = Text.break (=='@') x
(nick,user) = Text.break (=='!') nickuser