From: Camil Staps Date: Tue, 12 Sep 2017 21:10:07 +0000 (+0200) Subject: Several interface improvements X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=a07ec62a3f7932f70b34c5fe7fe5ec0fa92b283a;p=cloogle-irc.git Several interface improvements --- diff --git a/IRC.icl b/IRC.icl index d0a0098..266531a 100644 --- a/IRC.icl +++ b/IRC.icl @@ -132,7 +132,7 @@ instance toString IRCUser where toString m = m.irc_nick <+ maybe "" ((<+) "!") m.irc_user <+ maybe "" ((<+) "@") m.irc_host instance toString IRCCommand where - toString m = jon " " (gIRCPrint{|*|} m) +++ "\r\n" + toString m = jon " " (gIRCPrint{|*|} m) instance toString IRCReplies where toString r = printToString r instance toString IRCErrors where toString r = printToString r diff --git a/IRCBot.icl b/IRCBot.icl index 3b62090..3ea2f76 100644 --- a/IRCBot.icl +++ b/IRCBot.icl @@ -27,7 +27,7 @@ bot (host, port) start end state bot w | 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 @@ -59,7 +59,7 @@ process chan acc 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 diff --git a/cloogleirc.icl b/cloogleirc.icl index 3e89acc..1241b7b 100644 --- a/cloogleirc.icl +++ b/cloogleirc.icl @@ -56,7 +56,7 @@ shorten s w cloogle :: String *World -> (String, *World) cloogle data w -# (mer, w) = doHTTPRequestL +# (mer, w) = doHTTPRequestFollowRedirects { newHTTPRequest & req_path = "/api.php" , req_query = "?str=" + urlEncode data @@ -107,17 +107,18 @@ cloogle data 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 = [] @@ -125,7 +126,7 @@ Start w , 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" @@ -139,7 +140,7 @@ Start w | 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" @@ -151,9 +152,9 @@ Start w , "\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 @@ -182,7 +183,7 @@ Start w 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