{-# LANGUAGE OverloadedStrings #-}
module Irc.Cmd
( passCmd
, nickCmd
, userCmd
, operCmd
, modeCmd
, quitCmd
, joinCmd
, partCmd
, topicCmd
, namesCmd
, listCmd
, inviteCmd
, kickCmd
, privMsgCmd
, ctcpRequestCmd
, ctcpResponseCmd
, noticeCmd
, whoisCmd
, whowasCmd
, whoCmd
, pongCmd
, pingCmd
, capLsCmd
, capReqCmd
, capEndCmd
, authenticateCmd
, awayCmd
, helpCmd
, removeCmd
, knockCmd
, acceptCmd
, timeCmd
, adminCmd
, statsCmd
) where
import Data.Monoid
import Data.ByteString (ByteString)
import Data.Foldable (toList)
import qualified Data.ByteString.Char8 as B8
import Irc.Format
outgoingMsg :: RawIrcMsg
outgoingMsg = RawIrcMsg
{ msgTime = Nothing
, msgPrefix = Nothing
, msgCommand = ""
, msgParams = []
}
modeCmd ::
Identifier ->
[ByteString] ->
ByteString
modeCmd c modes = renderRawIrcMsg outgoingMsg
{ msgCommand = "MODE"
, msgParams = idBytes c : modes
}
kickCmd ::
Identifier ->
Identifier ->
ByteString ->
ByteString
kickCmd c nick msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "KICK"
, msgParams = [idBytes c, idBytes nick, msg]
}
removeCmd ::
Identifier ->
Identifier ->
ByteString ->
ByteString
removeCmd c nick msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "REMOVE"
, msgParams = [idBytes c, idBytes nick, msg]
}
joinCmd :: Identifier -> Maybe ByteString -> ByteString
joinCmd chan mbKeys = renderRawIrcMsg outgoingMsg
{ msgCommand = "JOIN"
, msgParams = [idBytes chan] <> toList mbKeys
}
partCmd ::
Identifier ->
ByteString ->
ByteString
partCmd chan msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "PART"
, msgParams = [idBytes chan,msg]
}
topicCmd ::
Identifier ->
ByteString ->
ByteString
topicCmd chan msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "TOPIC"
, msgParams = [idBytes chan,msg]
}
whoisCmd ::
Identifier ->
ByteString
whoisCmd user = renderRawIrcMsg outgoingMsg
{ msgCommand = "WHOIS"
, msgParams = [idBytes user]
}
whowasCmd ::
Identifier ->
ByteString
whowasCmd user = renderRawIrcMsg outgoingMsg
{ msgCommand = "WHOWAS"
, msgParams = [idBytes user]
}
nickCmd ::
Identifier ->
ByteString
nickCmd nick = renderRawIrcMsg outgoingMsg
{ msgCommand = "NICK"
, msgParams = [idBytes nick]
}
userCmd ::
ByteString ->
ByteString ->
ByteString
userCmd user realname = renderRawIrcMsg outgoingMsg
{ msgCommand = "USER"
, msgParams = [user,"0","*",realname]
}
pingCmd ::
ByteString ->
ByteString
pingCmd token = renderRawIrcMsg outgoingMsg
{ msgCommand = "PING"
, msgParams = [token]
}
pongCmd ::
ByteString ->
ByteString
pongCmd token = renderRawIrcMsg outgoingMsg
{ msgCommand = "PONG"
, msgParams = [token]
}
passCmd ::
ByteString ->
ByteString
passCmd password = renderRawIrcMsg outgoingMsg
{ msgCommand = "PASS"
, msgParams = [password]
}
capLsCmd :: ByteString
capLsCmd = renderRawIrcMsg outgoingMsg
{ msgCommand = "CAP"
, msgParams = ["LS"]
}
capReqCmd :: [ByteString] -> ByteString
capReqCmd caps = renderRawIrcMsg outgoingMsg
{ msgCommand = "CAP"
, msgParams = ["REQ",B8.unwords caps]
}
capEndCmd :: ByteString
capEndCmd = renderRawIrcMsg outgoingMsg
{ msgCommand = "CAP"
, msgParams = ["END"]
}
privMsgCmd ::
Identifier ->
ByteString ->
ByteString
privMsgCmd target msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "PRIVMSG"
, msgParams = [idBytes target,msg]
}
ctcpRequestCmd ::
Identifier ->
ByteString ->
ByteString ->
ByteString
ctcpRequestCmd target command params = renderRawIrcMsg outgoingMsg
{ msgCommand = "PRIVMSG"
, msgParams = [idBytes target, "\x01" <> command <> " " <> params <> "\x01"]
}
ctcpResponseCmd ::
Identifier ->
ByteString ->
ByteString ->
ByteString
ctcpResponseCmd target command params = renderRawIrcMsg outgoingMsg
{ msgCommand = "NOTICE"
, msgParams = [idBytes target, "\x01" <> command <> " " <> params <> "\x01"]
}
noticeCmd ::
Identifier ->
ByteString ->
ByteString
noticeCmd target msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "NOTICE"
, msgParams = [idBytes target,msg]
}
authenticateCmd ::
ByteString ->
ByteString
authenticateCmd msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "AUTHENTICATE"
, msgParams = [msg]
}
helpCmd ::
ByteString ->
ByteString
helpCmd msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "HELP"
, msgParams = [msg]
}
awayCmd ::
ByteString ->
ByteString
awayCmd msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "AWAY"
, msgParams = [msg]
}
quitCmd ::
ByteString ->
ByteString
quitCmd msg = renderRawIrcMsg outgoingMsg
{ msgCommand = "QUIT"
, msgParams = [msg]
}
listCmd ::
[Identifier] ->
ByteString
listCmd chans = renderRawIrcMsg outgoingMsg
{ msgCommand = "LIST"
, msgParams = [B8.intercalate "," (map idBytes chans)]
}
inviteCmd ::
Identifier ->
Identifier ->
ByteString
inviteCmd nick chan = renderRawIrcMsg outgoingMsg
{ msgCommand = "INVITE"
, msgParams = [idBytes nick,idBytes chan]
}
namesCmd ::
[Identifier] ->
ByteString
namesCmd chans = renderRawIrcMsg outgoingMsg
{ msgCommand = "NAMES"
, msgParams = if null chans
then []
else [B8.intercalate "," (map idBytes chans)]
}
operCmd ::
ByteString ->
ByteString ->
ByteString
operCmd name pass = renderRawIrcMsg outgoingMsg
{ msgCommand = "OPER"
, msgParams = [name,pass]
}
whoCmd ::
ByteString ->
ByteString
whoCmd mask = renderRawIrcMsg outgoingMsg
{ msgCommand = "WHO"
, msgParams = [mask]
}
knockCmd ::
Identifier ->
ByteString
knockCmd chan = renderRawIrcMsg outgoingMsg
{ msgCommand = "KNOCK"
, msgParams = [idBytes chan]
}
acceptCmd ::
ByteString ->
ByteString
acceptCmd nick = renderRawIrcMsg outgoingMsg
{ msgCommand = "ACCEPT"
, msgParams = [nick]
}
timeCmd ::
Maybe ByteString ->
ByteString
timeCmd server = renderRawIrcMsg outgoingMsg
{ msgCommand = "TIME"
, msgParams = toList server
}
adminCmd ::
Maybe ByteString ->
ByteString
adminCmd server = renderRawIrcMsg outgoingMsg
{ msgCommand = "ADMIN"
, msgParams = toList server
}
statsCmd ::
Char ->
Maybe ByteString ->
ByteString
statsCmd letter target = renderRawIrcMsg outgoingMsg
{ msgCommand = "STATS"
, msgParams = B8.singleton letter : toList target
}