blob: 0c86d74a76d5ef7398d796be7616705a977c2dbc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)
|