Commit 663ea3d6 authored by Mart Lubbers's avatar Mart Lubbers

update

parent 000d2eb9
......@@ -31,12 +31,12 @@ instance toInt IRCReplies, IRCErrors
| KICK String String (Maybe String)
| KILL String String
| LINKS (Maybe (Maybe String, String))
| LIST [String]
| LIST (Maybe ([String], Maybe String))
| LUSERS (Maybe (String, Maybe String))
| MODE String
| MODE String String (Maybe String) (Maybe String) (Maybe String)
| MOTD (Maybe String)
| NAMES [String]
| NICK String
| NICK String (Maybe String)
| NJOIN
| NOTICE String String
| OPER String String
......@@ -44,7 +44,7 @@ instance toInt IRCReplies, IRCErrors
| PASS String
| PING String (Maybe String)
| PONG String (Maybe String)
| PRIVMSG String String
| PRIVMSG [String] String
| QUIT (Maybe String)
| REHASH
| RESTART
......@@ -59,7 +59,7 @@ instance toInt IRCReplies, IRCErrors
| TIME (Maybe String)
| TOPIC String (Maybe String)
| TRACE (Maybe String)
| USER String Int String
| USER String String String
| USERHOST [String]
| USERS (Maybe String)
| VERSION (Maybe String)
......
......@@ -122,6 +122,15 @@ pCommand2 s p q c = pCommand s >>| liftM2 c p q
pCommand3 :: String (Parser Char a) (Parser Char b) (Parser Char c) (a b c -> IRCCommand) -> Parser Char IRCCommand
pCommand3 s p q r c = pCommand s >>| liftM3 c p q r
pCommand4 :: String (Parser Char a) (Parser Char b) (Parser Char c) (Parser Char d) (a b c d -> IRCCommand) -> Parser Char IRCCommand
pCommand4 s p q r t c = pCommand s >>| liftM4 c p q r t
pCommand5 :: String (Parser Char a) (Parser Char b) (Parser Char c) (Parser Char d) (Parser Char e) (a b c d e -> IRCCommand) -> Parser Char IRCCommand
pCommand5 s p q r t u c = pCommand s >>| liftM5 c p q r t u
pMode :: Parser Char String
pMode = toString <$> pSome (pOneOf ['+','-','o','p','i','t','n','b','v','w','s'])
parseCommand :: Parser Char IRCCommand
parseCommand =
pCommand1 "ADMIN" (optional pMiddle) ADMIN
......@@ -135,8 +144,42 @@ parseCommand =
<|> pCommand1 "JOIN" (pSepBy (liftM2 tuple pMiddle $ optional pMiddle) pComma) JOIN
<|> pCommand3 "KICK" pMiddle pMiddle (optional pParam) KICK
<|> pCommand2 "KILL" pMiddle pParam KILL
<|> pCommand1 "LINKS" (optional (liftM2 tuple (optional pMiddle) pMiddle)) LINKS
//<|> pCommand "QUIT" (optional pParam))
<|> pCommand1 "LINKS" (optional $ liftM2 tuple (optional pMiddle) pMiddle) LINKS
<|> pCommand1 "LIST" (optional $ liftM2 tuple (pSepBy pMiddle pComma) $ optional pMiddle) LIST
<|> pCommand1 "LUSERS" (optional $ liftM2 tuple pMiddle $ optional pMiddle) LUSERS
<|> pCommand5 "MODE" pMiddle pMode (optional pMiddle) (optional pMiddle) (optional pMiddle) MODE
<|> pCommand1 "MOTD" (optional pMiddle) MOTD
<|> pCommand1 "NAMES" (pSepBy pMiddle pComma) NAMES
//NJOIN
//NOTICE String String
//OPER String String
//PART [String]
//PASS String
<|> pCommand2 "PING" pMiddle (optional pMiddle) PING
<|> pCommand2 "PONG" pMiddle (optional pMiddle) PONG
<|> pCommand2 "PRIVMSG" (pSepBy pMiddle pComma) pParam PRIVMSG
<|> pCommand1 "QUIT" (optional pParam) QUIT
//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)
<|> pCommand3 "USER" pMiddle pMiddle (pMiddle >>| pParam) USER
//USERHOST [String]
//USERS (Maybe String)
//VERSION (Maybe String)
//WALLOPS String
//WHO (Maybe String)
//WHOIS (Maybe String) [String]
//WHOWAS (Maybe String) [String]
instance toString IRCCommand where
toString r = flip (+++) "\r\n" case r of
......@@ -153,12 +196,12 @@ instance toString IRCCommand where
//KICK String String (Maybe String)
//KILL String String
//LINKS (Maybe (Maybe String, String))
//LIST [String]
//LIST (Maybe ([String], Maybe String))
//LUSERS (Maybe (String, Maybe String))
//MODE String
//MODE String String (Maybe String) (Maybe String) (Maybe String)
//MOTD (Maybe String)
//NAMES [String]
NICK n = jon " " ["NICK", n]
NICK n ms = jon " " ["NICK", n]
//NJOIN
//NOTICE String String
//OPER String String
......@@ -166,7 +209,7 @@ instance toString IRCCommand where
//PASS String
PING a mb = jon " " ["PING",a:maybeToList mb]
PONG a mb = jon " " ["PONG",a:maybeToList mb]
PRIVMSG dest msg = jon " " ["PRIVMSG", dest, ":"+++msg]
PRIVMSG dest msg = undef //jon " " ["PRIVMSG", dest, ":"+++msg]
QUIT msg = jon " " ["QUIT":maybeToList msg]
//REHASH
//RESTART
......@@ -181,7 +224,7 @@ instance toString IRCCommand where
//TIME (Maybe String)
//TOPIC String (Maybe String)
//TRACE (Maybe String)
USER login mode rn = jon " " ["USER", login, toString mode, "*", ":"+++rn]
USER login mode rn = jon " " ["USER", login, mode, "*", ":"+++rn]
//USERHOST [String]
//USERS (Maybe String)
//VERSION (Maybe String)
......
......@@ -5,3 +5,8 @@ IRC library for Clean
```
make && ./test | nc irc.freenode.net 6667
```
## Todo
- Implement more commands
- Check comma separated parses
- Make a bot interface
......@@ -29,8 +29,8 @@ import TCPIP
commands :: [String]
commands = map toString
[NICK "clooglebot"
,USER "cloogle" 0 "Cloogle bot"
[NICK "clooglebot" Nothing
,USER "cloogle" "0" "Cloogle bot"
,JOIN [("#cloogle", Nothing)]
]
......@@ -132,7 +132,7 @@ cloogle data w
# resp = fromOk mer
= case fromJSON $ fromString resp.HTTPResponse.rsp_data of
Nothing = ("couldn't parse json", w)
Just clr = ("Results for " + data + " -- https://cloogle.org/#" + urlEncode data + "\n" +
Just clr = ("Results for " + data + " -- https://cloogle.org/#" + replaceSubString "+" "%20" (urlEncode data) + "\n" +
processResults clr, w)
where
processResults :: Response -> String
......@@ -185,7 +185,7 @@ recv {sChannel,rChannel} w
= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)
msg :: (String -> IRCCommand)
msg = PRIVMSG "#cloogle"
msg = PRIVMSG ["#cloogle"]
process :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)
process io chan w
......
......@@ -8,9 +8,9 @@ import IRC
Start :: [String]
Start = map toString
[NICK "clooglebot"
,USER "cloogle" 0 "Cloogle bot"
[NICK "clooglebot" Nothing
,USER "cloogle" "0" "Cloogle bot"
,JOIN [("#cloogle", Nothing)]
,PRIVMSG "#cloogle" "Hello world"
,PRIVMSG ["#cloogle"] "Hello world"
,QUIT Nothing
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment