working test program for the clooglebot
authorMart Lubbers <mart@martlubbers.net>
Sun, 5 Mar 2017 12:33:15 +0000 (13:33 +0100)
committerMart Lubbers <mart@martlubbers.net>
Sun, 5 Mar 2017 12:33:15 +0000 (13:33 +0100)
IRC.dcl
IRC.icl
README.md
test.icl

diff --git a/IRC.dcl b/IRC.dcl
index d476d72..337d6f9 100644 (file)
--- a/IRC.dcl
+++ b/IRC.dcl
@@ -1,5 +1,6 @@
 definition module IRC
 
 definition module IRC
 
+from Data.Either import :: Either
 from Data.Maybe import :: Maybe
 from StdOverloaded import class fromInt, class toInt, class toString
 
 from Data.Maybe import :: Maybe
 from StdOverloaded import class fromInt, class toInt, class toString
 
@@ -12,7 +13,7 @@ from StdOverloaded import class fromInt, class toInt, class toString
        | INFO (Maybe String)
        | INVITE String String
        | ISON [String]
        | INFO (Maybe String)
        | INVITE String String
        | ISON [String]
-       | JOIN [(String, Maybe String)]
+       | JOIN (Either () [(String, Maybe String)])
        | KICK String String (Maybe String)
        | KILL String String
        | LINKS (Maybe (Maybe String, String))
        | KICK String String (Maybe String)
        | KILL String String
        | LINKS (Maybe (Maybe String, String))
@@ -23,18 +24,18 @@ from StdOverloaded import class fromInt, class toInt, class toString
        | NAMES [String]
        | NICK String
        | NJOIN 
        | NAMES [String]
        | NICK String
        | NJOIN 
-       | NOTICE 
+       | NOTICE String String
        | OPER String String 
        | PART [String]
        | PASS String
        | PING [String]
        | PONG [String]
        | PRIVMSG String String
        | OPER String String 
        | PART [String]
        | PASS String
        | PING [String]
        | PONG [String]
        | PRIVMSG String String
-       | QUIT String
+       | QUIT (Maybe String)
        | REHASH 
        | RESTART 
        | SERVER 
        | REHASH 
        | RESTART 
        | SERVER 
-       | SERVICE 
+       | SERVICE String String String String
        | SERVLIST (Maybe (String, Maybe String))
        | SQUERY String String
        | SQUIRT 
        | SERVLIST (Maybe (String, Maybe String))
        | SQUERY String String
        | SQUIRT 
@@ -44,11 +45,11 @@ from StdOverloaded import class fromInt, class toInt, class toString
        | TIME (Maybe String)
        | TOPIC String (Maybe String)
        | TRACE (Maybe String)
        | TIME (Maybe String)
        | TOPIC String (Maybe String)
        | TRACE (Maybe String)
-       | USER String String String
+       | USER String Int String
        | USERHOST [String]
        | USERS (Maybe String)
        | VERSION (Maybe String)
        | USERHOST [String]
        | USERS (Maybe String)
        | VERSION (Maybe String)
-       | WALLOPS 
+       | WALLOPS String
        | WHO (Maybe String)
        | WHOIS (Maybe String) [String]
        | WHOWAS (Maybe String) [String]
        | WHO (Maybe String)
        | WHOIS (Maybe String) [String]
        | WHOWAS (Maybe String) [String]
diff --git a/IRC.icl b/IRC.icl
index 50a42e9..9b6b134 100644 (file)
--- a/IRC.icl
+++ b/IRC.icl
@@ -3,11 +3,68 @@ implementation module IRC
 import GenPrint
 import StdOverloaded
 import Data.Maybe
 import GenPrint
 import StdOverloaded
 import Data.Maybe
+import Data.Either
+import StdFunc
+import StdString
+from Text import class Text(..), instance Text String
 from StdMisc import undef
 
 from StdMisc import undef
 
-derive gPrint IRCCommands, IRCReplies, IRCErrors, (,), Maybe, ()
+derive gPrint IRCCommands, IRCReplies, IRCErrors, (,), Maybe, (), Either
+
+instance toString IRCCommands where
+       toString r = flip (+++) "\r\n" case r of
+       //ADMIN (Maybe String)
+       //AWAY String
+       //CONNECT String Int (Maybe String)
+       //DIE 
+       //ERROR String
+       //INFO (Maybe String)
+       //INVITE String String
+       //ISON [String]
+               JOIN chs = "JOIN " +++ either (const "0")
+                       (\c->join ", " [join " " [ch:maybeToList mkey]\\(ch, mkey)<-c]) chs
+       //KICK String String (Maybe String)
+       //KILL String String
+       //LINKS (Maybe (Maybe String, String))
+       //LIST [String]
+       //LUSERS (Maybe (String, Maybe String))
+       //MODE String
+       //MOTD (Maybe String)
+       //NAMES [String]
+               NICK n = join " " ["NICK", n]
+       //NJOIN 
+       //NOTICE String String
+       //OPER String String 
+       //PART [String]
+       //PASS String
+       //PING [String]
+       //PONG [String]
+               PRIVMSG dest msg = join " " ["PRIVMSG", dest, msg]
+               QUIT msg = join " " ["QUIT":maybeToList msg]
+       //REHASH 
+       //RESTART 
+       //SERVER 
+       //SERVICE String String String String
+       //SERVLIST (Maybe (String, Maybe String))
+       //SQUERY String String
+       //SQUIRT 
+       //SQUIT String String
+       //STATS (Maybe (String, Maybe String))
+       //SUMMON String (Maybe (String, Maybe String))
+       //TIME (Maybe String)
+       //TOPIC String (Maybe String)
+       //TRACE (Maybe String)
+               USER login mode rn = join " " ["USER", login, toString mode, "*", ":", rn]
+       //USERHOST [String]
+       //USERS (Maybe String)
+       //VERSION (Maybe String)
+       //WALLOPS String
+       //WHO (Maybe String)
+       //WHOIS (Maybe String) [String]
+       //WHOWAS (Maybe String) [String]
+               _ = printToString r
+
 
 
-instance toString IRCCommands where toString r = printToString r
 instance toString IRCReplies where toString r = printToString r
 instance toString IRCErrors where toString r = printToString r
 
 instance toString IRCReplies where toString r = printToString r
 instance toString IRCErrors where toString r = printToString r
 
index 71e6a11..f89cbf4 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,2 +1,7 @@
 # clean-irc
 IRC library for Clean
 # clean-irc
 IRC library for Clean
+
+## Test
+```
+make && ./test | nc irc.freenode.net 6667
+```
index d9498b4..da69fcd 100644 (file)
--- a/test.icl
+++ b/test.icl
@@ -1,5 +1,16 @@
 module test
 
 module test
 
+from Data.Func import $
+import Data.Either
+import Data.Maybe
+import StdEnv
 import IRC
 
 import IRC
 
-Start = "hi"
+Start :: [String]
+Start = map toString
+       [NICK "clooglebot"
+       ,USER "cloogle" 0 "Cloogle bot"
+       ,JOIN $ Right [("#cloogle", Nothing)]
+       ,PRIVMSG "#cloogle" "Hello world"
+       ,QUIT Nothing
+       ]