Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Responding to IRC messages


Another way to interact with IRC in Haskell is by using the Network.SimpleIRC package. This package encapsulates much of the low-level networking and also provides useful IRC interfaces.

In this recipe, we will respond to messages in a channel. If any user types in the trigger phrase, in our case "host?", then we will reply to that user with their host address.

Getting ready

Install the Network.SimpleIRC package:

$ cabal install simpleirc

To test out the IRC bot, it is helpful to install an IRC client. A decent IRC client is Hexchat, which can be downloaded from http://hexchat.github.io. For a terminal-based IRC client, Irssi is one of the best: http://www.irssi.org.

How to do it…

Create a new file, which we call Main.hs, and do the following:

  1. Import the relevant libraries:

    {-# LANGUAGE OverloadedStrings #-}
    
    import Network.SimpleIRC
    import Data.Maybe
    import qualified Data.ByteString.Char8 as B
  2. Create an event handler when a message is received. If the message is "host...