summaryrefslogtreecommitdiff
path: root/Hsbot/IRCPlugin.hs
blob: 568eb1d006586e09f311c89792957d16a2f64713 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
module Hsbot.IRCPlugin
    ( readMsg
    , sendCommand
    , sendRegisterCommand
    , sendUnregisterCommand
    , writeMsg
    ) where

import Control.Concurrent.Chan
import Control.Monad.State

import Hsbot.Types

-- | Basic input output for IrcPlugins
readMsg :: IrcPlugin (BotMsg)
readMsg = do
    chan  <- gets instanceChan
    input <- liftIO $ readChan chan
    return input

writeMsg :: BotMsg -> IrcPlugin ()
writeMsg botMsg = do
    serverChan <- gets instanceServerChan
    liftIO $ writeChan serverChan $ botMsg

-- | Commands management
sendCommand :: String -> String -> String -> IrcPlugin ()
sendCommand cmd to params = do
    serverChan <- gets instanceServerChan
    from       <- gets instanceName
    liftIO $ writeChan serverChan $ InternalCmd $ IntCmd cmd from to params Nothing

sendRegisterCommand :: String -> IrcPlugin ()
sendRegisterCommand cmd = sendCommand "REGISTER" "CORE" cmd

sendUnregisterCommand :: String -> IrcPlugin ()
sendUnregisterCommand cmd = sendCommand "UNREGISTER" "CORE" cmd

-- | a isAdmin helper : I need an admin plugin (to track admins' status around chans)