From: Mart Lubbers Date: Sun, 5 Mar 2017 12:33:15 +0000 (+0100) Subject: working test program for the clooglebot X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=a8fbb81c3108a913c6496553346037805157b9c0;p=cloogle-irc.git working test program for the clooglebot --- diff --git a/IRC.dcl b/IRC.dcl index d476d72..337d6f9 100644 --- a/IRC.dcl +++ b/IRC.dcl @@ -1,5 +1,6 @@ definition module IRC +from Data.Either import :: Either 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] - | JOIN [(String, Maybe String)] + | JOIN (Either () [(String, Maybe 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 - | NOTICE + | NOTICE String String | OPER String String | PART [String] | PASS String | PING [String] | PONG [String] | PRIVMSG String String - | QUIT String + | QUIT (Maybe String) | REHASH | RESTART | SERVER - | SERVICE + | SERVICE String String String String | 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) - | USER String String String + | USER String Int String | USERHOST [String] | USERS (Maybe String) | VERSION (Maybe String) - | WALLOPS + | WALLOPS String | WHO (Maybe String) | WHOIS (Maybe String) [String] | WHOWAS (Maybe String) [String] diff --git a/IRC.icl b/IRC.icl index 50a42e9..9b6b134 100644 --- a/IRC.icl +++ b/IRC.icl @@ -3,11 +3,68 @@ implementation module IRC 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 -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 diff --git a/README.md b/README.md index 71e6a11..f89cbf4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # clean-irc IRC library for Clean + +## Test +``` +make && ./test | nc irc.freenode.net 6667 +``` diff --git a/test.icl b/test.icl index d9498b4..da69fcd 100644 --- a/test.icl +++ b/test.icl @@ -1,5 +1,16 @@ module test +from Data.Func import $ +import Data.Either +import Data.Maybe +import StdEnv 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 + ]