Add EuphApi.Utils.Listing module
This commit is contained in:
parent
b72d662566
commit
7e0c5f82da
6 changed files with 127 additions and 12 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import Control.Monad
|
||||
import Data.Monoid
|
||||
import System.Environment
|
||||
import System.IO
|
||||
|
||||
import qualified System.Log.Formatter as LF
|
||||
|
|
@ -11,8 +12,12 @@ import qualified System.Log.Logger as L
|
|||
|
||||
import qualified EuphApi as E
|
||||
|
||||
type Bot = E.Bot () ()
|
||||
type Command = E.Command () ()
|
||||
type BotSpecific = ()
|
||||
type ConnectionSpecific = ()
|
||||
type Bot = E.Bot BotSpecific ConnectionSpecific
|
||||
type Config = E.BotConfig BotSpecific ConnectionSpecific
|
||||
type Command = E.Command BotSpecific ConnectionSpecific
|
||||
|
||||
|
||||
myCommands :: [Command]
|
||||
myCommands =
|
||||
|
|
@ -27,13 +32,13 @@ myCommands =
|
|||
]
|
||||
|
||||
myBotHandler :: E.EventType -> Bot ()
|
||||
myBotHandler (E.EuphEvent (E.SendEvent msg)) = E.runCommands myCommands msg
|
||||
myBotHandler _ = return ()
|
||||
myBotHandler (E.EuphEvent e) = E.autorunCommands myCommands e
|
||||
myBotHandler _ = return ()
|
||||
|
||||
myBotConfig :: E.BotConfig () ()
|
||||
myBotConfig = E.BotConfig
|
||||
myBotConfig :: String -> Config
|
||||
myBotConfig room = E.BotConfig
|
||||
{ E.botAddress = "euphoria.io"
|
||||
, E.botRoom = "test"
|
||||
, E.botRoom = room
|
||||
, E.botPassword = Nothing
|
||||
, E.botNick = "EuphApi test bot"
|
||||
, E.botHandler = myBotHandler
|
||||
|
|
@ -43,9 +48,19 @@ myBotConfig = E.BotConfig
|
|||
}
|
||||
|
||||
main = do
|
||||
-- Set up logging with custom message style
|
||||
myHandler <- LH.verboseStreamHandler stdout L.INFO
|
||||
let myFormatter = LF.simpleLogFormatter "<$time> [$loggername/$prio] $msg"
|
||||
myFormattedHandler = LH.setFormatter myHandler myFormatter
|
||||
L.updateGlobalLogger L.rootLoggerName (L.setHandlers [myFormattedHandler])
|
||||
L.updateGlobalLogger L.rootLoggerName (L.setLevel L.INFO)
|
||||
E.runBot (return myBotConfig)
|
||||
|
||||
-- Use args to determine room and start the bot
|
||||
args <- getArgs
|
||||
case args of
|
||||
[room] -> E.runBot (return $ myBotConfig room)
|
||||
_ -> do
|
||||
name <- getProgName
|
||||
putStrLn " USAGE:"
|
||||
putStr name
|
||||
putStrLn " <room>"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue