{-# LANGUAGE DeriveDataTypeable, OverloadedStrings #-}
module Network.IRC.Bot.Commands where
import Control.Applicative
import Control.Monad
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.Data
import Data.Monoid ((<>))
import Network.IRC (Message(Message, msg_prefix, msg_command, msg_params), Command, Prefix(NickName))
import Network.IRC.Bot.BotMonad (BotMonad, askMessage, sendMessage)
type HostName = ByteString
cmd :: (Functor m, MonadPlus m, BotMonad m) => Command -> m ()
cmd :: Command -> m ()
cmd Command
cmdName =
do Command
command' <- Message -> Command
msg_command (Message -> Command) -> m Message -> m Command
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Message
forall (m :: * -> *). BotMonad m => m Message
askMessage
if Command
cmdName Command -> Command -> Bool
forall a. Eq a => a -> a -> Bool
== Command
command'
then () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else m ()
forall (m :: * -> *) a. MonadPlus m => m a
mzero
data Ping
= Ping HostName
deriving (Ping -> Ping -> Bool
(Ping -> Ping -> Bool) -> (Ping -> Ping -> Bool) -> Eq Ping
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ping -> Ping -> Bool
$c/= :: Ping -> Ping -> Bool
== :: Ping -> Ping -> Bool
$c== :: Ping -> Ping -> Bool
Eq, Eq Ping
Eq Ping
-> (Ping -> Ping -> Ordering)
-> (Ping -> Ping -> Bool)
-> (Ping -> Ping -> Bool)
-> (Ping -> Ping -> Bool)
-> (Ping -> Ping -> Bool)
-> (Ping -> Ping -> Ping)
-> (Ping -> Ping -> Ping)
-> Ord Ping
Ping -> Ping -> Bool
Ping -> Ping -> Ordering
Ping -> Ping -> Ping
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Ping -> Ping -> Ping
$cmin :: Ping -> Ping -> Ping
max :: Ping -> Ping -> Ping
$cmax :: Ping -> Ping -> Ping
>= :: Ping -> Ping -> Bool
$c>= :: Ping -> Ping -> Bool
> :: Ping -> Ping -> Bool
$c> :: Ping -> Ping -> Bool
<= :: Ping -> Ping -> Bool
$c<= :: Ping -> Ping -> Bool
< :: Ping -> Ping -> Bool
$c< :: Ping -> Ping -> Bool
compare :: Ping -> Ping -> Ordering
$ccompare :: Ping -> Ping -> Ordering
$cp1Ord :: Eq Ping
Ord, ReadPrec [Ping]
ReadPrec Ping
Int -> ReadS Ping
ReadS [Ping]
(Int -> ReadS Ping)
-> ReadS [Ping] -> ReadPrec Ping -> ReadPrec [Ping] -> Read Ping
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Ping]
$creadListPrec :: ReadPrec [Ping]
readPrec :: ReadPrec Ping
$creadPrec :: ReadPrec Ping
readList :: ReadS [Ping]
$creadList :: ReadS [Ping]
readsPrec :: Int -> ReadS Ping
$creadsPrec :: Int -> ReadS Ping
Read, Int -> Ping -> ShowS
[Ping] -> ShowS
Ping -> String
(Int -> Ping -> ShowS)
-> (Ping -> String) -> ([Ping] -> ShowS) -> Show Ping
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ping] -> ShowS
$cshowList :: [Ping] -> ShowS
show :: Ping -> String
$cshow :: Ping -> String
showsPrec :: Int -> Ping -> ShowS
$cshowsPrec :: Int -> Ping -> ShowS
Show, Typeable Ping
DataType
Constr
Typeable Ping
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ping -> c Ping)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ping)
-> (Ping -> Constr)
-> (Ping -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Ping))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ping))
-> ((forall b. Data b => b -> b) -> Ping -> Ping)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ping -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ping -> r)
-> (forall u. (forall d. Data d => d -> u) -> Ping -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Ping -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Ping -> m Ping)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ping -> m Ping)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ping -> m Ping)
-> Data Ping
Ping -> DataType
Ping -> Constr
(forall b. Data b => b -> b) -> Ping -> Ping
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ping -> c Ping
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ping
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Ping -> u
forall u. (forall d. Data d => d -> u) -> Ping -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ping -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ping -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Ping -> m Ping
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ping -> m Ping
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ping
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ping -> c Ping
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Ping)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ping)
$cPing :: Constr
$tPing :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Ping -> m Ping
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ping -> m Ping
gmapMp :: (forall d. Data d => d -> m d) -> Ping -> m Ping
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ping -> m Ping
gmapM :: (forall d. Data d => d -> m d) -> Ping -> m Ping
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Ping -> m Ping
gmapQi :: Int -> (forall d. Data d => d -> u) -> Ping -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Ping -> u
gmapQ :: (forall d. Data d => d -> u) -> Ping -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Ping -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ping -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ping -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ping -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ping -> r
gmapT :: (forall b. Data b => b -> b) -> Ping -> Ping
$cgmapT :: (forall b. Data b => b -> b) -> Ping -> Ping
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ping)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ping)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Ping)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Ping)
dataTypeOf :: Ping -> DataType
$cdataTypeOf :: Ping -> DataType
toConstr :: Ping -> Constr
$ctoConstr :: Ping -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ping
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ping
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ping -> c Ping
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ping -> c Ping
$cp1Data :: Typeable Ping
Data, Typeable)
ping :: (Functor m, MonadPlus m, BotMonad m) => m Ping
ping :: m Ping
ping =
do Command -> m ()
forall (m :: * -> *).
(Functor m, MonadPlus m, BotMonad m) =>
Command -> m ()
cmd Command
"PING"
[Command]
params <- Message -> [Command]
msg_params (Message -> [Command]) -> m Message -> m [Command]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Message
forall (m :: * -> *). BotMonad m => m Message
askMessage
case [Command]
params of
(Command
hostName:[Command]
_) -> Ping -> m Ping
forall (m :: * -> *) a. Monad m => a -> m a
return (Ping -> m Ping) -> Ping -> m Ping
forall a b. (a -> b) -> a -> b
$ Command -> Ping
Ping Command
hostName
[Command]
_ -> m Ping
forall (m :: * -> *) a. MonadPlus m => m a
mzero
data PrivMsg
= PrivMsg { PrivMsg -> Maybe Prefix
prefix :: (Maybe Prefix)
, PrivMsg -> [Command]
receivers :: [ByteString]
, PrivMsg -> Command
msg :: ByteString
}
deriving (PrivMsg -> PrivMsg -> Bool
(PrivMsg -> PrivMsg -> Bool)
-> (PrivMsg -> PrivMsg -> Bool) -> Eq PrivMsg
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrivMsg -> PrivMsg -> Bool
$c/= :: PrivMsg -> PrivMsg -> Bool
== :: PrivMsg -> PrivMsg -> Bool
$c== :: PrivMsg -> PrivMsg -> Bool
Eq, ReadPrec [PrivMsg]
ReadPrec PrivMsg
Int -> ReadS PrivMsg
ReadS [PrivMsg]
(Int -> ReadS PrivMsg)
-> ReadS [PrivMsg]
-> ReadPrec PrivMsg
-> ReadPrec [PrivMsg]
-> Read PrivMsg
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PrivMsg]
$creadListPrec :: ReadPrec [PrivMsg]
readPrec :: ReadPrec PrivMsg
$creadPrec :: ReadPrec PrivMsg
readList :: ReadS [PrivMsg]
$creadList :: ReadS [PrivMsg]
readsPrec :: Int -> ReadS PrivMsg
$creadsPrec :: Int -> ReadS PrivMsg
Read, Int -> PrivMsg -> ShowS
[PrivMsg] -> ShowS
PrivMsg -> String
(Int -> PrivMsg -> ShowS)
-> (PrivMsg -> String) -> ([PrivMsg] -> ShowS) -> Show PrivMsg
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrivMsg] -> ShowS
$cshowList :: [PrivMsg] -> ShowS
show :: PrivMsg -> String
$cshow :: PrivMsg -> String
showsPrec :: Int -> PrivMsg -> ShowS
$cshowsPrec :: Int -> PrivMsg -> ShowS
Show)
privMsg :: (Functor m, MonadPlus m, BotMonad m) => m PrivMsg
privMsg :: m PrivMsg
privMsg =
do Message
msg' <- m Message
forall (m :: * -> *). BotMonad m => m Message
askMessage
m PrivMsg -> (PrivMsg -> m PrivMsg) -> Maybe PrivMsg -> m PrivMsg
forall b a. b -> (a -> b) -> Maybe a -> b
maybe m PrivMsg
forall (m :: * -> *) a. MonadPlus m => m a
mzero PrivMsg -> m PrivMsg
forall (m :: * -> *) a. Monad m => a -> m a
return (Message -> Maybe PrivMsg
toPrivMsg Message
msg')
toPrivMsg :: Message -> Maybe PrivMsg
toPrivMsg :: Message -> Maybe PrivMsg
toPrivMsg Message
m =
let cmd' :: Command
cmd' = Message -> Command
msg_command Message
m
params :: [Command]
params = Message -> [Command]
msg_params Message
m
prefix' :: Maybe Prefix
prefix' = Message -> Maybe Prefix
msg_prefix Message
m
in case Command
cmd' of
Command
"PRIVMSG" -> PrivMsg -> Maybe PrivMsg
forall a. a -> Maybe a
Just (PrivMsg -> Maybe PrivMsg) -> PrivMsg -> Maybe PrivMsg
forall a b. (a -> b) -> a -> b
$ Maybe Prefix -> [Command] -> Command -> PrivMsg
PrivMsg Maybe Prefix
prefix' ([Command] -> [Command]
forall a. [a] -> [a]
init [Command]
params) ([Command] -> Command
forall a. [a] -> a
last [Command]
params)
Command
_ -> Maybe PrivMsg
forall a. Maybe a
Nothing
class ToMessage a where
toMessage :: a -> Message
sendCommand :: (ToMessage c, BotMonad m, Functor m) => c -> m ()
sendCommand :: c -> m ()
sendCommand c
c = Message -> m ()
forall (m :: * -> *). BotMonad m => Message -> m ()
sendMessage (c -> Message
forall a. ToMessage a => a -> Message
toMessage c
c)
data Pong
= Pong HostName
deriving (Pong -> Pong -> Bool
(Pong -> Pong -> Bool) -> (Pong -> Pong -> Bool) -> Eq Pong
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Pong -> Pong -> Bool
$c/= :: Pong -> Pong -> Bool
== :: Pong -> Pong -> Bool
$c== :: Pong -> Pong -> Bool
Eq, Eq Pong
Eq Pong
-> (Pong -> Pong -> Ordering)
-> (Pong -> Pong -> Bool)
-> (Pong -> Pong -> Bool)
-> (Pong -> Pong -> Bool)
-> (Pong -> Pong -> Bool)
-> (Pong -> Pong -> Pong)
-> (Pong -> Pong -> Pong)
-> Ord Pong
Pong -> Pong -> Bool
Pong -> Pong -> Ordering
Pong -> Pong -> Pong
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Pong -> Pong -> Pong
$cmin :: Pong -> Pong -> Pong
max :: Pong -> Pong -> Pong
$cmax :: Pong -> Pong -> Pong
>= :: Pong -> Pong -> Bool
$c>= :: Pong -> Pong -> Bool
> :: Pong -> Pong -> Bool
$c> :: Pong -> Pong -> Bool
<= :: Pong -> Pong -> Bool
$c<= :: Pong -> Pong -> Bool
< :: Pong -> Pong -> Bool
$c< :: Pong -> Pong -> Bool
compare :: Pong -> Pong -> Ordering
$ccompare :: Pong -> Pong -> Ordering
$cp1Ord :: Eq Pong
Ord, ReadPrec [Pong]
ReadPrec Pong
Int -> ReadS Pong
ReadS [Pong]
(Int -> ReadS Pong)
-> ReadS [Pong] -> ReadPrec Pong -> ReadPrec [Pong] -> Read Pong
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Pong]
$creadListPrec :: ReadPrec [Pong]
readPrec :: ReadPrec Pong
$creadPrec :: ReadPrec Pong
readList :: ReadS [Pong]
$creadList :: ReadS [Pong]
readsPrec :: Int -> ReadS Pong
$creadsPrec :: Int -> ReadS Pong
Read, Int -> Pong -> ShowS
[Pong] -> ShowS
Pong -> String
(Int -> Pong -> ShowS)
-> (Pong -> String) -> ([Pong] -> ShowS) -> Show Pong
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Pong] -> ShowS
$cshowList :: [Pong] -> ShowS
show :: Pong -> String
$cshow :: Pong -> String
showsPrec :: Int -> Pong -> ShowS
$cshowsPrec :: Int -> Pong -> ShowS
Show, Typeable Pong
DataType
Constr
Typeable Pong
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pong -> c Pong)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Pong)
-> (Pong -> Constr)
-> (Pong -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Pong))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pong))
-> ((forall b. Data b => b -> b) -> Pong -> Pong)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pong -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pong -> r)
-> (forall u. (forall d. Data d => d -> u) -> Pong -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Pong -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Pong -> m Pong)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pong -> m Pong)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pong -> m Pong)
-> Data Pong
Pong -> DataType
Pong -> Constr
(forall b. Data b => b -> b) -> Pong -> Pong
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pong -> c Pong
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Pong
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Pong -> u
forall u. (forall d. Data d => d -> u) -> Pong -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pong -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pong -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Pong -> m Pong
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pong -> m Pong
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Pong
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pong -> c Pong
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Pong)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pong)
$cPong :: Constr
$tPong :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Pong -> m Pong
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pong -> m Pong
gmapMp :: (forall d. Data d => d -> m d) -> Pong -> m Pong
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Pong -> m Pong
gmapM :: (forall d. Data d => d -> m d) -> Pong -> m Pong
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Pong -> m Pong
gmapQi :: Int -> (forall d. Data d => d -> u) -> Pong -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Pong -> u
gmapQ :: (forall d. Data d => d -> u) -> Pong -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Pong -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pong -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pong -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pong -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pong -> r
gmapT :: (forall b. Data b => b -> b) -> Pong -> Pong
$cgmapT :: (forall b. Data b => b -> b) -> Pong -> Pong
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pong)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pong)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Pong)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Pong)
dataTypeOf :: Pong -> DataType
$cdataTypeOf :: Pong -> DataType
toConstr :: Pong -> Constr
$ctoConstr :: Pong -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Pong
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Pong
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pong -> c Pong
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Pong -> c Pong
$cp1Data :: Typeable Pong
Data, Typeable)
instance ToMessage Pong where
toMessage :: Pong -> Message
toMessage (Pong Command
hostName) = Maybe Prefix -> Command -> [Command] -> Message
Message Maybe Prefix
forall a. Maybe a
Nothing Command
"PONG" [Command
hostName]
instance ToMessage PrivMsg where
toMessage :: PrivMsg -> Message
toMessage (PrivMsg Maybe Prefix
prefix' [Command]
receivers' Command
msg') = Maybe Prefix -> Command -> [Command] -> Message
Message Maybe Prefix
prefix' Command
"PRIVMSG" ([Command]
receivers' [Command] -> [Command] -> [Command]
forall a. Semigroup a => a -> a -> a
<> [Command
msg'])
data Notice
= Notice { Notice -> Maybe Prefix
noticePrefix :: (Maybe Prefix)
, Notice -> [Command]
noticeReceivers :: [ByteString]
, Notice -> Command
noticeMsg :: ByteString
}
deriving (Notice -> Notice -> Bool
(Notice -> Notice -> Bool)
-> (Notice -> Notice -> Bool) -> Eq Notice
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Notice -> Notice -> Bool
$c/= :: Notice -> Notice -> Bool
== :: Notice -> Notice -> Bool
$c== :: Notice -> Notice -> Bool
Eq, ReadPrec [Notice]
ReadPrec Notice
Int -> ReadS Notice
ReadS [Notice]
(Int -> ReadS Notice)
-> ReadS [Notice]
-> ReadPrec Notice
-> ReadPrec [Notice]
-> Read Notice
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Notice]
$creadListPrec :: ReadPrec [Notice]
readPrec :: ReadPrec Notice
$creadPrec :: ReadPrec Notice
readList :: ReadS [Notice]
$creadList :: ReadS [Notice]
readsPrec :: Int -> ReadS Notice
$creadsPrec :: Int -> ReadS Notice
Read, Int -> Notice -> ShowS
[Notice] -> ShowS
Notice -> String
(Int -> Notice -> ShowS)
-> (Notice -> String) -> ([Notice] -> ShowS) -> Show Notice
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Notice] -> ShowS
$cshowList :: [Notice] -> ShowS
show :: Notice -> String
$cshow :: Notice -> String
showsPrec :: Int -> Notice -> ShowS
$cshowsPrec :: Int -> Notice -> ShowS
Show)
instance ToMessage Notice where
toMessage :: Notice -> Message
toMessage (Notice Maybe Prefix
prefix' [Command]
receivers' Command
msg') = Maybe Prefix -> Command -> [Command] -> Message
Message Maybe Prefix
prefix' Command
"NOTICE" ([Command]
receivers' [Command] -> [Command] -> [Command]
forall a. Semigroup a => a -> a -> a
<> [Command
msg'])
askSenderNickName :: (BotMonad m) => m (Maybe ByteString)
askSenderNickName :: m (Maybe Command)
askSenderNickName =
do Message
msg' <- m Message
forall (m :: * -> *). BotMonad m => m Message
askMessage
case Message -> Maybe Prefix
msg_prefix Message
msg' of
(Just (NickName Command
nick Maybe Command
_ Maybe Command
_)) -> Maybe Command -> m (Maybe Command)
forall (m :: * -> *) a. Monad m => a -> m a
return (Command -> Maybe Command
forall a. a -> Maybe a
Just Command
nick)
Maybe Prefix
_ -> Maybe Command -> m (Maybe Command)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Command
forall a. Maybe a
Nothing
replyTo :: (BotMonad m) => m (Maybe ByteString)
replyTo :: m (Maybe Command)
replyTo =
do PrivMsg
priv <- m PrivMsg
forall (m :: * -> *).
(Functor m, MonadPlus m, BotMonad m) =>
m PrivMsg
privMsg
let receiver :: Command
receiver = [Command] -> Command
forall a. [a] -> a
head (PrivMsg -> [Command]
receivers PrivMsg
priv)
if (Command
"#" Command -> Command -> Bool
`B.isPrefixOf` Command
receiver)
then Maybe Command -> m (Maybe Command)
forall (m :: * -> *) a. Monad m => a -> m a
return (Command -> Maybe Command
forall a. a -> Maybe a
Just Command
receiver)
else m (Maybe Command)
forall (m :: * -> *). BotMonad m => m (Maybe Command)
askSenderNickName
askReceiver :: (Alternative m, BotMonad m) => m (Maybe ByteString)
askReceiver :: m (Maybe Command)
askReceiver =
do PrivMsg
priv <- m PrivMsg
forall (m :: * -> *).
(Functor m, MonadPlus m, BotMonad m) =>
m PrivMsg
privMsg
Maybe Command -> m (Maybe Command)
forall (m :: * -> *) a. Monad m => a -> m a
return (Command -> Maybe Command
forall a. a -> Maybe a
Just ([Command] -> Command
forall a. [a] -> a
head ([Command] -> Command) -> [Command] -> Command
forall a b. (a -> b) -> a -> b
$ PrivMsg -> [Command]
receivers PrivMsg
priv))
m (Maybe Command) -> m (Maybe Command) -> m (Maybe Command)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
do Maybe Command -> m (Maybe Command)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Command
forall a. Maybe a
Nothing