This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/get.lua

44 lines
940 B
Lua
Raw Normal View History

local f = io.open('./res/values.json', "r+")
if f == nil then
f = io.open('./res/values.json', "w+")
f:write("{}") -- Write empty table
f:close()
_values = {}
else
local c = f:read "*a"
f:close()
_values = json:decode(c)
end
2014-11-23 00:31:22 +01:00
2014-11-17 20:47:03 +01:00
function get_value( value_name )
-- If there is not value name, return all the values.
if (value_name == nil ) then
local text = ""
2014-11-23 00:31:22 +01:00
for key,value in pairs(_values) do
2014-11-17 20:47:03 +01:00
text = text..key.." = "..value.."\n"
end
return text
end
2014-11-23 00:31:22 +01:00
local value = _values[value_name]
2014-11-17 20:47:03 +01:00
if ( value == nil) then
return "Can't find "..value_name
end
return value_name.." = "..value
end
function run(msg, matches)
2014-11-17 21:55:25 +01:00
if matches[1] == "!get" then
return get_value(nil)
end
return get_value(matches[1])
2014-11-17 20:47:03 +01:00
end
return {
description = "retrieves variables saved with !set",
usage = "!get (value_name)",
2014-11-17 21:55:25 +01:00
patterns = {
"^!get (%a+)$",
"^!get$"},
2014-11-17 20:47:03 +01:00
run = run
}