2015-11-12 17:42:03 +01:00
|
|
|
local function save_value(msg, name, value)
|
|
|
|
if (not name or not value) then
|
2016-06-22 13:59:06 +02:00
|
|
|
return "Benutzung: #set Variable Wert"
|
2015-11-12 17:42:03 +01:00
|
|
|
end
|
2015-05-09 16:34:53 +02:00
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
local hash = get_redis_hash(msg, 'variables')
|
|
|
|
if hash then
|
|
|
|
print('Saving variable to redis hash '..hash)
|
|
|
|
redis:hset(hash, name, value)
|
|
|
|
return "Gespeichert: "..name.." = "..value
|
|
|
|
end
|
|
|
|
end
|
2015-05-09 16:34:53 +02:00
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
local function delete_value(msg, name, value)
|
|
|
|
if msg.to.type == 'chat' then
|
|
|
|
hash = 'chat:'..msg.to.id..':variables'
|
|
|
|
end
|
|
|
|
if msg.to.type == 'user' then
|
|
|
|
hash = 'user:'..msg.from.id..':variables'
|
|
|
|
end
|
|
|
|
if redis:hexists(hash, name) == true then
|
|
|
|
print('Deleting variable from redis hash '..hash)
|
|
|
|
redis:hdel(hash, name, value)
|
|
|
|
return 'Variable "'..name..'" erfolgreich gelöscht!'
|
|
|
|
else
|
|
|
|
return 'Du kannst keine Variable löschen, die nicht existiert .-.'
|
|
|
|
end
|
2015-05-09 16:34:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function run(msg, matches)
|
2015-11-12 17:42:03 +01:00
|
|
|
local name = string.sub(matches[1], 1, 50)
|
|
|
|
local value = string.sub(matches[2], 1, 1000)
|
|
|
|
|
|
|
|
if value == "nil" then
|
|
|
|
text = delete_value(msg, name, value)
|
|
|
|
else
|
|
|
|
text = save_value(msg, name, value)
|
|
|
|
end
|
|
|
|
return text
|
2015-05-09 16:34:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2016-06-22 13:59:06 +02:00
|
|
|
description = "Setzt Variablen, nutze #get zum Abrufen.",
|
2015-11-12 17:42:03 +01:00
|
|
|
usage = {
|
2016-06-22 13:59:06 +02:00
|
|
|
"#set [Variable] [Wert]: Speichert eine Variable mit einem Wert.",
|
|
|
|
"#set (Variable) nil: Löscht Variable"
|
2015-11-12 17:42:03 +01:00
|
|
|
},
|
|
|
|
patterns = {
|
2016-06-22 13:59:06 +02:00
|
|
|
"^#set ([^%s]+) (.+)$"
|
2015-11-12 17:42:03 +01:00
|
|
|
},
|
|
|
|
run = run
|
2015-05-10 13:09:06 +02:00
|
|
|
}
|