parent
85cb92f1a0
commit
ab22760c49
@ -0,0 +1,8 @@ |
||||
module Network.IRC |
||||
( |
||||
module Network.IRC.Types, |
||||
module Network.IRC.Client |
||||
)where |
||||
|
||||
import Network.IRC.Types |
||||
import Network.IRC.Client |
@ -1,20 +1,20 @@ |
||||
module Network.IRC.Handlers (allMsgHandlerMakers) where |
||||
|
||||
import qualified Network.IRC.Handlers.Auth as Auth |
||||
import qualified Network.IRC.Handlers.Greet as Greet |
||||
import qualified Network.IRC.Handlers.MessageLogger as Logger |
||||
import qualified Network.IRC.Handlers.NickTracker as NickTracker |
||||
import qualified Network.IRC.Handlers.SongSearch as SongSearch |
||||
import qualified Network.IRC.Handlers.Tell as Tell |
||||
import Network.IRC.Handlers.Auth |
||||
import Network.IRC.Handlers.Greet |
||||
import Network.IRC.Handlers.MessageLogger |
||||
import Network.IRC.Handlers.NickTracker |
||||
import Network.IRC.Handlers.SongSearch |
||||
import Network.IRC.Handlers.Tell |
||||
|
||||
import Network.IRC.Types |
||||
|
||||
allMsgHandlerMakers :: [MsgHandlerMaker] |
||||
allMsgHandlerMakers = [ |
||||
Auth.mkMsgHandler |
||||
, Greet.mkMsgHandler |
||||
, Logger.mkMsgHandler |
||||
, NickTracker.mkMsgHandler |
||||
, SongSearch.mkMsgHandler |
||||
, Tell.mkMsgHandler |
||||
allMsgHandlerMakers = |
||||
[ authMsgHandlerMaker |
||||
, greetMsgHandlerMaker |
||||
, messageLoggerMsgHandlerMaker |
||||
, nickTrackerMsgHandlerMaker |
||||
, songSearchMsgHandlerMaker |
||||
, tellMsgHandlerMaker |
||||
] |
||||
|
@ -0,0 +1,53 @@ |
||||
{-# LANGUAGE TemplateHaskell #-} |
||||
|
||||
module Network.IRC.Handlers.NickTracker.Internal.Types where |
||||
|
||||
import ClassyPrelude |
||||
import Control.Concurrent.Lifted (Chan, writeChan) |
||||
import Data.Data (Data) |
||||
import Data.IxSet (IxSet, Indexable (..), ixSet, ixFun) |
||||
import Data.SafeCopy (base, deriveSafeCopy) |
||||
|
||||
import Network.IRC.Types |
||||
|
||||
newtype CanonicalNick = CanonicalNick { canonicalNickToText :: Text } |
||||
deriving (Eq, Ord, Show, Data, Typeable) |
||||
newtype LastSeenOn = LastSeenOn UTCTime deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
data NickTrack = NickTrack { |
||||
nick :: !Nick, |
||||
canonicalNick :: !CanonicalNick, |
||||
lastSeenOn :: !UTCTime, |
||||
lastMessageOn :: !UTCTime, |
||||
lastMessage :: !Text |
||||
} deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
instance Indexable NickTrack where |
||||
empty = ixSet [ ixFun $ (: []) . nick |
||||
, ixFun $ (: []) . canonicalNick |
||||
, ixFun $ (: []) . LastSeenOn . lastSeenOn ] |
||||
|
||||
newtype NickTracking = NickTracking { nickTracking :: IxSet NickTrack } |
||||
deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
$(deriveSafeCopy 0 'base ''CanonicalNick) |
||||
$(deriveSafeCopy 0 'base ''LastSeenOn) |
||||
$(deriveSafeCopy 0 'base ''NickTrack) |
||||
$(deriveSafeCopy 0 'base ''NickTracking) |
||||
|
||||
emptyNickTracking :: NickTracking |
||||
emptyNickTracking = NickTracking empty |
||||
|
||||
data NickTrackRequest = NickTrackRequest Nick (MVar (Maybe NickTrack)) deriving (Eq, Typeable) |
||||
|
||||
instance Event NickTrackRequest |
||||
|
||||
instance Show NickTrackRequest where |
||||
show (NickTrackRequest nick _) = "NickTrackRequest[" ++ unpack (nickToText nick) ++ "]" |
||||
|
||||
getCanonicalNick :: Chan SomeEvent -> Nick -> IO (Maybe CanonicalNick) |
||||
getCanonicalNick eventChan nick = do |
||||
reply <- newEmptyMVar |
||||
request <- toEvent $ NickTrackRequest nick reply |
||||
writeChan eventChan request |
||||
map (map canonicalNick) $ takeMVar reply |
@ -1,53 +1,9 @@ |
||||
{-# LANGUAGE TemplateHaskell #-} |
||||
|
||||
module Network.IRC.Handlers.NickTracker.Types where |
||||
|
||||
import ClassyPrelude |
||||
import Control.Concurrent.Lifted (Chan, writeChan) |
||||
import Data.Data (Data) |
||||
import Data.IxSet (IxSet, Indexable (..), ixSet, ixFun) |
||||
import Data.SafeCopy (base, deriveSafeCopy) |
||||
|
||||
import Network.IRC.Types |
||||
|
||||
newtype CanonicalNick = CanonicalNick { canonicalNickToText :: Text } |
||||
deriving (Eq, Ord, Show, Data, Typeable) |
||||
newtype LastSeenOn = LastSeenOn UTCTime deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
data NickTrack = NickTrack { |
||||
nick :: !Nick, |
||||
canonicalNick :: !CanonicalNick, |
||||
lastSeenOn :: !LastSeenOn, |
||||
lastMessageOn :: !UTCTime, |
||||
lastMessage :: !Text |
||||
} deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
instance Indexable NickTrack where |
||||
empty = ixSet [ ixFun $ (: []) . nick |
||||
, ixFun $ (: []) . canonicalNick |
||||
, ixFun $ (: []) . lastSeenOn ] |
||||
|
||||
newtype NickTracking = NickTracking { nickTracking :: IxSet NickTrack } |
||||
deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
$(deriveSafeCopy 0 'base ''CanonicalNick) |
||||
$(deriveSafeCopy 0 'base ''LastSeenOn) |
||||
$(deriveSafeCopy 0 'base ''NickTrack) |
||||
$(deriveSafeCopy 0 'base ''NickTracking) |
||||
|
||||
emptyNickTracking :: NickTracking |
||||
emptyNickTracking = NickTracking empty |
||||
|
||||
data NickTrackRequest = NickTrackRequest Nick (MVar (Maybe NickTrack)) deriving (Eq, Typeable) |
||||
|
||||
instance Event NickTrackRequest |
||||
|
||||
instance Show NickTrackRequest where |
||||
show (NickTrackRequest nick _) = "NickTrackRequest[" ++ unpack (nickToText nick) ++ "]" |
||||
|
||||
getCanonicalNick :: Chan SomeEvent -> Nick -> IO (Maybe CanonicalNick) |
||||
getCanonicalNick eventChan nick = do |
||||
reply <- newEmptyMVar |
||||
request <- toEvent $ NickTrackRequest nick reply |
||||
writeChan eventChan request |
||||
map (map canonicalNick) $ takeMVar reply |
||||
module Network.IRC.Handlers.NickTracker.Types |
||||
( |
||||
CanonicalNick (..) |
||||
, NickTrack (..) |
||||
, getCanonicalNick |
||||
) |
||||
where |
||||
|
||||
import Network.IRC.Handlers.NickTracker.Internal.Types |
||||
|
@ -0,0 +1,54 @@ |
||||
{-# LANGUAGE DeriveDataTypeable #-} |
||||
{-# LANGUAGE TemplateHaskell #-} |
||||
|
||||
module Network.IRC.Handlers.Tell.Internal.Types where |
||||
|
||||
import ClassyPrelude |
||||
import Control.Concurrent.Lifted (Chan, writeChan) |
||||
import Data.Data (Data) |
||||
import Data.IxSet (IxSet, Indexable (..), ixSet, ixFun) |
||||
import Data.SafeCopy (base, deriveSafeCopy) |
||||
|
||||
import Network.IRC.Handlers.NickTracker.Types |
||||
import Network.IRC.Types |
||||
|
||||
newtype TellId = TellId Int deriving (Eq, Ord, Show, Data, Typeable, Num) |
||||
data TellStatus = NewTell | DeliveredTell deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
data Tell = Tell { |
||||
tellId :: !TellId, |
||||
tellFromNick :: !Nick, |
||||
tellToNick :: !CanonicalNick, |
||||
tellTopic :: !(Maybe Text), |
||||
tellStatus :: !TellStatus, |
||||
tellCreatedOn :: !UTCTime, |
||||
tellDeliveredOn :: !(Maybe UTCTime), |
||||
tellContent :: !Text |
||||
} deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
instance Indexable Tell where |
||||
empty = ixSet [ ixFun $ (: []) . tellId |
||||
, ixFun $ (: []) . tellToNick |
||||
, ixFun $ (: []) . tellStatus ] |
||||
|
||||
data Tells = Tells { nextTellId :: TellId, tells :: IxSet Tell } |
||||
deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
$(deriveSafeCopy 0 'base ''TellId) |
||||
$(deriveSafeCopy 0 'base ''TellStatus) |
||||
$(deriveSafeCopy 0 'base ''Tell) |
||||
$(deriveSafeCopy 0 'base ''Tells) |
||||
|
||||
emptyTells :: Tells |
||||
emptyTells = Tells (TellId 1) empty |
||||
|
||||
data TellRequest = TellRequest User Text deriving (Eq, Typeable) |
||||
|
||||
instance Event TellRequest |
||||
|
||||
instance Show TellRequest where |
||||
show (TellRequest user tell) = |
||||
"TellRequest[" ++ unpack (nickToText (userNick user) ++ ": " ++ tell) ++ "]" |
||||
|
||||
sendTell :: Chan SomeEvent -> User -> Text -> IO () |
||||
sendTell eventChan user tell = toEvent (TellRequest user tell) >>= writeChan eventChan |
@ -1,54 +1,9 @@ |
||||
{-# LANGUAGE DeriveDataTypeable #-} |
||||
{-# LANGUAGE TemplateHaskell #-} |
||||
|
||||
module Network.IRC.Handlers.Tell.Types where |
||||
|
||||
import ClassyPrelude |
||||
import Control.Concurrent.Lifted (Chan, writeChan) |
||||
import Data.Data (Data) |
||||
import Data.IxSet (IxSet, Indexable (..), ixSet, ixFun) |
||||
import Data.SafeCopy (base, deriveSafeCopy) |
||||
|
||||
import Network.IRC.Handlers.NickTracker.Types |
||||
import Network.IRC.Types |
||||
|
||||
newtype TellId = TellId Int deriving (Eq, Ord, Show, Data, Typeable, Num) |
||||
data TellStatus = NewTell | DeliveredTell deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
data Tell = Tell { |
||||
tellId :: !TellId, |
||||
tellFromNick :: !Nick, |
||||
tellToNick :: !CanonicalNick, |
||||
tellTopic :: !(Maybe Text), |
||||
tellStatus :: !TellStatus, |
||||
tellCreatedOn :: !UTCTime, |
||||
tellDeliveredOn :: !(Maybe UTCTime), |
||||
tellContent :: !Text |
||||
} deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
instance Indexable Tell where |
||||
empty = ixSet [ ixFun $ (: []) . tellId |
||||
, ixFun $ (: []) . tellToNick |
||||
, ixFun $ (: []) . tellStatus ] |
||||
|
||||
data Tells = Tells { nextTellId :: TellId, tells :: IxSet Tell } |
||||
deriving (Eq, Ord, Show, Data, Typeable) |
||||
|
||||
$(deriveSafeCopy 0 'base ''TellId) |
||||
$(deriveSafeCopy 0 'base ''TellStatus) |
||||
$(deriveSafeCopy 0 'base ''Tell) |
||||
$(deriveSafeCopy 0 'base ''Tells) |
||||
|
||||
emptyTells :: Tells |
||||
emptyTells = Tells (TellId 1) empty |
||||
|
||||
data TellRequest = TellRequest User Text deriving (Eq, Typeable) |
||||
|
||||
instance Event TellRequest |
||||
|
||||
instance Show TellRequest where |
||||
show (TellRequest user tell) = |
||||
"TellRequest[" ++ unpack (nickToText (userNick user) ++ ": " ++ tell) ++ "]" |
||||
|
||||
sendTell :: Chan SomeEvent -> User -> Text -> IO () |
||||
sendTell eventChan user tell = toEvent (TellRequest user tell) >>= writeChan eventChan |
||||
module Network.IRC.Handlers.Tell.Types |
||||
( |
||||
TellId (..) |
||||
, TellStatus (..) |
||||
, Tell (..) |
||||
, sendTell |
||||
) where |
||||
|
||||
import Network.IRC.Handlers.Tell.Internal.Types |
||||
|
Loading…
Reference in new issue