aboutsummaryrefslogtreecommitdiffstats
path: root/src/Reaktor/Plugins/Mention.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2019-01-13 23:52:05 +0100
committertv <tv@krebsco.de>2019-01-21 02:12:00 +0100
commitce276eee82ec0b8c4106beb4c51d6f9eb77335c4 (patch)
treee41019c40471a45659fefba1671fa68395f062d6 /src/Reaktor/Plugins/Mention.hs
parentdffc580ca255cd118a0dfcdae7a5bb67f4824dcc (diff)
src: initv0.0.0
Diffstat (limited to 'src/Reaktor/Plugins/Mention.hs')
-rw-r--r--src/Reaktor/Plugins/Mention.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Reaktor/Plugins/Mention.hs b/src/Reaktor/Plugins/Mention.hs
new file mode 100644
index 0000000..0c86d74
--- /dev/null
+++ b/src/Reaktor/Plugins/Mention.hs
@@ -0,0 +1,27 @@
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE OverloadedStrings #-}
+module Reaktor.Plugins.Mention (plugin) where
+
+import Control.Monad (when)
+import Data.Aeson
+import qualified Data.ByteString.Char8 as BS
+import qualified Data.Char
+import Reaktor.Message
+import Reaktor.Types
+
+
+plugin :: Value -> IO Plugin
+plugin _ = return (Plugin run False)
+
+
+run :: PluginFunc
+run = \case
+ Message _ "PRIVMSG" (msgtarget:text:[]) -> do
+ nick <- getNick
+ when (isMention nick text) $ do
+ sendMsg (privmsg msgtarget ["I'm famous!"])
+ _ -> return ()
+ where
+ isMention nick text =
+ not (BS.isPrefixOf (nick <> ":") text) &&
+ any (==nick) (BS.splitWith (not . Data.Char.isAlphaNum) text)