Vil opføre sig ordentlig, og undgå at spamme.

This commit is contained in:
Jon Michael Aanes 2018-06-08 19:25:57 +02:00
parent 6d3faf178a
commit ae5ed523d0

View File

@ -20,7 +20,8 @@ if CONFIG.LUA_EXTRA_CPATH then package.cpath = package.cpath .. CONFIG.LUA_EXTR
--------------------------------------------------------------------------------
-- Constants
local FARVEL_INTERVAL = 90
local FARVEL_INTERVAL = 60
local MEME_INTERVAL = 30
--------------------------------------------------------------------------------
-- Make sure all required modules can be loaded
@ -486,13 +487,14 @@ local function escape_pattern (text)
end
local FORRIGE_FARVEL = 0
local FORRIGE_MEME = 0
local function handle_message(bot, user, channel, message)
local function handle_message(bot, user, channel, message, is_slow_channel)
-- Direct commands
if message:lower():match('^'..escape_pattern(CONFIG.IRC_NICK)..'%f[%A]') then
local msg = message:sub(#CONFIG.IRC_NICK+1)
if msg:match '%s*join%s+(#%a)' then
local channel = msg:match '^%s*join%s+(#%a+)%s*$'
if msg:match '^%s*join%s+(#..-)%s*$' then
local channel = msg:match '^%s*join%s+(#..-)%s*$'
bot:sendChat(channel, "Will do! I'll join "..tostring(channel))
join_channel(channel)
else
@ -501,13 +503,6 @@ local function handle_message(bot, user, channel, message)
return 'BOT'
end
-- Bait msg
if message:match '%f[%a]bait%f[%A]' then
human_delay()
bot:sendChat(channel, generate_bait_link())
return 'BAIT'
end
-- Farvel msg
if FORRIGE_FARVEL + FARVEL_INTERVAL < os.time() then
for farvel_fmt, possible_answeres in pairs(FARVEL) do
@ -523,6 +518,20 @@ local function handle_message(bot, user, channel, message)
end
end
-- Rest of this function is memes
-- Memes are restricted, a bit.
if is_slow_channel then
if not (FORRIGE_MEME + MEME_INTERVAL < os.time()) then return 'NOMEME' end
FORRIGE_MEME = os.time()
end
-- Bait msg
if message:match '%f[%a]bait%f[%A]' then
human_delay()
bot:sendChat(channel, generate_bait_link())
return 'BAIT'
end
-- Comparison memes
local topics = get_topics_from_comparison_message(message)
if not topics then return end
@ -546,11 +555,14 @@ local function handle_message(bot, user, channel, message)
return 'BRAIN'
end
local DEBUG_CHANNEL = '#bot-test'
bot:hook("OnChat", function(user, channel, message)
local is_slow_channel = not (user == CONFIG.IRC_NICK or channel == DEBUG_CHANNEL)
if channel == CONFIG.IRC_NICK then channel = user.nick end
io.write '...\r'
io.flush()
local success, status = pcall(handle_message, bot, user, channel, message)
local success, status = pcall(handle_message, bot, user, channel, message, is_slow_channel)
-- Handle error
if not success then