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

Safe HaskellNone
LanguageHaskell2010

Network.IRC.Fun.Bot.Types

Description

This module provides the datatypes.

Synopsis

Documentation

data Connection :: *

Details of the connection to IRC.

Constructors

Connection 

Fields

connServer :: String

IRC Server address, e.g. "irc.freenode.net"

connPort :: Int

IRC server port, 6667 should be a safe default

connTls :: Bool

Whether to make an encrypted connection via TLS (not implemented)

connNick :: String

IRC nickname for the bot, e.g. "funbot"

connPassword :: Maybe String

Connection password, use if the nickname is registered

data Config Source

Configuration for the bot connection to IRC.

Constructors

Config 

Fields

cfgConnection :: Connection

Connection details, including nickname and optional password

cfgChannels :: [String]

The list of channels for the bot to join is generally set in the state file, but when the bot launches it joins both the channels listed there and the ones listed here. This list is intended to be used as hard-coded backup, i.e. the bot will always join these channels regardless of what the state file says.

cfgLogDir :: FilePath

Directory path under which IRC log files will be placed. Relative to the bot process working directory, or absolute.

cfgStateRepo :: Maybe FilePath

Directory path for the state file. This enables Git commits of the state file. A relative (to the bot process working dir) or absolute path to the Git repository. You must create the directory yourself if it doesn't exist, but repo will be auto-created for you if needed.

cfgStateFile :: FilePath

Filename into the bot state managed by this library will be stored. The custom part of the state isn't handled. If stateDir is Nothing, this is a path relative to the bot process working directory, or absolute. Otherwise, it's relative to the stateDir.

cfgSaveInterval :: TimeInterval

Minimal time interval between state saves. For example, to say "don't write state to file more than once per three seconds", set this field to 3 seconds, i.e. time (3 :: Second).

cfgBotEventLogFile :: FilePath

Filename for the bot's main event log, i.e. produced by the IRC event source.

cfgIrcErrorLogFile :: Maybe FilePath

Filename for writing error messages generated by invalid IRC lines or errors in their analysis or in event detection. Useful for debugging.

cfgMaxMsgChars :: Maybe Int

Maximal number of characters in a message the bot can send to a user or a channel. Longer messages will be split. Nothing means no limit, i.e. let the IRC server truncate long messages. This limit applies to sendToUser and sendToChannel and all the functions which use them. A safe default if you want to set a limit is 400.

cfgLagCheck :: Maybe TimeInterval

Time interval for sending PINGs to the server, to make sure the connection is alive. Nothing means no PINGs sent.

cfgLagMax :: TimeInterval

Maximal lag time allowed before the bot quits.

cfgMaxMsgCount :: Int

Maximal number of messages to count per channel in the message counter. Possibly a bit more will be counted, in cases it doesn't require more memory anyway. If a user misses more than that number N, they will simply be notified "you missed at least N messages!".

TODO actually right now this is the maximal length of the per-channel log, which includes messages, joins and parts. It's just a tool to limit memory usage, nothing more.

cfgMsgDelay :: TimeInterval

IRC messages can be sent to users or channels either instantly, or through a dedicated sender thread. That thread creates a delay between messages, to avoid flooding, since that may result with the server blocking some of the messages. This option sets the time to wait between messages.

Instances

data Failure Source

Describes wrong usage of a bot command.

Constructors

WrongNumArgs

The number of arguments given is wrong

WrongNumArgsN (Maybe Int) (Maybe Int)

<first-param> arguments were given, instead of <second-param>

InvalidArgs

At least one of the arguments is invalid

InvalidArg (Maybe Int) (Maybe String)

Argument in position <first-param> and value <second-param> invalid

OtherFail String

Some other error, with a given description

data Command e s Source

A bot command, triggered by a message sent to an IRC channel the bot has joined.

The type parameter e is the type of environment, i.e. real-only state. The type parameter s is the type of the writable state the bot holds. For example, maybe you want your bot to keep a list of to-do items and manage it using bot commands. The bot state is where you store the to-do list.

Constructors

Command 

Fields

cmdNames :: [String]

The command's name string, e.g. "echo". More than one name is allowed per command, so that localized names and shortcuts can be made available.

The first name in the list is considered the primary name. When one name is shown, e.g. in help messages, it will be the primary name.

cmdRespond :: Maybe String -> String -> [String] -> (String -> Session e s ()) -> Session e s ()

