Bugfix für handle_exception() und Crons

This commit is contained in:
Andreas Bielawski 2016-08-24 15:54:16 +02:00
parent fb9d3652f3
commit 49dd18ce3f
2 changed files with 16 additions and 10 deletions

View File

@ -221,9 +221,9 @@ function bot:run(config)
for n=1, #self.plugins do for n=1, #self.plugins do
local v = self.plugins[n] local v = self.plugins[n]
if v.cron then -- Call each plugin's cron function, if it has one. if v.cron then -- Call each plugin's cron function, if it has one.
local result, err = pcall(function() v.cron(config) end) local result, err = pcall(function() v.cron(self, config) end)
if not result then if not result then
utilities.handle_exception(err, 'CRON: ' .. n, config.log_chat) utilities.handle_exception(self, err, 'CRON: ' .. n, config.log_chat)
end end
end end
end end

View File

@ -499,14 +499,20 @@ function utilities:resolve_username(input)
end end
function utilities:handle_exception(err, message, log_chat) function utilities:handle_exception(err, message, log_chat)
if not err then err = '' end local output = string.format(
local output = '\n[' .. os.date('%F %T', os.time()) .. ']\n' .. self.info.username .. ': ' .. err .. '\n' .. message .. '\n' '[%s]\n%s: %s\n%s\n',
os.date('%F %T'),
self.info.username,
err or '',
message
)
if log_chat then if log_chat then
output = '<code>' .. utilities.html_escape(output) .. '</code>' output = '<code>' .. utilities.html_escape(output) .. '</code>'
return utilities.send_message(log_chat, output, true, nil, 'html') return utilities.send_message(log_chat, output, true, nil, 'html')
else else
print(output) print(output)
end end
end end
-- MOVED TO DOWNLOAD_TO_FILE -- MOVED TO DOWNLOAD_TO_FILE