From 5f607d8d31b62ff3671e44cb7f8a4dc1c675fa69 Mon Sep 17 00:00:00 2001 From: Nicholas Chambers Date: Thu, 22 Jun 2017 04:01:20 +0100 Subject: [PATCH] lambot has a syntax error nchambers@spectre:~/lambot$ lamb irc.lamb lamb: ParseError (LocPos (SrcPos {locFile = "", locAbs = 7924, locLine = 319, locCol = 1})) "unexpected input" CallStack (from HasCallStack): error, called at ./Interp.hs:528:29 in main:Interp nchambers@spectre:~/lambot$ --- irc.lamb | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/irc.lamb b/irc.lamb index 92568a9..9c62639 100644 --- a/irc.lamb +++ b/irc.lamb @@ -2,6 +2,7 @@ import("std/base64"). import("std/list"). import("std/str"). import("std/http"). +import("std/op"). import("config"). -- the lexical environment that $eval uses @@ -265,25 +266,28 @@ handleCommand(s, _, "366", _) -> s. -- End of NAMES list handleCommand(s, _, "CAP", ["*", "ACK", "sasl "]) -> do putstrln("Starting SASL handshake."); - fputstr(sock, "AUTHENTICATE PLAIN\r\n") + fputstr(sock, "AUTHENTICATE PLAIN\r\n"); + s end. handleCommand(s, _, "AUTHENTICATE", ["+"]) -> do auth = base64\base64_encode(config\NICK + "\0" + config\NICK + "\0" + config\PASS); - fputstr(sock, "AUTHENTICATE " + auth + "\r\n") + fputstr(sock, "AUTHENTICATE " + auth + "\r\n"); + s end. +registering_finished = false. + handleCommand(s, _, "903", _) -> do putstrln("SASL authentication successful."); fputstr(sock, "CAP END\r\n"); - fputstr(sock, "NICK " + config\NICK + "\r\n"); - fputstr(sock, "USER " + config\NICK + " 0 * :Lamb Da. Bot\r\n"); - joinChans() -> list\map(\chan -> fputstr(sock, "JOIN " + chan + "\r\n"), config\CHANS); - joinChans() + registering_finished = true; + s end. handleCommand(s, src, cmd, args) -> do - putstrln("Unhandled command: " + cmd + ", with args: " + repr(args) + " from " + src) + putstrln("Unhandled command: " + cmd + ", with args: " + repr(args) + " from " + src); + s end. handleLine(s, ":" :: line) -> do @@ -304,16 +308,26 @@ end. -- build our socket and connect to the server sock = sockopen(config\HOST, config\PORT). +-- SASL register loop +registerLoop(state) -> + if op\and(feof(sock) != true, finished_registering == false) then do + line = fgetline(state, line) + end + else false. + -- send introduction -if config\PASS == "" then do - fputstr(sock, "NICK " + config\NICK + "\r\n"); - fputstr(sock, "USER " + config\NICK + " 0 * :Lamb Da. Bot\r\n"); - joinChans() -> list\map(\chan -> fputstr(sock, "JOIN " + chan + "\r\n"), config\CHANS); - joinChans() -end -else do - fputstr(sock, "CAP REQ :sasl\r\n") -end. +if config\PASS != "" then + if config\SASL == true then + fputstr(sock, "CAP REQ :sasl\r\n") + loop(registerLoop, []) + else + fputstr(sock, "PASS " + config\PASS + "\r\n") +else (,). + +fputstr(sock, "NICK " + config\NICK + "\r\n"). +fputstr(sock, "USER " + config\NICK + " 0 * :Lamb Da. Bot\r\n"). +joinChans() -> list\map(\chan -> fputstr(sock, "JOIN " + chan + "\r\n"), config\CHANS). +joinChans(). -- loop receiving lines mainloop(state) ->