From 59d7bdb0d4252288c600a0e97ed15a3494a9d1ee Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 12 Aug 2017 20:04:14 +0200 Subject: Set up basic IRC support Add the 'irc-client' package to facilitate communication over IRC. Copy the example from: http://hackage.haskell.org/package/irc-client-0.4.4.4/docs/Network-IRC-Client.html which connects to a network. We specify a channel to join, and what do you know, it works! Pretty cool. Commented out the code that runs the GitHub Commit plugin for now while testing this. Add the `OverloadedStrings` extension so we can write string literals but have them converted into the appropriate `Data.Text` and `Data.ByteString` types required by the IRC library. --- src/Lib.hs | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Lib.hs b/src/Lib.hs index a6ea8c0..38fc283 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -1,23 +1,40 @@ +{-# LANGUAGE OverloadedStrings #-} + module Lib ( someFunc ) where +import qualified Data.ByteString as B +import qualified Data.Text as T + import Database.SQLite.Simple +import Network.IRC.Client import Message import Plugin someFunc :: IO () someFunc = do - let message = Message - { text = "75ac7b18a009ffe7a77a17a61d95c01395f36b44" - , channel = "#a-channel" - , nick = "anon" - } - Just plugin = matchPlugin message - dbConn <- open "db/sorbot_development.sqlite3" - response <- performPlugin plugin message dbConn - putStrLn $ case response of - Left e -> e - Right r -> r - close dbConn + connectIRC "irc.freenode.net" 6697 "test-bot-7890asdf" + -- let message = Message + -- { text = "75ac7b18a009ffe7a77a17a61d95c01395f36b44" + -- , channel = "#a-channel" + -- , nick = "anon" + -- } + -- Just plugin = matchPlugin message + -- dbConn <- open "db/sorbot_development.sqlite3" + -- response <- performPlugin plugin message dbConn + -- putStrLn $ case response of + -- Left e -> e + -- Right r -> r + -- close dbConn + +connectIRC :: B.ByteString -> Int -> T.Text -> IO () +connectIRC host port nick = do + conn <- connectWithTLS host port 1 + let cfg = defaultIRCConf nick + -- let cfg' = cfg { _eventHandlers = yourCustomEventHandlers : _eventHandlers cfg } + let cfg' = cfg { + _channels = ["#test-chan-13513"] + } + start conn cfg' -- cgit v1.2.3