irc-fun-bot-0.3.0.0: Library for writing fun IRC bots.

Safe HaskellNone
LanguageHaskell2010

Network.IRC.Fun.Bot.Chat

Contents

Description

This module provides IRC commands the bot can do within a bot session. They conveniently wrap the details of IRC connections and messages.

Synopsis

Connection Management

disconnect :: Session e s () Source

Disconnect from IRC by closing the bot's side of the connection. This function is mainly provided for completeness and cases of error. You should probably use the QUIT command of IRC to quit the network in a manner coordinated with the server.

After disconnection, make sure not to send more IRC commands.

quit Source

Arguments

:: Maybe String

Optional message, e.g. the reason for quitting

-> Session e s () 

Finish the IRC session, asking the server to close the connection.

Session Management

run Source

Arguments

:: Config

IRC configuration

-> Behavior e s

Bot behavior definition

-> e

Custom bot environment (read-only state)

-> s

Initial custom bot state

-> Session e s a

Session definition

-> IO a 

Connect to an IRC server and run the bot session

login :: Session e s () Source

Log in as an IRC user and identify with the bot's nickname and password. This is the first thing to do after botConnecting to the server.

pong Source

Arguments

:: String

Server name

-> Maybe String

Optional server to forward to

-> Session e s () 

IRC servers send PING messages at regular intervals to test the presence of an active client, at least if no other activity is detected on the connection. The server closes the connection automatically if a PONG response isn't sent from the client within a certain amount of time.

Therefore, an IRC client (both humans users and bots) usually listens to these PINGs and sends back PONG messages. This function sends a PONG. The parameters should simply be the ones received in the PING message.

Channels

joinChannel Source

Arguments

:: String

Channel name

-> Maybe String

Optional channel key (password)

-> Session e s () 

Join an IRC channel.

joinMulti Source

Arguments

:: [(String, Maybe String)]

List of channels and optional keys

-> Session e s () 

Join one or more IRC channels.

joinConfig :: Session e s () Source

Join the IRC channels listed in the configuration, without leaving any other channels the bot already joined.

partChannel Source

Arguments

:: String

Channel name

-> Maybe String

Optional part message, e.g. the reason for leaving

-> Session e s () 

Leave an IRC channel.

partMulti Source

Arguments

:: [String]

List of channel names

-> Maybe String

Optional part message, e.g. the reason for leaving

-> Session e s () 

Leave one or more IRC channels.

partAll :: Session e s () Source

Leave all IRC channels the bot joined.

Sending Messages

sendToChannel Source

Arguments

:: String

The channel name

-> String

The message to send. It may contain newlines, in which case it will be split into multiple messages and sent sequentially.

-> Session e s () 

Send a message to an IRC channel.

This usually requires that the bot joins the channel first, because many channels have the +n flag set. This flag forbids sending a messages into a channel from outside it.

sendToUser Source

Arguments

:: String

The user's nickname

-> String

The message to send. It may contain newlines, in which case it will be split into multiple messages and sent sequentially.

-> Session e s () 

Send a private message to an IRC user.

sendBack Source

Arguments

:: Maybe String

Channel name, specify if replying to a message sent in a channel. Otherwise pass Nothing.

-> String

The sender user's nickname

-> String

The message to send. It may contain newlines, in which case it will be split into multiple messages and sent sequentially.

-> Session e s () 

Send a message back to the sender. If a channel is specified, send to the channel. If not, send a private message.

failToChannel Source

Arguments

:: String

Target channel

-> String

User to whom to refer

-> Failure

Problem indication

-> Session e s () 

Send message explaining a failure to an IRC channel.

failToUser Source

Arguments

:: String

Target user

-> Failure

Problem indication

-> Session e s () 

Send message explaining a failure to an IRC user.

failBack Source

Arguments

:: Maybe String

Optional target channel, Nothing means private message

-> String

Target user nickname

-> Failure

Problem indication

-> Session e s () 

Send message explaining a failure back to the sender.

Other Utilities

putIrc :: Message -> Session e s () Source

Send an IRC message to the server. This should only be used if the other wrappers don't provide what you need. If that's the case, it may be a good idea for reusability to add a new wrapper.