Added explicit imports

master
Abhinav Sarkar 2014-05-21 11:20:53 +05:30
parent ced2f4b578
commit 5b83b531c5
6 changed files with 47 additions and 41 deletions

14
Main.hs
View File

@ -7,12 +7,12 @@ module Main (main) where
import qualified Data.Configurator as CF import qualified Data.Configurator as CF
import ClassyPrelude hiding (try, getArgs) import ClassyPrelude hiding (try, getArgs)
import Control.Concurrent.Lifted import Control.Concurrent.Lifted (myThreadId)
import Control.Exception.Lifted import Control.Exception.Lifted (try, throwTo, AsyncException (UserInterrupt))
import Data.Configurator.Types import Data.Configurator.Types (Configured (..), ConfigError (..), Value (List), KeyError (..))
import System.Environment import System.Environment (getArgs, getProgName)
import System.Exit import System.Exit (exitFailure)
import System.Posix.Signals import System.Posix.Signals (installHandler, sigINT, sigTERM, Handler (Catch))
import Network.IRC.Types import Network.IRC.Types
import Network.IRC.Client import Network.IRC.Client
@ -39,7 +39,7 @@ main = do
loadBotConfig :: String -> IO BotConfig loadBotConfig :: String -> IO BotConfig
loadBotConfig configFile = do loadBotConfig configFile = do
eCfg <- try $ CF.load [Required configFile] eCfg <- try $ CF.load [CF.Required configFile]
case eCfg of case eCfg of
Left (ParseError _ _) -> error "Error while loading config" Left (ParseError _ _) -> error "Error while loading config"
Right cfg -> do Right cfg -> do

View File

@ -10,13 +10,13 @@ import qualified Data.Text.Format as TF
import qualified Data.Text.Format.Params as TF import qualified Data.Text.Format.Params as TF
import ClassyPrelude import ClassyPrelude
import Control.Exception.Lifted import Control.Exception.Lifted (mask_, AsyncException (UserInterrupt))
import Control.Concurrent.Lifted import Control.Concurrent.Lifted (fork, Chan, newChan, readChan, writeChan, threadDelay)
import Control.Monad.Reader hiding (forM_, foldM) import Control.Monad.Reader (ask)
import Control.Monad.State hiding (forM_, foldM) import Control.Monad.State (get, put)
import Network import Network (PortID (PortNumber), connectTo, withSocketsDo)
import System.IO (hIsEOF, hSetBuffering, BufferMode(..)) import System.IO (hIsEOF, hSetBuffering, BufferMode(..))
import System.Timeout import System.Timeout (timeout)
import Network.IRC.Handlers import Network.IRC.Handlers
import Network.IRC.Protocol import Network.IRC.Protocol

View File

@ -9,11 +9,11 @@ import qualified Network.IRC.Handlers.MessageLogger as L
import qualified Network.IRC.Handlers.SongSearch as SS import qualified Network.IRC.Handlers.SongSearch as SS
import ClassyPrelude import ClassyPrelude
import Control.Concurrent.Lifted import Control.Concurrent.Lifted (Chan)
import Control.Monad.Reader.Class import Control.Monad.Reader (ask)
import Data.Convertible import Data.Convertible (convert)
import Data.Text (strip) import Data.Text (strip)
import Data.Time (addUTCTime) import Data.Time (addUTCTime)
import Network.IRC.Types import Network.IRC.Types

View File

@ -11,13 +11,13 @@ import qualified Data.Text.Format as TF
import qualified Data.Text.Format.Params as TF import qualified Data.Text.Format.Params as TF
import ClassyPrelude hiding (try, (</>), (<.>), FilePath, log) import ClassyPrelude hiding (try, (</>), (<.>), FilePath, log)
import Control.Concurrent.Lifted import Control.Concurrent.Lifted (Chan)
import Control.Exception.Lifted import Control.Exception.Lifted (mask_)
import Control.Monad.Reader import Control.Monad.Reader (ask)
import Data.Time (diffDays) import Data.Time (diffDays)
import System.Directory import System.Directory (createDirectoryIfMissing, getModificationTime, copyFile, removeFile)
import System.FilePath import System.FilePath (FilePath, (</>), (<.>))
import System.IO (openFile, IOMode(..), hSetBuffering, BufferMode(..)) import System.IO (openFile, IOMode(..), hSetBuffering, BufferMode(..))
import Network.IRC.Types import Network.IRC.Types

