2016-06-14 16:17:13 +02:00
|
|
|
local loc_manager = {}
|
|
|
|
|
|
|
|
function loc_manager:init(config)
|
|
|
|
loc_manager.triggers = {
|
2016-07-18 18:37:29 +02:00
|
|
|
"^/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn] (set) (.*)$",
|
|
|
|
"^/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn] (del)$",
|
|
|
|
"^/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn]$"
|
2016-06-14 16:17:13 +02:00
|
|
|
}
|
|
|
|
loc_manager.doc = [[*
|
|
|
|
]]..config.cmd_pat..[[location*: Gibt deinen gesetzten Wohnort aus
|
|
|
|
*]]..config.cmd_pat..[[location* _set_ _<Ort>_: Setzt deinen Wohnort auf diesen Ort
|
|
|
|
*]]..config.cmd_pat..[[location* _del_: Löscht deinen angegebenen Wohnort
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
loc_manager.command = 'location'
|
|
|
|
|
|
|
|
function loc_manager:set_location(user_id, location)
|
|
|
|
local hash = 'user:'..user_id
|
|
|
|
local set_location = get_location(user_id)
|
|
|
|
if set_location == location then
|
|
|
|
return 'Dieser Ort wurde bereits gesetzt.'
|
|
|
|
else
|
2016-08-01 21:07:27 +02:00
|
|
|
print('Setze location in redis hash '..hash..' zu '..location)
|
2016-06-14 16:17:13 +02:00
|
|
|
redis:hset(hash, 'location', location)
|
|
|
|
return 'Dein Wohnort wurde auf *'..location..'* festgelegt.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function loc_manager:del_location(user_id)
|
|
|
|
local hash = 'user:'..user_id
|
|
|
|
local set_location = get_location(user_id)
|
|
|
|
if not set_location then
|
|
|
|
return 'Du hast keinen Ort gesetzt'
|
|
|
|
else
|
2016-08-01 21:07:27 +02:00
|
|
|
print('Setze location in redis hash '..hash..' auf false')
|
2016-06-14 16:17:13 +02:00
|
|
|
-- We set the location to false, because deleting the value blocks redis for a few milliseconds
|
|
|
|
redis:hset(hash, 'location', false)
|
|
|
|
return 'Dein Wohnort *'..set_location..'* wurde gelöscht!'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function loc_manager:action(msg, config, matches)
|
|
|
|
local user_id = msg.from.id
|
|
|
|
|
|
|
|
if matches[1] == 'set' then
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_reply(msg, loc_manager:set_location(user_id, matches[2]), true)
|
2016-06-14 16:17:13 +02:00
|
|
|
return
|
|
|
|
elseif matches[1] == 'del' then
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_reply(msg, loc_manager:del_location(user_id), true)
|
2016-06-14 16:17:13 +02:00
|
|
|
return
|
|
|
|
else
|
|
|
|
local set_location = get_location(user_id)
|
|
|
|
if not set_location then
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_reply(msg, '*Du hast keinen Ort gesetzt!*', true)
|
2016-06-14 16:17:13 +02:00
|
|
|
return
|
|
|
|
else
|
|
|
|
local coords = utilities.get_coords(set_location, config)
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_location(msg.chat.id, coords.lat, coords.lon, msg.message_id)
|
|
|
|
utilities.send_reply(msg, 'Gesetzter Wohnort: *'..set_location..'*', true)
|
2016-06-14 16:17:13 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return loc_manager
|