diff --git a/otouto/bot.lua b/otouto/bot.lua index 38ffed9..1b6c08c 100644 --- a/otouto/bot.lua +++ b/otouto/bot.lua @@ -221,9 +221,9 @@ function bot:run(config) for n=1, #self.plugins do local v = self.plugins[n] 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 - utilities.handle_exception(err, 'CRON: ' .. n, config.log_chat) + utilities.handle_exception(self, err, 'CRON: ' .. n, config.log_chat) end end end diff --git a/otouto/utilities.lua b/otouto/utilities.lua index 27f369b..36cfd7f 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -499,14 +499,20 @@ function utilities:resolve_username(input) end function utilities:handle_exception(err, message, log_chat) - if not err then err = '' end - local output = '\n[' .. os.date('%F %T', os.time()) .. ']\n' .. self.info.username .. ': ' .. err .. '\n' .. message .. '\n' - if log_chat then - output = '' .. utilities.html_escape(output) .. '' - return utilities.send_message(log_chat, output, true, nil, 'html') - else - print(output) - end + local output = string.format( + '[%s]\n%s: %s\n%s\n', + os.date('%F %T'), + self.info.username, + err or '', + message + ) + if log_chat then + output = '' .. utilities.html_escape(output) .. '' + return utilities.send_message(log_chat, output, true, nil, 'html') + else + print(output) + end + end -- MOVED TO DOWNLOAD_TO_FILE