| rpt == TR_NoSuccess
= (Just $ "Could not connect to " +++ host, state, w)
// Send startup commands
-# (merr, chan, w) = send (map toString start) (fromJust chan) w
+# (merr, chan, w) = send [toString s +++ "\r\n" \\ s <- start] (fromJust chan) w
| isError merr = (Just $ fromError merr, state, w)
//Start processing function
# (mer, chan, state, w) = process chan "" state bot w
# (mircc, state, w) = bot msg state w
| isNothing mircc = (Ok (), chan, state, w) // Bot asks to quit
//Possible send the commands
- # (merr, chan, w) = send (map toString $ fromJust mircc) chan w
+ # (merr, chan, w) = send [toString c +++ "\r\n" \\ c <- fromJust mircc] chan w
| isError merr = (Error $ fromError merr, chan, state, w)
//Recurse
= process chan acc state bot w
Start :: *World -> (Maybe String, *World)
Start w
-# ([arg0:args], w) = getCommandLine w
+# ([cmd:args], w) = getCommandLine w
# (io, w) = stdio w
-# io = io <<< "\n"
-# bs = parseCLI args
-//| isError bs = (Just $ "\n" +++ fromError bs +++ "\n", snd $ fclose io w)
+# bs = parseCLI cmd args
+| isError bs
+ # io = io <<< fromError bs <<< "\n"
+ = (Nothing, snd $ fclose io w)
# (Ok bs) = bs
# (merr, io, w) = bot (bs.bs_server, bs.bs_port) (startup bs) shutdown io (process bs.bs_strftime) w
-= (Nothing, w)//= (merr, snd $ fclose io w)
+= (merr, snd $ fclose io w)
where
- parseCLI :: [String] -> MaybeErrorString BotSettings
- parseCLI [] = Ok
+ parseCLI :: String [String] -> MaybeErrorString BotSettings
+ parseCLI _ [] = Ok
{ bs_nick = "clooglebot"
, bs_nickserv = Nothing
, bs_autojoin = []
, bs_server = "irc.freenode.net"
, bs_strftime = "%s"
}
- parseCLI [a:as]
+ parseCLI cmd [a:as]
| a == "-f" || a == "--strftime"
= arg1 "--strftime" as \a c->{c & bs_strftime=a}
| a == "-n" || a == "--nick"
| a == "-s" || a == "--server"
= arg1 "--server" as \a c->{c & bs_server=a}
| a == "-h" || a == "--help" = Error $ join "\n" $
- [ "Usage: cloogle [OPTS]"
+ [ "Usage: " + cmd + " [OPTS]"
, "Options:"
, "\t--strftime/-f FORMAT strftime format used in the output. default: %s\n"
, "\t--nick/-n NICKNAME Use the given nickname instead of clooglebot"
, "\t has to be escaped in most shells"
]
= Error $ "Unknown option: " +++ a
-
- arg1 name [] _ = Error $ name +++ " requires an argument"
- arg1 name [a:as] f = parseCLI as >>= Ok o f a
+ where
+ arg1 name [] _ = Error $ name +++ " requires an argument"
+ arg1 name [a:as] f = parseCLI cmd as >>= Ok o f a
nickserv pw = PRIVMSG (CSepList ["NickServ"]) $ "IDENTIFY " +++ pw
log :: String String IRCMessage (!*File, !*World) -> (!*File, !*World)
log strf pref m (io, w)
#! (t, w) = localTime w
- = (io <<< strfTime strf t <<< pref <<< toString m, w)
+ = (io <<< strfTime strf t <<< pref <<< toString m <<< "\n", w)
process` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)
process` (Just (Left user)) (PRIVMSG t m) w