loadPlugin :: String -> FilePath -> Bot s (LoadStatus Plugin)
loadPlugin pluginName filePath = do
  debugMsg $ "Loading " ++ pluginName
  loadResult <- getPlugin filePath
  case loadResult of
    LoadFailure errs -> do
      debugMsg $ "The following errors occured when loading " ++ filePath
      mapM_ debugMsg errs
    
    LoadSuccess mod plugin -> do
      debugMsg $ "Loading " ++ pluginName ++ " successful"
      let pluginState = PluginState plugin mod []
      plugsVar <- use pluginMap
      modifyMVar_ plugsVar $ \plugMap -> do
        plugMap' <- unloadPlugin_ pluginName plugMap
        return $ HashMap.insert pluginName pluginState plugMap'
      withCurrentPlugin plugin $ forkBot_ (onLoad plugin)    
  return loadResult
loadPlugin :: String -> FilePath -> Bot s (LoadStatus Plugin)
loadPlugin pluginName filePath = do
  debugMsg $ "Loading " ++ pluginName
  loadResult <- getPlugin filePath
  case loadResult of
    LoadFailure errs -> do
      debugMsg $ "The following errors occured when loading " ++ filePath
      mapM_ debugMsg errs
    
    LoadSuccess mod plugin -> do
      debugMsg $ "Loading " ++ pluginName ++ " successful"
      let pluginState = PluginState plugin mod []
      plugsVar <- use pluginMap
      modifyMVar_ plugsVar $ \plugMap -> do
        plugMap' <- unloadPlugin_ pluginName plugMap
        return $ HashMap.insert pluginName pluginState plugMap'
      withCurrentPlugin plugin $ forkBot_ (onLoad plugin)    
  return loadResult
loadPlugin pluginName filePath = do
  debugMsg $ "Loading " ++ pluginName
  loadResult <- getPlugin filePath
  case loadResult of
    LoadFailure errs -> do
      debugMsg $ "The following errors occured when loading " ++ filePath
      mapM_ debugMsg errs
    
    LoadSuccess mod plugin -> do
      debugMsg $ "Loading " ++ pluginName ++ " successful"
      let pluginState = PluginState plugin mod []
      plugsVar <- use pluginMap
      modifyMVar_ plugsVar $ \plugMap -> do
        plugMap' <- unloadPlugin_ pluginName plugMap
        return $ HashMap.insert pluginName pluginState plugMap'
      withCurrentPlugin plugin $ forkBot_ (onLoad plugin)    
  return loadResult