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-2/otouto/plugins/get.lua
Andreas Bielawski a4d7c40ad9 Committe aktuellen Status.
NEU:
- Twitter-Plugin (ohne Markdown bisher)
- Get- Set-Plugins
- 9GAG
- Adfly
- Redis-Integration
- Google Search
- Google Images (modifiziert, mit Blacklist, bisher ohne Caching)
- Einige Plugins lokalisiert

Das ist momentan noch alles WIP, das meiste ist einfach bloß copy&paste vom proprietären
Brawlbot v1.
2016-06-11 14:46:41 +02:00

60 lines
1.4 KiB
Lua

local get = {}
local utilities = require('otouto.utilities')
local redis = (loadfile "./otouto/redis.lua")()
get.command = 'get <Variable>'
function get:init(config)
get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('get', true).table
get.doc = [[*
]]..config.cmd_pat..[[get*: Gibt alle Variablen aus
*]]..config.cmd_pat..[[get* _<Variable>_: Gibt _Variable_ aus
Nutze `!set <Variable> <Wert>` zum Setzen von Variablen]]
end
function get: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
end
function get:list_variables(msg)
local hash = get_redis_hash(msg, 'variables')
print(hash)
if hash then
print('Getting variable from redis hash '..hash)
local names = redis:hkeys(hash)
local text = ''
for i=1, #names do
variables = get:get_value(msg, names[i])
text = text..variables.."\n"
end
if text == '' or text == nil then
return 'Keine Variablen vorhanden!'
else
return text
end
end
end
function get:action(msg)
local input = utilities.input(msg.text)
if input then
output = get:get_value(msg, input:match('(.+)'))
else
output = get:list_variables(msg)
end
utilities.send_message(self, msg.chat.id, output, true, nil, true)
end
return get