Add matrix.disable to config file (fix #47)
This commit is contained in:
parent
a4ae6f77c7
commit
dea25cd2f9
25
config.go
25
config.go
@ -17,6 +17,7 @@ type Configuration struct {
|
||||
username string
|
||||
password string
|
||||
room_id string
|
||||
disabled bool
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +47,19 @@ func getIntFromTable(L *lua.LState, lobj lua.LValue, key string, out *int64) (bo
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// getBoolFromTable retrieves a bool from a table on the Lua stack using the key passed in.
|
||||
//
|
||||
// If the value is nil, 'out' is unchanged.
|
||||
func getBoolFromTable(L *lua.LState, lobj lua.LValue, key string, out *bool) (bool, error) {
|
||||
lv := L.GetTable(lobj, lua.LString(key))
|
||||
if boolean, ok := lv.(lua.LBool); ok { // Value is boolean
|
||||
*out = bool(boolean)
|
||||
} else if _, ok := lv.(*lua.LNilType); !ok { // Value is not a bool, and is not nil
|
||||
return true, errors.New("'" + key + "' is not a bool")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// getTableFromTable retrieves a nested table from the Lua stack using the key passed in.
|
||||
func getTableFromTable(L *lua.LState, lobj lua.LValue, key string, out *lua.LValue) bool {
|
||||
lv := L.GetTable(lobj, lua.LString(key))
|
||||
@ -80,9 +94,14 @@ func parseConfig(path string, config *Configuration) {
|
||||
// Matrix config
|
||||
var matrix lua.LValue
|
||||
getTableFromTable(L, table, "matrix", &matrix) // Get the 'matrix' sub table
|
||||
if matrix.Type().String() != "table" { // Make sure 'config.matrix' is of type 'table'
|
||||
// Make sure 'config.matrix' is of type 'table'
|
||||
if matrix_type := matrix.Type().String(); matrix_type != "table" && matrix_type != "nil" {
|
||||
log.Fatalf("config.matrix is of type : '%s', not 'table'", matrix.Type().String())
|
||||
} else if matrix_type != "nil" {
|
||||
if _, err := getBoolFromTable(L, matrix, "disabled", &config.matrix.disabled); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !config.matrix.disabled { // Only load the rest of the matrix config if matrix isn't disabled
|
||||
if _, err := getStringFromTable(L, matrix, "homeserver", &config.matrix.homeserver); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -96,3 +115,7 @@ func parseConfig(path string, config *Configuration) {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
} else if matrix_type == "nil" { // Assume config.matrix.disabled is true if 'matrix' is missing from the config file
|
||||
config.matrix.disabled = true
|
||||
}
|
||||
}
|
||||
|
4
main.go
4
main.go
@ -105,6 +105,8 @@ func main() {
|
||||
}
|
||||
|
||||
parseConfig(*config_path, &configuration) // Parse JSON configuration file
|
||||
// Disable Matrix if it's disabled in either the config or specified on CLI
|
||||
configuration.matrix.disabled = *disable_matrix || configuration.matrix.disabled
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // Webhook receiver
|
||||
var data map[string]interface{}
|
||||
@ -125,7 +127,7 @@ func main() {
|
||||
log.Printf("Starting Lapis Deploy on port %d...", configuration.port)
|
||||
|
||||
startAllSites() // Start all the servers
|
||||
if !*disable_matrix { // Only start Matrix bot if --disable-matrix isn't passed
|
||||
if !configuration.matrix.disabled { // Only start Matrix bot if --disable-matrix isn't passed
|
||||
go initMatrix() // Start Matrix stuff in a goroutine
|
||||
} else {
|
||||
log.Print("Matrix bot is disabled!")
|
||||
|
Loading…
Reference in New Issue
Block a user