- | isNothing toSend = (io, chan, w)
- # (chan, w) = send (map toString $ fromJust toSend) chan w
- = process io chan w
-| indexOf "PING :" resp >= 0
- # cmd = rtrim $ subString (indexOf "PING :" resp + size "PING :") (size resp) resp
- #! io = io <<< (toString $ PONG cmd Nothing) <<< "\n"
- # (chan, w) = send [toString $ PONG cmd Nothing] chan w
- = process io chan w
-= process io chan w
-
-Start :: *World -> (String, *World)
-Start w = cloogle "Monad" w
-//Start :: *World -> *World
-//Start w
-//# (io, w) = stdio w
-//# (ip, w) = lookupIPAddress SERVER w
-//| isNothing ip = abort $ "DNS lookup for " +++ SERVER +++ " failed\n"
-//# (Just ip) = ip
-//# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w
-//| rpt == TR_Expired = abort $ "Connection to " +++ SERVER +++ " timed out\n"
-//| rpt == TR_NoSuccess = abort $ "Could not connect to " +++ SERVER +++ "\n"
-//# chan = fromJust chan
-//# (chan, w) = send commands chan w
-//# (io, chan, w) = process io chan w
-//# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w
-//# (_, w) = fclose io w
-//= closeChannel sChannel (closeRChannel rChannel w)
+*/
+
+Start :: *World -> (MaybeErrorString (), *World)
+Start w = bot ("irc.freenode.net", 6667) startup shutdown () process w
+ where
+ toPrefix c = {irc_prefix=Nothing,irc_command=Right c}
+ startup = map toPrefix
+ [NICK "clooglebot" Nothing
+ ,USER "cloogle" "0" "Cloogle bot"
+ ,JOIN [("#cloogle", Nothing)]]
+ shutdown = map toPrefix [QUIT (Just "Bye")]
+
+ process :: IRCMessage () *World -> (Maybe [IRCMessage], (), *World)
+ process im s w = case im.irc_command of
+ Left numr = (Just [], (), w)
+ Right cmd = case process` cmd w of
+ (Nothing, w) = (Nothing, (), w)
+ (Just cs, w) = (Just $ map toPrefix cs, (), w)
+
+ process` :: IRCCommand *World -> (Maybe [IRCCommand], *World)
+ process` (PRIVMSG t m) w = (Just $ if (startsWith "!" m)
+ (map (PRIVMSG t) $ realProcess $ split " " $ subString 1 (size m) m)
+ [], w)
+ process` (PING t mt) w = (Just [PONG t mt], w)
+ process` _ w = (Just [], w)
+
+ realProcess :: [String] -> [String]
+ realProcess ["help":xs] =
+ ["type !help cmd for command specific help"
+ ,"available commands: help"]
+ realProcess [c:_] = [join " " ["unknown cmd: ", c, ", type !help to get help"]]