Mercurial Hosting > disearch
view src/lib/Config.luan @ 15:d0b8e1a8fc69
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 01 Nov 2023 00:12:08 -0600 |
parents | 80105b716a62 |
children |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local parse = Luan.parse or error() local Db = require "site:/lib/Db.luan" local Config = {} local function get() local doc = Db.get_document("type:config") return doc and parse(doc.config) end function Config.get() return get() or error "config not set" end function Config.get_for_config() local config = get() or {} config.discord = config.discord or {} config.discord.client_id = config.discord.client_id or "replace" config.discord.client_secret = config.discord.client_secret or "replace" config.discord.bot_token = config.discord.bot_token or "replace" return config end function Config.set(text) parse(text) -- validate Db.run_in_transaction( function() local doc = Db.get_document("type:config") or {type="config"} doc.config = text Db.save(doc) end ) end return Config