1 implementation module IRCBot
3 from Data.Func import $
11 from Text import class Text(concat,split,join), instance Text String
12 import StdList, StdString
13 import TCPServer.Connection
15 bot :: (String, Int) [IRCMessage] [IRCMessage] .a (IRCMessage -> (.a -> *(*World -> *(Maybe [IRCMessage], .a, *World)))) !*World -> *(Maybe String, .a, !*World)
16 bot (host, port) start end state bot w = appSnd3 snd $ connect host port
18 & onConnect = onConnect
22 onConnect s w = (Just (concat (map toString start)), connectionResponse s, w)
23 onData d (acc, s) w = case split "\r\n" (acc +++ d) of
25 = case parseIRCMessage $ m +++ "\r\n" of
26 // Do something with the error
27 (Left err) = (Nothing, {connectionResponse ("", s) & stop=True}, w)// (Error $ "IRC Parsing error: " +++ join "\n" err, chan, state, w)
29 # acc = join "\r\n" [rest:xs]
30 # (mircc, s, w) = bot msg s w
31 | isNothing mircc = (Just (concat (map toString end)), {connectionResponse (acc, s) & stop=True}, w)
32 # tosendthis = concat (map toString (fromJust mircc))
33 # (tosend, cr, w) = onData "" (acc, s) w
34 = (Just (maybe tosendthis ((+++) tosendthis) tosend), cr, w)
35 [m] = (Nothing, connectionResponse (m, s), w)