What to do in response to the command being triggered by an IRC user. The bot can send an IRC message back to the channel, or modify its state, or both.

The returned value is in the Session monad (it is really RWST behind the scenes), which allows the bot to access the configuration and bot state, store and load data from files, communicate through the network (e.g. download RSS feeds) and more.

Parameters:

  1. Channel in which the command was triggered, if any
  2. Nickname of user who triggered the command
  3. Command parameters given
  4. Action for sending a message back to the sender, same as using sendBack with the channel and nickname
cmdHelp :: String

Help string for the command, explaining it purpose, its parameters and its usage, possibly giving an example. May contain newlines.

data CommandSet e s Source

The bot recognizes commands by picking IRC channel messages which begin with a special character, the command prefix. It's possible to have several prefixes, maybe give each its own role or meaning. A command set is a set of commands which share a prefix.

A command can be in more than one set.

Common prefixes are !, \@, >, :.

Constructors

CommandSet 

Fields

csetPrefix :: Char
 
csetCommands :: [Command e s]
 

data HistoryLine Source

A message sent previously by an IRC user into a channel.

Constructors

HistoryLine 

data ChanInfo Source

Per-channel information to return to the API user

Constructors

ChanInfo 

Fields

ciTrack :: Bool

Whether user-in-channel tracking is enabled for this channel

ciCount :: Bool

Whether message counting is enabled for this channel

ciLog :: Bool

Whether logging-to-file is enabled for this channel

ciHistoryLines :: Int

Maximal number of channel message history lines to remember

data MsgCountEntry Source

Message counter log entry.

Constructors

MsgCountMsgs Int

Number of messages sent in a channel

MsgCountJoin String

User joined the channel

MsgCountPart String

User left the channel

type Session e s = RWST (BotEnv e s) () (BotState s) IO Source

Bot monad. It provides read-only bot environment (e.g. the configuration), read-writable bot state (for use by bot commands) and IO.

data EventMatchSpace Source

Where an event matcher applies.

data Behavior e s Source

Bot behavior definition.

Constructors

Behavior 

Fields

handleJoin :: String -> String -> Session e s ()
 
handlePart :: String -> String -> Maybe String -> Session e s ()
 
handleQuit :: String -> Maybe String -> Session e s ()
 
handleMsg :: String -> String -> String -> Bool -> Session e s ()
 
handleAction :: String -> String -> String -> Bool -> Session e s ()
 
handleBotMsg :: String -> String -> String -> String -> Session e s ()
 
commandSets :: [CommandSet e s]
 
handlePersonalMsg :: String -> String -> Session e s ()
 
handlePersonalAction :: String -> String -> Session e s ()
 
handleNickChange :: String -> String -> Session e s ()
 
handleTopicChange :: String -> String -> String -> Session e s ()
 
handleNames :: String -> ChannelPrivacy -> [(Privilege, String)] -> Session e s ()

Handle a channel member list received. Parameters:

  1. Channel name
  2. Channel privacy
  3. List of channel members: their privilege level in the channel and their nicknames

type EventSource e s a Source

Arguments

 = Config

The bot configuration. The event source may find this useful.

-> e

The bot's custom environment. The event source may find this useful.

-> (a -> IO ())

A non-blocking IO action which sends a given event to the processing queue.

-> ([a] -> IO ())

A non-blocking IO action which sends a given list of events to the processing queue.

-> (FilePath -> IO Logger)

An IO action which creates a logger with a given target filename. An event source can use it to log events, errors, debug into, etc. into files efficiently.

-> IO () 

An IO action, possibly running forever, which produces events for the bot to process. These event sources are run by the bot in dedicated threads.

Type parameters:

  • e - custom bot environment type
  • s - custom bot state type
  • a - event type

type EventHandler e s a = a -> Session e s () Source

A bot session action which reacts to a single event which came from an EventSource.

Type parameters:

  • e - custom bot environment type
  • s - custom bot state type
  • a - event type

data Quotes Source

Quote types for string formatting.

Constructors

SingleQuotes Bool

Single quote on each side of the formatted string. The parameter sets whether to use Unicode (otherwise use ASCII fallback).

DoubleQuotes Bool

Double quote on each side of the formatted string. The parameter sets whether to use Unicode (otherwise use ASCII fallback).

BackTicks

Backtick on each side of the formatted string.