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

50 lines
1.0 KiB
Lua
Raw Normal View History

2015-05-28 16:47:30 +02:00
local function get_variables_hash(msg)
if msg.to.type == 'chat' then
return 'chat:'..msg.to.id..':variables'
end
2015-05-28 16:47:30 +02:00
if msg.to.type == 'user' then
return 'user:'..msg.from.id..':variables'
end
2015-05-28 16:47:30 +02:00
end
local function list_variables(msg)
local hash = get_variables_hash(msg)
if hash then
local names = redis:hkeys(hash)
local text = ''
for i=1, #names do
text = text..names[i]..'\n'
end
return text
end
end
2015-05-28 16:47:30 +02:00
local function get_value(msg, var_name)
local hash = get_variables_hash(msg)
if hash then
local value = redis:hget(hash, var_name)
if not value then
return'Not found, use "/get" to list variables'
else
return var_name..' => '..value
end
end
end
2015-05-28 16:47:30 +02:00
local function run(msg, matches)
if matches[2] then
return get_value(msg, matches[2])
else
return list_variables(msg)
end
end
return {
description = "Bekommt Variable, die mit /set gesetzt wurde",
usage = {"/get (Variable)"},
2015-05-28 16:47:30 +02:00
patterns = {"^/get (%a+)$","^/get$"},
run = run,
pre_process = lex
}