From 9d034f464797fd469053ba00ed28f571e0677a86 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 13 Aug 2017 14:13:40 +0200 Subject: Lib.hs: Test chat message listening and posting Add an event handler that gets called when a message is posted to a channel the bot is on. When a message is posted, the bot will send a chat message containing the text "test". This tests out the message handling and posting mechanism, and gives us a place to build off of to allow the bot to communicate. --- src/Lib.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Lib.hs b/src/Lib.hs index 63b6367..06745ba 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -33,8 +33,16 @@ connectIRC :: B.ByteString -> Int -> T.Text -> IO () connectIRC host port nick = do conn <- IRC.connectWithTLS host port 1 let cfg = IRC.defaultIRCConf nick - -- let cfg' = cfg { _eventHandlers = yourCustomEventHandlers : _eventHandlers cfg } let cfg' = cfg { - IRC._channels = ["#test-chan-13513"] + IRC._eventHandlers = handlePrivmsg : IRC._eventHandlers cfg + , IRC._channels = ["#test-chan-13513"] } IRC.start conn cfg' + +handlePrivmsg :: IRC.EventHandler s +handlePrivmsg = IRC.EventHandler + { IRC._description = "" + , IRC._matchType = IRC.EPrivmsg + , IRC._eventFunc = \evt -> + IRC.send $ IRC.Privmsg "#test-chan-13513" (Right "test") + } -- cgit v1.2.3