hask-irc-core-0.1.0: A simple extensible IRC bot

Copyright(c) Abhinav Sarkar, 2014
LicenseApache-2.0
Maintainerabhinav@abhinavsarkar.net
Stabilityexperimental
PortabilityPOSIX
Safe HaskellTrustworthy
LanguageHaskell2010

Network.IRC.Types

Contents

Description

 

Synopsis

IRC Messages

newtype Nick Source

An IRC nick.

Constructors

Nick 

Fields

nickToText :: Text
 

Instances

Eq Nick 
Data Nick 
Ord Nick 
Show Nick 
Hashable Nick 
SafeCopy Nick 
Typeable * Nick 

data User Source

An IRC user.

Constructors

Self

The user for the bot itself.

User

An user other than the bot.

Fields

userNick :: !Nick

The user's nick.

userServer :: !Text

The user's server.

Instances

data Message Source

An message sent from the server to the bot or from the bot to the server or from a handler to another handler.

Constructors

Message 

Fields

msgTime :: !UTCTime

The time when the message was received/sent.

msgLine :: !Text

The raw message.

message :: !MessageW

The details of the parsed message.

Instances

data MessageW Source

A wrapper over all types of messages.

newMessage Source

Arguments

:: (MessageC msg, MonadIO m) 
=> msg

Message details

-> m Message 

Creates a new message with the current time and the given message details.

data IdleMsg Source

The internal (non-IRC) message received when the bot is idle.

Constructors

IdleMsg 

data NickInUseMsg Source

The message received when the bot's current nick is already in use.

Constructors

NickInUseMsg 

data PingMsg Source

A PING message. Must be replied with a PongCmd.

Constructors

PingMsg !Text 

data PongMsg Source

A PONG message. Received in response to a PingCmd.

Constructors

PongMsg !Text 

data NamesMsg Source

A NAMES message which contains a list of nicks of all users in the channel.

Constructors

NamesMsg ![Nick] 

data ChannelMsg Source

A PRIVMSG message sent to the channel from a user.

Constructors

ChannelMsg !User !Text 

data PrivMsg Source

A PRIVMSG private message sent to the bot from a user.

Constructors

PrivMsg !User !Text 

data ActionMsg Source

An PRIVMSG action message sent to the channel from a user.

Constructors

ActionMsg !User !Text 

data JoinMsg Source

A JOIN message received when a user joins the channel.

Constructors

JoinMsg !User 

data QuitMsg Source

A QUIT message received when a user quits the server.

Constructors

QuitMsg !User !Text 

data PartMsg Source

A PART message received when a user leaves the channel.

Constructors

PartMsg !User !Text 

data NickMsg Source

A NICK message received when a user changes their nick.

Constructors

NickMsg !User !Nick 

data KickMsg Source

A KICK message received when a user kicks another user from the channel.

Constructors

KickMsg 

Fields

kickUser :: !User
 
kickedNick :: !Nick
 
kickMsg :: !Text
 

data ModeMsg Source

A MODE message received when a user's mode changes.

Constructors

ModeMsg 

Fields

modeUser :: !User
 
modeTarget :: !Text
 
mode :: !Text
 
modeArgs :: ![Text]
 

data WhoisReplyMsg Source

A message received as a response to a WhoisCmd.

Constructors

WhoisNoSuchNickMsg 

Fields

whoisNick :: !Nick
 
WhoisNickInfoMsg 

Fields

whoisNick :: !Nick
 
whoisUser :: !Text
 
whoisHost :: !Text
 
whoisRealName :: !Text
 
whoisChannels :: ![Text]
 
whoisServer :: !Text
 
whoisServerInfo :: !Text
 

data OtherMsg Source

All other messages which are not parsed as any of the above message types.

Constructors

OtherMsg 

Fields

msgSource :: !Text
 
msgCommand :: !Text
 
msgTarget :: !Text
 
msg :: !Text
 

IRC Commands

data PingCmd Source

A PING command. A PongMsg is expected as a response to this.

Constructors

PingCmd !Text 

data PongCmd Source

A PONG command. Sent in response to a PingMsg.

