aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-08-13 18:39:34 +0200
committerTeddy Wing2017-08-13 18:39:34 +0200
commitf6d317f1e36f7fbd83e5f47b54a3c1f5a5ceedde (patch)
tree878d8c8ab15867cc7a3e4febfedc85b69e1412ad
parent9d034f464797fd469053ba00ed28f571e0677a86 (diff)
downloadsorbot-f6d317f1e36f7fbd83e5f47b54a3c1f5a5ceedde.tar.bz2
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
-rw-r--r--src/Lib.hs10
1 files changed, 8 insertions, 2 deletions
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))