module Data.IRC.Event
(
Nick (..)
, Event (..)
, EventAt(..)
, GenericEvent(..)
, decompose
) where
import qualified Data.Time as Time
import qualified Data.Text as T
import Data.Typeable ( Typeable )
import Data.Data ( Data, Constr, toConstr )
data EventAt
= EventAt Time.UTCTime Event
| NoParse T.Text
deriving (Show, Eq, Ord, Typeable)
newtype Nick = Nick T.Text
deriving (Show, Eq, Ord, Typeable, Data)
data Event
= Join Nick T.Text
| Part Nick T.Text
| Quit Nick T.Text
| ReNick Nick Nick
| Talk Nick T.Text
| Notice Nick T.Text
| Act Nick T.Text
| Kick Nick Nick T.Text
| Mode Nick T.Text
| Log T.Text
| Topic T.Text
| Names T.Text
deriving (Show, Eq, Ord, Typeable, Data)
data GenericEvent
= GenericEvent Constr (Maybe Nick) [T.Text]
deriving (Show, Eq, Typeable)
decompose :: Event -> GenericEvent
decompose x = go x where
c = GenericEvent $ toConstr x
go (Join n t) = c (Just n) [t]
go (Part n t) = c (Just n) [t]
go (Quit n t) = c (Just n) [t]
go (Talk n t) = c (Just n) [t]
go (Notice n t) = c (Just n) [t]
go (Act n t) = c (Just n) [t]
go (Mode n t) = c (Just n) [t]
go (Log t) = c Nothing [t]
go (Topic t) = c Nothing [t]
go (Names t) = c Nothing [t]
go (ReNick n (Nick t)) = c (Just n) [t]
go (Kick a (Nick b) t) = c (Just a) [b,t]