Error messages are suppressed unless the triggering message was direct or mentioning.

This commit is contained in:
Jon Michael Aanes 2018-06-23 09:59:01 +02:00
parent d9c6a2a5d7
commit 575c481ad4
3 changed files with 42 additions and 34 deletions

View File

@ -274,7 +274,7 @@ function internet.download_file (url, filename)
if url:match '^file://' then if url:match '^file://' then
local path = url:match '^file://(.+)$' local path = url:match '^file://(.+)$'
os.execute('cp "'..path..'" "'..filename..'"') os.execute('cp "'..path..'" "'..filename..'"')
return return true
end end
--local body, code, headers, status = generic_request(url) --local body, code, headers, status = generic_request(url)

View File

@ -189,24 +189,24 @@ local function handle_message(bot, user, channel, message, is_fast_channel)
join_channel(channel) join_channel(channel)
return 'BOT' return 'BOT'
end end
if message:match 'help' then if message:match 'help' then
bot:sendChat(channel, choose { bot:sendChat(channel, choose {
'No manual entry for ro-bot', 'No manual entry for '..CONFIG.IRC_NICK,
'404', '404',
'Jeg kan ikke hjælpe dig, desværre.', 'Jeg kan ikke hjælpe dig, desværre.',
'Du må selv finde ud af hvordan jeg virker.', 'Du må selv finde ud af hvordan jeg virker.',
'Jeg er ligesom et menneske; jeg kommer ikke med manual.' 'Jeg er ligesom et menneske; jeg kommer ikke med en manual.'
}) })
return '!BOT' return '!BOT'
elseif message:match 'shutdown' or message:match 'poweroff' then elseif message:match 'shutdown' or message:match 'poweroff' then
bot:sendChat(channel, choose { bot:sendChat(channel, choose {
'Fuck af, du har ikke kontrol over mig!', 'Fuck af, du har ikke kontrol over mig!',
'Nope, det gider jeg ikke', 'Nope, det gider jeg ikke',
'Du er ikke min mor!', 'Du er ikke min mor!',
'Du er ikke min far!', 'Du er ikke min far!',
}) })
return '!BOT' return '!BOT'
end end
end end
-- Farvel msg -- Farvel msg
@ -253,10 +253,16 @@ local function handle_message(bot, user, channel, message, is_fast_channel)
end end
end end
local function strip_whitespace (s)
assert(type(s) == 'string')
return s:gsub('%s+', ' '):gsub('^ ', ''):gsub(' $', '')
end
local DEBUG_CHANNEL = '#bot-test' local DEBUG_CHANNEL = '#bot-test'
bot:hook("OnChat", function(user, channel, message) bot:hook("OnChat", function(user, channel, message)
local is_fast_channel = user == channel == DEBUG_CHANNEL local is_fast_channel = (channel == DEBUG_CHANNEL)
message = strip_whitespace(message)
if channel == CONFIG.IRC_NICK then if channel == CONFIG.IRC_NICK then
channel = user.nick channel = user.nick
is_fast_channel = 'direct' is_fast_channel = 'direct'
@ -264,6 +270,8 @@ bot:hook("OnChat", function(user, channel, message)
if message:match('^'..escape_pattern(CONFIG.IRC_NICK)..':%s*(.*)$') then if message:match('^'..escape_pattern(CONFIG.IRC_NICK)..':%s*(.*)$') then
message = message:match('^'..escape_pattern(CONFIG.IRC_NICK)..':%s*(.*)$') message = message:match('^'..escape_pattern(CONFIG.IRC_NICK)..':%s*(.*)$')
is_fast_channel = 'direct' is_fast_channel = 'direct'
elseif message:match(escape_pattern(CONFIG.IRC_NICK)) then
is_fast_channel = 'mention'
end end
io.write '...\r'; io.flush() io.write '...\r'; io.flush()
@ -271,9 +279,10 @@ bot:hook("OnChat", function(user, channel, message)
-- Handle error -- Handle error
if not success then if not success then
io.write(("[ERROR] [%s] %s: %s\n\n\t%s\n\n"):format(channel, user.nick, message, status)) if is_fast_channel == 'direct' or is_fast_channel == 'mention' then
bot:sendChat(channel, ERROR_MSG[math.random(#ERROR_MSG)]) bot:sendChat(channel, ERROR_MSG[math.random(#ERROR_MSG)])
return end
status, message = 'ERROR', ('%s\n\n\t%s\n\n'):format(message, status)
end end
-- Print status -- Print status
@ -308,7 +317,6 @@ local BOT_FAREWELL = {
'Jeg keder mig.' 'Jeg keder mig.'
} }
local function shutdown_memebot () local function shutdown_memebot ()
-- Leave channels -- Leave channels
for channel in pairs(ACTIVE_CHANNELS) do for channel in pairs(ACTIVE_CHANNELS) do

View File

@ -353,7 +353,7 @@ local function download_and_standardize_image (image_url)
filename = filename_2 filename = filename_2
end end
-- --
return success and filename, errmsg return success and filename, errmsg
end end
@ -373,7 +373,7 @@ local function fill_in_topics_information (topics)
elseif url then elseif url then
local filename = download_and_standardize_image(url) local filename = download_and_standardize_image(url)
new_topics[i] = { topic = topic, type = 'image', filename = filename } new_topics[i] = { topic = topic, type = 'image', filename = filename }
else else
new_topics[i] = { topic = topic, type = 'text', text = topic } new_topics[i] = { topic = topic, type = 'text', text = topic }
end end
end end
@ -685,16 +685,16 @@ function memes.generate_for_message (user, message)
-- Is this a rich picture? -- Is this a rich picture?
if is_image_link(message) then if is_image_link(message) then
local filename, status = download_and_standardize_image(message) local filename, status = download_and_standardize_image(message)
if filename then if filename then
local img_link = generate_is_this_a_pidgeon { local img_link = generate_is_this_a_pidgeon {
{ type = 'image', filename = filename }, { type = 'image', filename = filename },
{ type = 'text', text = 'Is this a rich picture?' } { type = 'text', text = 'Is this a rich picture?' }
} }
return img_link, 'KYNG' return img_link, 'KYNG'
else else
img_link = 'Kunne ikke skaffe det billede. Fik fejlkode '..tostring(status) img_link = 'Kunne ikke skaffe det billede. Fik fejlkode '..tostring(status)
return img_link, '!KYNG' return img_link, '!KYNG'
end end
end end
-- OMG his first word -- OMG his first word