3
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local parse = Luan.parse or error()
|
|
4 local Db = require "site:/lib/Db.luan"
|
|
5
|
|
6
|
|
7 local Config = {}
|
|
8
|
|
9 local function get()
|
|
10 local doc = Db.get_document("type:config")
|
|
11 return doc and parse(doc.config)
|
|
12 end
|
|
13
|
|
14 function Config.get()
|
|
15 return get() or error "config not set"
|
|
16 end
|
|
17
|
|
18 function Config.get_for_config()
|
|
19 local config = get() or {}
|
|
20 config.discord = config.discord or {}
|
|
21 config.discord.client_id = config.discord.client_id or "replace"
|
|
22 config.discord.client_secret = config.discord.client_secret or "replace"
|
14
|
23 config.discord.bot_token = config.discord.bot_token or "replace"
|
3
|
24 return config
|
|
25 end
|
|
26
|
|
27 function Config.set(text)
|
|
28 parse(text) -- validate
|
|
29 Db.run_in_transaction( function()
|
|
30 local doc = Db.get_document("type:config") or {type="config"}
|
|
31 doc.config = text
|
|
32 Db.save(doc)
|
|
33 end )
|
|
34 end
|
|
35
|
|
36 return Config
|