Clean. Get and Set
This commit is contained in:
27
plugins/get.lua
Normal file
27
plugins/get.lua
Normal file
@ -0,0 +1,27 @@
|
||||
function get_value( value_name )
|
||||
-- If there is not value name, return all the values.
|
||||
if (value_name == nil ) then
|
||||
local text = ""
|
||||
for key,value in pairs(config.values) do
|
||||
text = text..key.." = "..value.."\n"
|
||||
end
|
||||
return text
|
||||
end
|
||||
local value = config.values[value_name]
|
||||
if ( value == nil) then
|
||||
return "Can't find "..value_name
|
||||
end
|
||||
return value_name.." = "..value
|
||||
end
|
||||
|
||||
function run(msg, matches)
|
||||
local text = matches[1]
|
||||
return text
|
||||
end
|
||||
|
||||
return {
|
||||
description = "retrieves variables saved with !set",
|
||||
usage = "!get (value_name)",
|
||||
patterns = {"^!get ?(%a+)?$"},
|
||||
run = run
|
||||
}
|
25
plugins/set.lua
Normal file
25
plugins/set.lua
Normal file
@ -0,0 +1,25 @@
|
||||
function save_value( text )
|
||||
var_name, var_value = string.match(text, "(%a+) (.+)")
|
||||
if (var_name == nil or var_value == nil) then
|
||||
return "Usage: !set var_name value"
|
||||
end
|
||||
config.values[var_name] = var_value
|
||||
local json_text = json:encode_pretty(config)
|
||||
file = io.open ("./bot/config.json", "w+")
|
||||
file:write(json_text)
|
||||
file:close()
|
||||
return "Saved "..var_name.." = "..var_value
|
||||
end
|
||||
|
||||
function run(msg, matches)
|
||||
local text = save_value(msg.text)
|
||||
return text
|
||||
end
|
||||
|
||||
return {
|
||||
description = "Set value",
|
||||
usage = "!set [value_name] [data]",
|
||||
patterns = {"^!set (%a+) (.+)$"},
|
||||
run = run
|
||||
}
|
||||
|
Reference in New Issue
Block a user