Fi, Fix und nochmal Fix

This commit is contained in:
Andreas Bielawski 2016-08-02 01:01:06 +02:00
parent 206c06937a
commit 49824fcb26
4 changed files with 53 additions and 51 deletions

View File

@ -26,7 +26,7 @@ function gSearch:googlethat(query, config)
utilities.send_reply(self, msg, config.errors.connection) utilities.send_reply(self, msg, config.errors.connection)
return return
end end
local data = JSON.decode(res) local data = json.decode(res)
if data.searchInformation.formattedTotalResults == "0" then return nil end if data.searchInformation.formattedTotalResults == "0" then return nil end
local results={} local results={}

View File

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

View File

@ -23,7 +23,7 @@ function leave_group:check_for_admin(msg, self, config)
end end
end end
function leave_group:action(msg) function leave_group:action(msg, config)
if not is_service_msg(msg) then return end -- Bad attempt at trolling! if not is_service_msg(msg) then return end -- Bad attempt at trolling!
local admin_in_group = leave_group:check_for_admin(msg, self, config) local admin_in_group = leave_group:check_for_admin(msg, self, config)
if not admin_in_group then if not admin_in_group then

View File

@ -254,7 +254,7 @@ function utilities.trim(str)
return s return s
end end
-- Retruns true if the string is empty -- Returns true if the string is empty
function string:isempty() function string:isempty()
return self == nil or self == '' return self == nil or self == ''
end end