aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-08-12 20:04:14 +0200
committerTeddy Wing2017-08-12 20:04:14 +0200
commit59d7bdb0d4252288c600a0e97ed15a3494a9d1ee (patch)
treeae6833a6bf98e72e0fe3dc240121c8040b69259d
parent983ede99bf5861bb52b163da846767e5de12ef07 (diff)
downloadsorbot-59d7bdb0d4252288c600a0e97ed15a3494a9d1ee.tar.bz2
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.
-rw-r--r--sorbot.cabal3
-rw-r--r--src/Lib.hs41
2 files changed, 32 insertions, 12 deletions
diff --git a/sorbot.cabal b/sorbot.cabal
index ba34ed4..8b29113 100644
--- a/sorbot.cabal
+++ b/sorbot.cabal
@@ -21,8 +21,11 @@ library
, Plugin.Base
, Plugin.GitHubCommit
build-depends: base >= 4.7 && < 5
+ , bytestring
+ , irc-client
, regex-tdfa
, sqlite-simple
+ , text
default-language: Haskell2010
executable sorbot-exe
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'