module API where
import qualified Data.Map as M
import Control.Monad.Reader
import Control.Concurrent
import System.Plugins
import Data.Version
import System.Info
import Text.Printf
import System.IO
import Config
type PluginAction a = ReaderT PluginState IO a
type InfAction = (String -> String -> String -> String -> PluginAction String)
type PluginList = [(Module,InfinityPlugin)]
data InfinityPlugin = InfinityPlugin {
name :: String,
commands :: [String],
help :: [(String,String)],
action :: InfAction
}
data PluginState = PluginState {
handle :: Handle,
remotechan :: Chan String,
addr :: String,
admins :: [String],
chans :: [String],
pluglist :: [InfinityPlugin]
}
runAction :: PluginAction String -> PluginState -> IO String
runAction x r = runReaderT x r
-- functions usable by plugins
send :: String -> String -> PluginAction ()
send c s = do
h <- asks handle
io $ hPrintf h "%s %s\r\n" c s
report $ ((printf "%s %s" c s) :: String)
privmsg :: String -> String -> PluginAction ()
privmsg c s = do
h <- asks handle
send "PRIVMSG" (c++" :"++s)
io :: IO a -> PluginAction a
io = liftIO
report :: String -> PluginAction ()
report s = do
c <- asks remotechan
serv <- asks addr
io $ writeChan c (serv ++ " *** " ++ s)
infinityVer = unwords ["Infinity",v,"-",arch,os,compilerName,(showVersion compilerVersion)]
where
v = "v0.1.1"