-
Notifications
You must be signed in to change notification settings - Fork 0
/
SayPlugin.hs
35 lines (27 loc) · 1016 Bytes
/
SayPlugin.hs
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
28
29
30
31
32
33
34
35
{-# LANGUAGE OverloadedStrings #-}
module SayPlugin
( plugin
) where
import qualified Data.Text as T(Text, isPrefixOf, words, unwords)
import IrcUtilities(Plugin(Plugin), Bot(Bot), IrcMsg(Privmsg), bNick, msgTo)
import MyUtils(when)
import Redirection(unwrapRedirectFromMsg)
-- Plugin Info
plugin :: Plugin
plugin = Plugin "SayPlugin" run helpAvailableUserCmds helpAvailableModCmds helpCmd
-- Main run
run :: IrcMsg -> Bot -> IO [T.Text]
run (Privmsg author channel message) bot@(Bot _ config _) = do
when (",say" `T.isPrefixOf` message') $ do
return [msgTo channel target textToSay]
where
(message', target) = unwrapRedirectFromMsg message author (bNick config)
textToSay = T.unwords . drop 1 . T.words $ message'
run _ _ = return []
-- Help
helpAvailableUserCmds :: [T.Text]
helpAvailableUserCmds = ["say"]
helpAvailableModCmds :: [T.Text]
helpAvailableModCmds = []
helpCmd :: T.Text -> [T.Text]
helpCmd "say" = [",say <text> # Mówi <text>"]