|
|
|
@ -11,54 +11,56 @@ function remind:init(config)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function remind:action(msg)
|
|
|
|
|
-- Ensure there are arguments. If not, send doc.
|
|
|
|
|
local input = utilities.input(msg.text)
|
|
|
|
|
if not input then
|
|
|
|
|
utilities.send_message(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
-- Ensure first arg is a number. If not, send doc.
|
|
|
|
|
local duration = utilities.get_word(input, 1)
|
|
|
|
|
if not tonumber(duration) then
|
|
|
|
|
utilities.send_message(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
-- Duration must be between one minute and one year (approximately).
|
|
|
|
|
duration = tonumber(duration)
|
|
|
|
|
if duration < 1 then
|
|
|
|
|
duration = 1
|
|
|
|
|
elseif duration > 526000 then
|
|
|
|
|
duration = 526000
|
|
|
|
|
end
|
|
|
|
|
-- Ensure there is a second arg.
|
|
|
|
|
local message = utilities.input(input)
|
|
|
|
|
if not message then
|
|
|
|
|
utilities.send_message(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
-- Make a database entry for the group/user if one does not exist.
|
|
|
|
|
self.database.reminders[msg.chat.id_str] = self.database.reminders[msg.chat.id_str] or {}
|
|
|
|
|
-- Limit group reminders to 10 and private reminders to 50.
|
|
|
|
|
if msg.chat.type ~= 'private' and utilities.table_size(self.database.reminders[msg.chat.id_str]) > 9 then
|
|
|
|
|
utilities.send_reply(self, msg, 'Diese Gruppe hat schon zehn Erinnerungen!')
|
|
|
|
|
return
|
|
|
|
|
elseif msg.chat.type == 'private' and utilities.table_size(self.database.reminders[msg.chat.id_str]) > 49 then
|
|
|
|
|
utilities.send_reply(msg, 'Du hast schon 50 Erinnerungen!')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
-- Put together the reminder with the expiration, message, and message to reply to.
|
|
|
|
|
local reminder = {
|
|
|
|
|
time = os.time() + duration * 60,
|
|
|
|
|
message = message
|
|
|
|
|
}
|
|
|
|
|
table.insert(self.database.reminders[msg.chat.id_str], reminder)
|
|
|
|
|
local output = 'Ich werde dich in ' .. duration
|
|
|
|
|
if duration == 1 then
|
|
|
|
|
output = output .. ' Minute erinnern!'
|
|
|
|
|
else
|
|
|
|
|
output = output .. ' Minuten erinnern!'
|
|
|
|
|
end
|
|
|
|
|
utilities.send_reply(self, msg, output)
|
|
|
|
|
-- Ensure there are arguments. If not, send doc.
|
|
|
|
|
local input = utilities.input(msg.text)
|
|
|
|
|
if not input then
|
|
|
|
|
utilities.send_message(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Ensure first arg is a number. If not, send doc.
|
|
|
|
|
local duration = utilities.get_word(input, 1)
|
|
|
|
|
if not tonumber(duration) then
|
|
|
|
|
utilities.send_message(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Duration must be between one minute and one day (approximately).
|
|
|
|
|
duration = tonumber(duration)
|
|
|
|
|
if duration < 1 then
|
|
|
|
|
duration = 1
|
|
|
|
|
elseif duration > 1440 then
|
|
|
|
|
duration = 1440
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Ensure there is a second arg.
|
|
|
|
|
local message = utilities.input(input)
|
|
|
|
|
if not message then
|
|
|
|
|
utilities.send_message(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Make a database entry for the group/user if one does not exist.
|
|
|
|
|
self.database.reminders[msg.chat.id_str] = self.database.reminders[msg.chat.id_str] or {}
|
|
|
|
|
-- Limit group reminders to 10 and private reminders to 50.
|
|
|
|
|
if msg.chat.type ~= 'private' and utilities.table_size(self.database.reminders[msg.chat.id_str]) > 9 then
|
|
|
|
|
utilities.send_reply(self, msg, 'Diese Gruppe hat schon zehn Erinnerungen!')
|
|
|
|
|
return
|
|
|
|
|
elseif msg.chat.type == 'private' and utilities.table_size(self.database.reminders[msg.chat.id_str]) > 49 then
|
|
|
|
|
utilities.send_reply(msg, 'Du hast schon 50 Erinnerungen!')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Put together the reminder with the expiration, message, and message to reply to.
|
|
|
|
|
local timestamp = os.time() + duration * 60
|
|
|
|
|
local reminder = {
|
|
|
|
|
time = timestamp,
|
|
|
|
|
message = message
|
|
|
|
|
}
|
|
|
|
|
table.insert(self.database.reminders[msg.chat.id_str], reminder)
|
|
|
|
|
local human_readable_time = convert_timestamp(timestamp, '%H:%M:%S')
|
|
|
|
|
local output = 'Ich werde dich um *'..human_readable_time..' Uhr* erinnern.'
|
|
|
|
|
utilities.send_reply(self, msg, output, true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function remind:cron()
|
|
|
|
|