View File

@ -8,15 +8,15 @@ module Network.IRC.Handlers.SongSearch (mkMsgHandler) where
import qualified Data.Configurator as CF import qualified Data.Configurator as CF
import ClassyPrelude hiding (try) import ClassyPrelude hiding (try)
import Control.Concurrent.Lifted import Control.Concurrent.Lifted (Chan)
import Control.Exception.Lifted import Control.Exception.Lifted (try, evaluate)
import Control.Monad.Reader import Control.Monad.Reader (ask)
import Data.Aeson import Data.Aeson (FromJSON, parseJSON, Value (..), (.:))
import Data.Aeson.Types (emptyArray) import Data.Aeson.Types (emptyArray)
import Data.Text (strip) import Data.Text (strip)
import Network.Curl.Aeson import Network.Curl.Aeson (curlAesonGet, CurlAesonException)
import Network.HTTP.Base import Network.HTTP.Base (urlEncode)
import Network.IRC.Types import Network.IRC.Types

View File

@ -32,10 +32,12 @@ module Network.IRC.Types
where where
import ClassyPrelude import ClassyPrelude
import Control.Monad.Reader import Control.Monad.Reader (ReaderT, MonadReader, runReaderT)
import Control.Monad.State import Control.Monad.State (StateT, MonadState, execStateT)
import Data.Configurator.Types import Data.Configurator.Types (Config)
import Data.Typeable (cast) import Data.Typeable (cast)
-- IRC related
type Nick = Text type Nick = Text
type MsgHandlerName = Text type MsgHandlerName = Text
@ -76,6 +78,8 @@ data Command =
| NamesCmd | NamesCmd
deriving (Show, Eq) deriving (Show, Eq)
-- Internal events
class (Typeable e, Show e) => Event e where class (Typeable e, Show e) => Event e where
toEvent :: e -> IO SomeEvent toEvent :: e -> IO SomeEvent
toEvent e = SomeEvent <$> pure e <*> getCurrentTime toEvent e = SomeEvent <$> pure e <*> getCurrentTime
@ -86,12 +90,10 @@ class (Typeable e, Show e) => Event e where
return (ev, time) return (ev, time)
data SomeEvent = forall e. Event e => SomeEvent e UTCTime deriving (Typeable) data SomeEvent = forall e. Event e => SomeEvent e UTCTime deriving (Typeable)
instance Show SomeEvent where instance Show SomeEvent where
show (SomeEvent e time) = formatTime defaultTimeLocale "[%F %T] " time ++ show e show (SomeEvent e time) = formatTime defaultTimeLocale "[%F %T] " time ++ show e
data QuitEvent = QuitEvent deriving (Show, Typeable) data QuitEvent = QuitEvent deriving (Show, Typeable)
instance Event QuitEvent instance Event QuitEvent
data EventResponse = RespNothing data EventResponse = RespNothing
@ -100,6 +102,8 @@ data EventResponse = RespNothing
| RespCommand Command | RespCommand Command
deriving (Show) deriving (Show)
-- Bot
data BotConfig = BotConfig { server :: !Text data BotConfig = BotConfig { server :: !Text
, port :: !Int , port :: !Int
, channel :: !Text , channel :: !Text
@ -141,6 +145,8 @@ newtype IRC a = IRC { _runIRC :: StateT BotStatus (ReaderT Bot IO) a }
runIRC :: Bot -> BotStatus -> IRC a -> IO BotStatus runIRC :: Bot -> BotStatus -> IRC a -> IO BotStatus
runIRC bot botStatus = flip runReaderT bot . flip execStateT botStatus . _runIRC runIRC bot botStatus = flip runReaderT bot . flip execStateT botStatus . _runIRC
-- Message handlers
newtype MsgHandlerT a = MsgHandlerT { _runMsgHandler :: ReaderT BotConfig IO a } newtype MsgHandlerT a = MsgHandlerT { _runMsgHandler :: ReaderT BotConfig IO a }
deriving ( Functor deriving ( Functor
, Applicative , Applicative