Constructors

PongCmd !Text 

data PrivMsgReply Source

A PRIVMSG message sent to a user.

Constructors

PrivMsgReply !User !Text 

data NickCmd Source

A NICK command sent to set the bot's nick.

Constructors

NickCmd 

data UserCmd Source

A USER command sent to identify the bot.

Constructors

UserCmd 

data JoinCmd Source

A JOIN command sent to join the channel.

Constructors

JoinCmd 

data QuitCmd Source

A QUIT command sent to quit the server.

Constructors

QuitCmd 

data NamesCmd Source

A NAMES command sent to ask for the nicks of the users in the channel.

Constructors

NamesCmd 

data WhoisCmd Source

A WHOIS command sent to ask for the status of a user nick.

Constructors

WhoisCmd !Text 

Message Parsing

type MessageParserId = Text Source

Message parser id. Should be unique.

data MessagePart Source

A part of a mutlipart message.

Constructors

MessagePart 

Fields

msgPartTarget :: !Text
 
msgPartTime :: !UTCTime
 
msgPartLine :: !Text
 

data MessageParseResult Source

The result of parsing a message line.

Constructors

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 Messages.

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

data BotConfig Source

The configuration for running the bot.

Constructors

BotConfig 

Fields

botServer :: !Text

The server to connect to.

botPort :: !Int

The port to connect to.

botChannel :: !Text

The channel to join.

botOrigNick :: !Nick

Original nick of the bot.

botNick :: !Nick

Current nick of the bot.

botTimeout :: !Int

The timeout in seconds after which bot automatically disconnects and tries to reconnect. Should be few seconds more than the ping timeout of the server.

msgHandlerInfo :: !(Map MsgHandlerName (Map Text Text))

Info about the message handlers. A map of message handler names to a map of all commands supported by that message handler to the help text of that command.

msgHandlerMakers :: !(Map MsgHandlerName MsgHandlerMaker)

A map of message handler names to MsgHandlerMakers which are used to create message handlers for the bot.

msgParsers :: ![MessageParser]

A list of extra message parsers.

cmdFormatters :: ![CommandFormatter]

A list of extra command formatters. Note that these formatters will always be called after the built-in ones.

config :: !Configuration

All the bot configuration so that message handlers can lookup their own specific configs.

Instances

newBotConfig Source

Arguments

:: Text

server

-> Int

port

-> Text

channel

-> Nick

botNick

-> Int

botTimeout

-> BotConfig 

Creates a new bot config with essential fields leaving rest of the fields empty.

data Bot Source

The bot.

Constructors

Bot 

Fields

botConfig :: !BotConfig

The config for the bot.

botSocket :: !Handle

The network socket on which the bot communicates with the server.

msgHandlers :: !(Map MsgHandlerName MsgHandler)

The message handlers attached with the bot as a map of message handler names to the message handlers.

data BotStatus Source

The current status of the bot.

Constructors

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 botTimeout seconds, it disconnects.

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.

Minimal complete definition

fromMsgHandler

data MsgHandler Source

A message handler containing actions which are invoked by the bot.

Constructors

MsgHandler 

Fields

onMessage :: !(forall m. MonadMsgHandler m => Message -> m [Message])

The action invoked when a message is received. It returns a list of nessages in response which the bot sends to the server.

onStop :: !(forall m. MonadMsgHandler m => m ())

The action invoked when the message handler is stopped. Can use this for resource cleanup.

handlerHelp :: !(forall m. MonadMsgHandler m => m (Map Text Text))

The action invoked to get the map of the commands supported by the message handler and their help messages.

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.

Constructors

MsgHandlerMaker 

Fields

msgHandlerName :: !MsgHandlerName

The name of the message handler.

msgHandlerMaker :: !(BotConfig -> MessageChannel Message -> IO MsgHandler)

The action which is invoked to create a new message handler. Gets the bot config and the message channel used to receive messages.

Message Channel

data MessageChannel a Source

A channel through which messages are sent and received.

sendMessage Source

Arguments

:: MessageChannel a

The channel

-> a

The message to send

-> IO () 

Sends a message through a message channel.