Files
shaniqua-core/src/GypsFulvus/PluginStuff.hs

54 lines
2.0 KiB
Haskell
Raw Normal View History

2020-09-14 17:17:43 +02:00
module GypsFulvus.PluginStuff(loadCommsPlugins, Sewage(..), Manhole(..), InitStatus(..)) where
2020-09-12 23:56:49 +02:00
import Control.Monad
import System.Directory
import System.Plugins.Make
import Data.Maybe
import Control.Concurrent.STM
import Control.Concurrent.STM.TMVar
2020-09-14 15:46:45 +02:00
import qualified Data.Text as T
data Sewage = Sewage {
getSewageAuthor :: T.Text,
getSewage :: T.Text
}
data Manhole = Manhole {
getInputChan :: TChan Sewage,
getOutputChan :: TChan Sewage}
2020-09-14 17:07:31 +02:00
data InitStatus = GoodInitStatus | BadInitStatus T.Text
srcPluginPath :: IO FilePath
2020-09-14 15:46:45 +02:00
srcPluginPath = getXdgDirectory XdgData "gypsfulvus/srcplugins" >>= makeAbsolute
2020-09-12 23:56:49 +02:00
configPath :: IO FilePath
configPath = getXdgDirectory XdgConfig "gypsfulvus"
2020-09-12 21:44:21 +02:00
-- load all the plugins for IO (e.g. IRC, stdio, maybe matrix procol, telnet, whatever)
2020-09-12 23:56:49 +02:00
loadCommsPlugins canary collectorChannel =
let potentialPlugins = srcPluginPath >>= \pp -> listDirectory pp >>= filterM (\fuku -> doesDirectoryExist (pp ++ "/" ++ fuku)) >>= mapM (\fuku -> return (pp ++ "/" ++ fuku))
2020-09-12 23:56:49 +02:00
in do
srcPluginPath >>= putStrLn
srcPluginPath >>= listDirectory >>= mapM putStrLn
srcPluginPath >>= \pp -> listDirectory pp >>= filterM (\fuku -> putStrLn (pp ++ "/" ++ fuku) >> doesDirectoryExist (pp ++ "/" ++ fuku))
2020-09-12 23:56:49 +02:00
pp <- potentialPlugins
mapM_ putStrLn pp
ff <- mapM (\d -> findFile [d] "Plugin.hs") pp
let rff = map (fromMaybe "") $ filter (/= Nothing) ff
s <- mapM (\hng -> makeAll hng ["-v","-dynamic"]) rff
mapM (\s' -> case s' of
MakeSuccess _ p -> putStrLn p
2020-09-14 15:46:45 +02:00
MakeFailure e -> putStrLn $ show e) s
2020-09-12 23:56:49 +02:00
_ <- atomically $ swapTMVar canary True
-- I don't actually want to quit here but I don't like errors from STM heuristics when the canary is GCed
return ()
2020-09-12 21:44:21 +02:00
-- load all the routines that the bot can run (e.g. run tcl code, calculator, youtube, etc.)
loadLabourPlugins availableCommandMap = undefined
-- thread to pass any work to be done