Error messages are suppressed unless the triggering message was direct or mentioning.
This commit is contained in:
parent
d9c6a2a5d7
commit
575c481ad4
|
@ -274,7 +274,7 @@ function internet.download_file (url, filename)
|
|||
if url:match '^file://' then
|
||||
local path = url:match '^file://(.+)$'
|
||||
os.execute('cp "'..path..'" "'..filename..'"')
|
||||
return
|
||||
return true
|
||||
end
|
||||
|
||||
--local body, code, headers, status = generic_request(url)
|
||||
|
|
50
main.lua
50
main.lua
|
@ -189,24 +189,24 @@ local function handle_message(bot, user, channel, message, is_fast_channel)
|
|||
join_channel(channel)
|
||||
return 'BOT'
|
||||
end
|
||||
if message:match 'help' then
|
||||
bot:sendChat(channel, choose {
|
||||
'No manual entry for ro-bot',
|
||||
'404',
|
||||
'Jeg kan ikke hjælpe dig, desværre.',
|
||||
'Du må selv finde ud af hvordan jeg virker.',
|
||||
'Jeg er ligesom et menneske; jeg kommer ikke med manual.'
|
||||
})
|
||||
if message:match 'help' then
|
||||
bot:sendChat(channel, choose {
|
||||
'No manual entry for '..CONFIG.IRC_NICK,
|
||||
'404',
|
||||
'Jeg kan ikke hjælpe dig, desværre.',
|
||||
'Du må selv finde ud af hvordan jeg virker.',
|
||||
'Jeg er ligesom et menneske; jeg kommer ikke med en manual.'
|
||||
})
|
||||
return '!BOT'
|
||||
elseif message:match 'shutdown' or message:match 'poweroff' then
|
||||
bot:sendChat(channel, choose {
|
||||
'Fuck af, du har ikke kontrol over mig!',
|
||||
'Nope, det gider jeg ikke',
|
||||
'Du er ikke min mor!',
|
||||
'Du er ikke min far!',
|
||||
})
|
||||
elseif message:match 'shutdown' or message:match 'poweroff' then
|
||||
bot:sendChat(channel, choose {
|
||||
'Fuck af, du har ikke kontrol over mig!',
|
||||
'Nope, det gider jeg ikke',
|
||||
'Du er ikke min mor!',
|
||||
'Du er ikke min far!',
|
||||
})
|
||||
return '!BOT'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Farvel msg
|
||||
|
@ -253,10 +253,16 @@ local function handle_message(bot, user, channel, message, is_fast_channel)
|
|||
end
|
||||
end
|
||||
|
||||
local function strip_whitespace (s)
|
||||
assert(type(s) == 'string')
|
||||
return s:gsub('%s+', ' '):gsub('^ ', ''):gsub(' $', '')
|
||||
end
|
||||
|
||||
local DEBUG_CHANNEL = '#bot-test'
|
||||
|
||||
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
|
||||
channel = user.nick
|
||||
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
|
||||
message = message:match('^'..escape_pattern(CONFIG.IRC_NICK)..':%s*(.*)$')
|
||||
is_fast_channel = 'direct'
|
||||
elseif message:match(escape_pattern(CONFIG.IRC_NICK)) then
|
||||
is_fast_channel = 'mention'
|
||||
end
|
||||
|
||||
io.write '...\r'; io.flush()
|
||||
|
@ -271,9 +279,10 @@ bot:hook("OnChat", function(user, channel, message)
|
|||
|
||||
-- Handle error
|
||||
if not success then
|
||||
io.write(("[ERROR] [%s] %s: %s\n\n\t%s\n\n"):format(channel, user.nick, message, status))
|
||||
bot:sendChat(channel, ERROR_MSG[math.random(#ERROR_MSG)])
|
||||
return
|
||||
if is_fast_channel == 'direct' or is_fast_channel == 'mention' then
|
||||
bot:sendChat(channel, ERROR_MSG[math.random(#ERROR_MSG)])
|
||||
end
|
||||
status, message = 'ERROR', ('%s\n\n\t%s\n\n'):format(message, status)
|
||||
end
|
||||
|
||||
-- Print status
|
||||
|
@ -308,7 +317,6 @@ local BOT_FAREWELL = {
|
|||
'Jeg keder mig.'
|
||||
}
|
||||
|
||||
|
||||
local function shutdown_memebot ()
|
||||
-- Leave channels
|
||||
for channel in pairs(ACTIVE_CHANNELS) do
|
||||
|
|
24
memes.lua
24
memes.lua
|
@ -353,7 +353,7 @@ local function download_and_standardize_image (image_url)
|
|||
filename = filename_2
|
||||
end
|
||||
--
|
||||
|
||||
|
||||
return success and filename, errmsg
|
||||
end
|
||||
|
||||
|
@ -373,7 +373,7 @@ local function fill_in_topics_information (topics)
|
|||
elseif url then
|
||||
local filename = download_and_standardize_image(url)
|
||||
new_topics[i] = { topic = topic, type = 'image', filename = filename }
|
||||
else
|
||||
else
|
||||
new_topics[i] = { topic = topic, type = 'text', text = topic }
|
||||
end
|
||||
end
|
||||
|
@ -685,16 +685,16 @@ function memes.generate_for_message (user, message)
|
|||
-- Is this a rich picture?
|
||||
if is_image_link(message) then
|
||||
local filename, status = download_and_standardize_image(message)
|
||||
if filename then
|
||||
local img_link = generate_is_this_a_pidgeon {
|
||||
{ type = 'image', filename = filename },
|
||||
{ type = 'text', text = 'Is this a rich picture?' }
|
||||
}
|
||||
return img_link, 'KYNG'
|
||||
else
|
||||
img_link = 'Kunne ikke skaffe det billede. Fik fejlkode '..tostring(status)
|
||||
return img_link, '!KYNG'
|
||||
end
|
||||
if filename then
|
||||
local img_link = generate_is_this_a_pidgeon {
|
||||
{ type = 'image', filename = filename },
|
||||
{ type = 'text', text = 'Is this a rich picture?' }
|
||||
}
|
||||
return img_link, 'KYNG'
|
||||
else
|
||||
img_link = 'Kunne ikke skaffe det billede. Fik fejlkode '..tostring(status)
|
||||
return img_link, '!KYNG'
|
||||
end
|
||||
end
|
||||
|
||||
-- OMG his first word
|
||||
|
|
Loading…
Reference in New Issue
Block a user