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

51 lines
1.1 KiB
Lua
Raw Permalink Normal View History

2015-11-12 17:42:03 +01:00
local function get_value(msg, var_name)
local hash = get_redis_hash(msg, 'variables')
if hash then
local value = redis:hget(hash, var_name)
if not value then
return'Nicht gefunden, benutze "!get", um alle Variablen aufzulisten.'
else
return var_name..' = '..value
end
end
2015-11-12 17:42:03 +01:00
end
2015-05-28 16:47:30 +02:00
local function list_variables(msg)
2015-11-12 17:42:03 +01:00
local hash = get_redis_hash(msg, 'variables')
2015-05-28 16:47:30 +02:00
if hash then
2015-11-12 17:42:03 +01:00
print('Getting variable from redis hash '..hash)
2015-05-28 16:47:30 +02:00
local names = redis:hkeys(hash)
local text = ''
2015-11-12 17:42:03 +01:00
for i=1, #names do
variables = get_value(msg, names[i])
text = text..variables.."\n"
2015-05-28 16:47:30 +02:00
end
2015-11-12 17:42:03 +01:00
if text == '' or text == nil then
return 'Keine Variablen vorhanden!'
else
return text
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 {
2015-11-12 17:42:03 +01:00
description = "Bekommt Variablen, die mit !set gesetzt wurden",
usage = {
"#get: Gibt alle Variablen aus",
"#get (Variable): Gibt die Variable aus."
2015-11-12 17:42:03 +01:00
},
patterns = {
"^(#get) (.+)$",
"^#get$"
2015-11-12 17:42:03 +01:00
},
run = run
}