Mercurial Hosting > disearch
view src/lib/Config.luan @ 14:80105b716a62
start bot
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 31 Oct 2023 23:56:48 -0600 |
parents | 43814e9f5802 |
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