From f6d317f1e36f7fbd83e5f47b54a3c1f5a5ceedde Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 13 Aug 2017 18:39:34 +0200 Subject: Lib.hs: Bot now responds on the channel that message came from Instead of always responding on a hard-coded channel, the bot now responds on the channel the PRIVMSG was received on. This can be either a regular channel or a query message. The `serv` argument is apparently the message sender's hostname. Wanted to print it out to see what that argument was. I had been following this example from "barrucadu"'s 'yukibot': https://github.com/barrucadu/yukibot/blob/31930b234eb423ed74546b56ada100105c1680ce/yukibot-backend-irc/Yukibot/Backend/IRC.hs#L152-L156 but the code ignored the first `Event` argument. In order to send it as a chat message, needed to convert it to a `Data.Text`, using the method courtesy of this tutorial: https://haskell-lang.org/tutorial/string-types --- src/Lib.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/Lib.hs') diff --git a/src/Lib.hs b/src/Lib.hs index 06745ba..4b5e844 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -6,6 +6,7 @@ module Lib import qualified Data.ByteString as B import qualified Data.Text as T +import qualified Data.Text.Encoding as TE import Database.SQLite.Simple import qualified Network.IRC.Client as IRC @@ -43,6 +44,11 @@ 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") + , IRC._eventFunc = \evt -> dispatchEvent evt } + where + dispatchEvent (IRC.Event serv (IRC.User nick) (IRC.Privmsg _ (Right msg))) = + IRC.send $ IRC.Privmsg nick (Right (TE.decodeUtf8 serv)) + dispatchEvent (IRC.Event serv + (IRC.Channel chan nick) (IRC.Privmsg _ (Right msg))) = + IRC.send $ IRC.Privmsg chan (Right (TE.decodeUtf8 serv)) -- cgit v1.2.3