{-# Language OverloadedStrings #-}
module Irc.Commands
( ircAway
, ircCapEnd
, ircCapLs
, ircCapReq
, ircInvite
, ircIson
, ircJoin
, ircKick
, ircLinks
, ircMode
, ircNick
, ircNotice
, ircPart
, ircPass
, ircPing
, ircPong
, ircPrivmsg
, ircQuit
, ircRemove
, ircStats
, ircTime
, ircTopic
, ircUser
, ircUserhost
, ircWho
, ircWhois
, ircWhowas
, ircZnc
, ircAuthenticate
, plainAuthenticationMode
, encodePlainAuthentication
) where
import Irc.RawIrcMsg
import Irc.Identifier
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Data.ByteString.Base64 as Enc
ircPrivmsg ::
Text ->
Text ->
RawIrcMsg
ircPrivmsg who msg = rawIrcMsg "PRIVMSG" [who, msg]
ircNotice ::
Text ->
Text ->
RawIrcMsg
ircNotice who msg = rawIrcMsg "NOTICE" [who, msg]
ircMode ::
Identifier ->
[Text] ->
RawIrcMsg
ircMode tgt params = rawIrcMsg "MODE" (idText tgt : params)
ircWhois ::
[Text] ->
RawIrcMsg
ircWhois = rawIrcMsg "WHOIS"
ircWho ::
[Text] ->
RawIrcMsg
ircWho = rawIrcMsg "WHO"
ircWhowas ::
[Text] ->
RawIrcMsg
ircWhowas = rawIrcMsg "WHOWAS"
ircNick ::
Text ->
RawIrcMsg
ircNick nick = rawIrcMsg "NICK" [nick]
ircPart ::
Identifier ->
Text ->
RawIrcMsg
ircPart chan msg
| Text.null msg = rawIrcMsg "PART" [idText chan]
| otherwise = rawIrcMsg "PART" [idText chan, msg]
ircJoin ::
Text ->
Maybe Text ->
RawIrcMsg
ircJoin chan (Just key) = rawIrcMsg "JOIN" [chan, key]
ircJoin chan Nothing = rawIrcMsg "JOIN" [chan]
ircInvite ::
Text ->
Identifier ->
RawIrcMsg
ircInvite nick channel = rawIrcMsg "INVITE" [nick, idText channel]
ircTopic ::
Identifier ->
Text ->
RawIrcMsg
ircTopic chan msg
| Text.null msg = rawIrcMsg "TOPIC" [idText chan]
| otherwise = rawIrcMsg "TOPIC" [idText chan, msg]
ircKick ::
Identifier ->
Text ->
Text ->
RawIrcMsg
ircKick chan who msg
| Text.null msg = rawIrcMsg "KICK" [idText chan, who]
| otherwise = rawIrcMsg "KICK" [idText chan, who, msg]
ircRemove ::
Identifier ->
Text ->
Text ->
RawIrcMsg
ircRemove chan who msg
| Text.null msg = rawIrcMsg "REMOVE" [idText chan, who]
| otherwise = rawIrcMsg "REMOVE" [idText chan, who, msg]
ircQuit :: Text -> RawIrcMsg
ircQuit msg
| Text.null msg = rawIrcMsg "QUIT" []
| otherwise = rawIrcMsg "QUIT" [msg]
ircPass :: Text -> RawIrcMsg
ircPass pass = rawIrcMsg "PASS" [pass]
ircPing ::
[Text] ->
RawIrcMsg
ircPing = rawIrcMsg "PING"
ircPong ::
[Text] ->
RawIrcMsg
ircPong = rawIrcMsg "PONG"
ircIson ::
[Text] ->
RawIrcMsg
ircIson nicks = rawIrcMsg "ISON" [Text.unwords nicks]
ircTime ::
[Text] ->
RawIrcMsg
ircTime = rawIrcMsg "TIME"
ircUserhost ::
[Text] ->
RawIrcMsg
ircUserhost = rawIrcMsg "USERHOST"
ircStats ::
[Text] ->
RawIrcMsg
ircStats = rawIrcMsg "STATS"
ircLinks ::
[Text] ->
RawIrcMsg
ircLinks = rawIrcMsg "LINKS"
ircAway ::
Text ->
RawIrcMsg
ircAway msg
| Text.null msg = rawIrcMsg "AWAY" []
| otherwise = rawIrcMsg "AWAY" [msg]
ircUser ::
Text ->
Bool ->
Bool ->
Text -> RawIrcMsg
ircUser user set_w set_i real = rawIrcMsg "USER" [user, modeTxt, "*", real]
where
modeTxt = Text.pack (show mode)
mode :: Int
mode = (if set_w then 4 else 0)
+ (if set_i then 8 else 0)
ircCapReq ::
[Text] ->
RawIrcMsg
ircCapReq caps = rawIrcMsg "CAP" ["REQ", Text.unwords caps]
ircCapEnd :: RawIrcMsg
ircCapEnd = rawIrcMsg "CAP" ["END"]
ircCapLs :: RawIrcMsg
ircCapLs = rawIrcMsg "CAP" ["LS"]
ircZnc ::
[Text] ->
RawIrcMsg
ircZnc = rawIrcMsg "ZNC"
ircAuthenticate :: Text -> RawIrcMsg
ircAuthenticate msg = rawIrcMsg "AUTHENTICATE" [msg]
plainAuthenticationMode :: Text
plainAuthenticationMode = "PLAIN"
encodePlainAuthentication ::
Text ->
Text ->
Text
encodePlainAuthentication user pass
= Text.decodeUtf8
$ Enc.encode
$ Text.encodeUtf8
$ Text.intercalate "\0" [user,user,pass]