Copyright | (c) Abhinav Sarkar, 2014 |
---|---|
License | Apache-2.0 |
Maintainer | abhinav@abhinavsarkar.net |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
- newtype Nick = Nick {
- nickToText :: Text
- data User
- = Self
- | User {
- userNick :: !Nick
- userServer :: !Text
- class (Typeable msg, Show msg, Eq msg, Ord msg) => MessageC msg where
- toMessage :: msg -> MessageW
- fromMessage :: MessageW -> Maybe msg
- data Message = Message {}
- data MessageW
- newMessage :: (MessageC msg, MonadIO m) => msg -> m Message
- data IdleMsg = IdleMsg
- data NickInUseMsg = NickInUseMsg
- data PingMsg = PingMsg !Text
- data PongMsg = PongMsg !Text
- data NamesMsg = NamesMsg ![Nick]
- data ChannelMsg = ChannelMsg !User !Text
- data PrivMsg = PrivMsg !User !Text
- data ActionMsg = ActionMsg !User !Text
- data JoinMsg = JoinMsg !User
- data QuitMsg = QuitMsg !User !Text
- data PartMsg = PartMsg !User !Text
- data NickMsg = NickMsg !User !Nick
- data KickMsg = KickMsg {
- kickUser :: !User
- kickedNick :: !Nick
- kickMsg :: !Text
- data ModeMsg = ModeMsg {
- modeUser :: !User
- modeTarget :: !Text
- mode :: !Text
- modeArgs :: ![Text]
- data WhoisReplyMsg
- = WhoisNoSuchNickMsg { }
- | WhoisNickInfoMsg {
- whoisNick :: !Nick
- whoisUser :: !Text
- whoisHost :: !Text
- whoisRealName :: !Text
- whoisChannels :: ![Text]
- whoisServer :: !Text
- whoisServerInfo :: !Text
- data OtherMsg = OtherMsg {
- msgSource :: !Text
- msgCommand :: !Text
- msgTarget :: !Text
- msg :: !Text
- data PingCmd = PingCmd !Text
- data PongCmd = PongCmd !Text
- data ChannelMsgReply = ChannelMsgReply !Text
- data PrivMsgReply = PrivMsgReply !User !Text
- data NickCmd = NickCmd
- data UserCmd = UserCmd
- data JoinCmd = JoinCmd
- data QuitCmd = QuitCmd
- data NamesCmd = NamesCmd
- data WhoisCmd = WhoisCmd !Text
- type MessageParserId = Text
- data MessagePart = MessagePart {
- msgPartTarget :: !Text
- msgPartTime :: !UTCTime
- msgPartLine :: !Text
- data MessageParseResult
- = ParseDone !Message ![MessagePart]
- | ParsePartial ![MessagePart]
- | ParseReject
- data MessageParser = MessageParser {
- msgParserId :: !MessageParserId
- msgParser :: !(BotConfig -> UTCTime -> Text -> [MessagePart] -> MessageParseResult)
- type CommandFormatter = BotConfig -> Message -> Maybe Text
- data BotConfig = BotConfig {
- botServer :: !Text
- botPort :: !Int
- botChannel :: !Text
- botOrigNick :: !Nick
- botNick :: !Nick
- botTimeout :: !Int
- msgHandlerInfo :: !(Map MsgHandlerName (Map Text Text))
- msgHandlerMakers :: !(Map MsgHandlerName MsgHandlerMaker)
- msgParsers :: ![MessageParser]
- cmdFormatters :: ![CommandFormatter]
- config :: !Configuration
- newBotConfig :: Text -> Int -> Text -> Nick -> Int -> BotConfig
- data Bot = Bot {
- botConfig :: !BotConfig
- botSocket :: !Handle
- msgHandlers :: !(Map MsgHandlerName MsgHandler)
- data BotStatus
- type MsgHandlerName = Text
- class (MonadIO m, Applicative m, MonadReader BotConfig m, MonadBase IO m) => MonadMsgHandler m
- data MsgHandler = MsgHandler {
- onMessage :: !(forall m. MonadMsgHandler m => Message -> m [Message])
- onStop :: !(forall m. MonadMsgHandler m => m ())
- handlerHelp :: !(forall m. MonadMsgHandler m => m (Map Text Text))
- newMsgHandler :: MsgHandler
- data MsgHandlerMaker = MsgHandlerMaker {
- msgHandlerName :: !MsgHandlerName
- msgHandlerMaker :: !(BotConfig -> MessageChannel Message -> IO MsgHandler)
- data MessageChannel a
- sendMessage :: MessageChannel a -> a -> IO ()
IRC Messages
An IRC nick.
Nick | |
|
An IRC user.
Self | The user for the bot itself. |
User | An user other than the bot. |
|
class (Typeable msg, Show msg, Eq msg, Ord msg) => MessageC msg where Source
The typeclass for different types of messages.
Nothing
An message sent from the server to the bot or from the bot to the server or from a handler to another handler.
A wrapper over all types of messages.
Creates a new message with the current time and the given message details.
The internal (non-IRC) message received when the bot is idle.
data NickInUseMsg Source
The message received when the bot's current nick is already in use.
A NAMES message which contains a list of nicks of all users in the channel.
A PRIVMSG private message sent to the bot from a user.
An PRIVMSG action message sent to the channel from a user.
A JOIN message received when a user joins the channel.
A QUIT message received when a user quits the server.
A PART message received when a user leaves the channel.
A NICK message received when a user changes their nick.
A KICK message received when a user kicks another user from the channel.
A MODE message received when a user's mode changes.
data WhoisReplyMsg Source
A message received as a response to a WhoisCmd
.
WhoisNoSuchNickMsg | |
WhoisNickInfoMsg | |
|
All other messages which are not parsed as any of the above message types.
OtherMsg | |
|
IRC Commands
A NICK command sent to set the bot's nick.
A USER command sent to identify the bot.
A JOIN command sent to join the channel.
A QUIT command sent to quit the server.
A NAMES command sent to ask for the nicks of the users in the channel.
A WHOIS command sent to ask for the status of a user nick.
WhoisCmd !Text |
Message Parsing
type MessageParserId = Text Source
Message parser id. Should be unique.
data MessagePart Source
A part of a mutlipart message.
MessagePart | |
|
data MessageParseResult Source
The result of parsing a message line.
ParseDone !Message ![MessagePart] | A fully parsed message and leftover message parts. |
ParsePartial ![MessagePart] | A partial message with message parts received yet. |
ParseReject | Returned if a message line cannot be parsed by a particular parser. |
data MessageParser Source
A message parser used for parsing text lines from the server to Message
s.
MessageParser | |
|
Command Formatting
type CommandFormatter = BotConfig -> Message -> Maybe Text Source
A command formatter which optionally formats commands to texts which are then sent to the server.
Bot
The configuration for running the bot.
BotConfig | |
|
Creates a new bot config with essential fields leaving rest of the fields empty.
The bot.
Bot | |
|
The current status of the bot.
Connected | Connected to the server |
Disconnected | Disconnected from the server. |
Joined | Joined the channel. |
Kicked | Kicked from the channel. |
Errored | Some unhandled error happened. |
Idle | No communication with the server. The bot is idle.
If the bot stays idle for |
Interrupted | Interrupted using external signals like SIGINT. |
NickNotAvailable | Bot's current nick is already taken on the server. |
NickAvailable | Bot's original nick is available on the server. |
Message Handlers
type MsgHandlerName = Text Source
Name of a message handler.
class (MonadIO m, Applicative m, MonadReader BotConfig m, MonadBase IO m) => MonadMsgHandler m Source
The monad in which message handlers actions run.
fromMsgHandler
data MsgHandler Source
A message handler containing actions which are invoked by the bot.
MsgHandler | |
|
newMsgHandler :: MsgHandler Source
Creates a new message handler which doesn't do anything.
data MsgHandlerMaker Source
A message handler maker which creates a new message handler.
MsgHandlerMaker | |
|
Message Channel
data MessageChannel a Source
A channel through which messages are sent and received.
:: MessageChannel a | The channel |
-> a | The message to send |
-> IO () |
Sends a message through a message channel.