-
Notifications
You must be signed in to change notification settings - Fork 1
/
configedit.lua
164 lines (164 loc) · 5.16 KB
/
configedit.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
local ____lualib = require("lualib_bundle")
local __TS__ArrayFind = ____lualib.__TS__ArrayFind
local Error = ____lualib.Error
local RangeError = ____lualib.RangeError
local ReferenceError = ____lualib.ReferenceError
local SyntaxError = ____lualib.SyntaxError
local TypeError = ____lualib.TypeError
local URIError = ____lualib.URIError
local __TS__New = ____lualib.__TS__New
local __TS__ArrayMap = ____lualib.__TS__ArrayMap
local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
local __TS__StringSplit = ____lualib.__TS__StringSplit
local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
local ____exports = {}
local props
local ____data = require("data")
local storage = ____data.default
local ____inspect = require("inspect")
local inspect = ____inspect.inspect
local ____utils = require("utils")
local utils = ____utils.default
local ____storage_0 = storage
local config = ____storage_0.config
local function config_show(ctx, args)
ctx.channel:add_system_message("Supibot Completion Plugin config:")
for ____, p in ipairs(props) do
ctx.channel:add_system_message((((("[" .. p.name) .. "] ") .. p.display) .. ": ") .. tostring(config.data[p.name]))
end
end
local function config_set(ctx, args)
if #args == 0 then
ctx.channel:add_system_message("Usage: /sbc:config set <property_name> <value>")
return
end
local prop = table.remove(ctx.words, 1)
local value = table.remove(ctx.words, 1)
if prop == nil or value == nil then
return assert(false)
end
local p = __TS__ArrayFind(
props,
function(____, v) return v.name == prop end
)
if p == nil then
ctx.channel:add_system_message("Unknown sbc config: " .. prop)
return
end
do
local function ____catch(e)
ctx.channel:add_system_message("Error: " .. tostring(e))
return true
end
local ____try, ____hasReturned, ____returnValue = pcall(function()
config.data[prop] = p.convert(value)
end)
if not ____try then
____hasReturned, ____returnValue = ____catch(____hasReturned)
end
if ____hasReturned then
return ____returnValue
end
end
ctx.channel:add_system_message(("Updated " .. prop) .. ".")
config:save()
end
local function conv_str(s)
return s
end
local function conv_bool(s)
if s == "true" then
return true
end
if s == "false" then
return false
end
error(
__TS__New(Error, ("Unable to convert: " .. s) .. " to boolean"),
0
)
end
props = {{name = "my_username", display = "Username", convert = conv_str}, {name = "rewrite_gift", display = "Rewrite $gift to $cookie", convert = conv_bool}}
local config_subs = {
show = {
help = "Shows you the config",
func = config_show,
completions = function() return {} end
},
set = {
help = "Sets a config value",
func = config_set,
completions = function(words)
if #words == 0 then
return {}
end
if #words == 1 then
return __TS__ArrayMap(
props,
function(____, it) return it.name .. " " end
)
else
local prop = __TS__ArrayFind(
props,
function(____, it) return string.lower(it.name) == words[1] end
)
if (prop and prop.convert) == conv_bool then
return {"true", "false"}
end
return {}
end
end
}
}
local function command_config(ctx)
table.remove(ctx.words, 1)
if #ctx.words == 0 then
ctx.channel:add_system_message("Available /sbc:config subcommands:")
for ____, ____value in ipairs(__TS__ObjectEntries(config_subs)) do
local k = ____value[1]
local sub = ____value[2]
ctx.channel:add_system_message(((" " .. k) .. " -- ") .. sub.help)
end
return
end
local sub = table.remove(ctx.words, 1)
local cb = config_subs[sub]
print(inspect(ctx.words))
cb.func(
ctx,
{table.unpack(ctx.words)}
)
end
function ____exports.init_config_edit()
c2.register_command("/sbc:config", command_config)
end
function ____exports.sbcconfig_complete(ev)
print(inspect(ev))
local words = __TS__StringSplit(ev.full_text_content, " ")
if words[#words] == "" then
table.remove(words)
end
print(inspect(words))
if #words == 1 then
return utils.new_completion_list()
end
if #words == 2 then
local list = utils.new_completion_list()
list.hide_others = true
list.values = __TS__ArrayMap(
__TS__ObjectKeys(config_subs),
function(____, it) return it .. " " end
)
print(inspect(list))
return utils.filter(list, ev.query)
end
table.remove(words, 1)
local sub = table.remove(words, 1)
local out = utils.new_completion_list()
out.values = config_subs[sub].completions(words)
if #out.values > 0 then
out.hide_others = true
end
return utils.filter(out, ev.query)
end
return ____exports