Mindre spammy på alle fronter
This commit is contained in:
parent
33b6ed79fe
commit
f351bb0623
90
main.lua
90
main.lua
|
@ -22,6 +22,7 @@ if CONFIG.LUA_EXTRA_CPATH then package.cpath = package.cpath .. CONFIG.LUA_EXTR
|
||||||
|
|
||||||
local FARVEL_INTERVAL = 120
|
local FARVEL_INTERVAL = 120
|
||||||
local MEME_INTERVAL = 30
|
local MEME_INTERVAL = 30
|
||||||
|
local MEME_CHANCE = 0.3
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Make sure all required modules can be loaded
|
-- Make sure all required modules can be loaded
|
||||||
|
@ -551,18 +552,59 @@ local ERROR_MSG = {
|
||||||
'Do androids dream of electric sheep?',
|
'Do androids dream of electric sheep?',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local HILSNER = {
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hej, %s',
|
||||||
|
'Hejsa, %s!',
|
||||||
|
'Hovsa, der var en %s',
|
||||||
|
'Long time no see, %s',
|
||||||
|
}
|
||||||
|
|
||||||
|
local LAST_USER_LOGIN
|
||||||
|
local LAST_TIME_USER_LOGGED_OUT = {}
|
||||||
|
local IRC_ALLOWED_TIMEOUT = 20 --20 * 60
|
||||||
|
|
||||||
bot:hook('OnJoin', function(user, channel)
|
bot:hook('OnJoin', function(user, channel)
|
||||||
|
io.write '...\r'; io.flush()
|
||||||
|
--
|
||||||
if user.nick == CONFIG.IRC_NICK then
|
if user.nick == CONFIG.IRC_NICK then
|
||||||
-- On self join
|
-- On self join
|
||||||
io.write(string.format(' !! Joined %s\n', channel))
|
io.write(string.format(' !! Joined %s\n', channel))
|
||||||
if #imlib.font.list_fonts() == 0 then
|
if #imlib.font.list_fonts() == 0 then
|
||||||
common_error(channel, 'Hjælp! Min computer har ingen fonts! Hvorfor er fonts så svære på linux? Jeg har kigget i: "'..table.concat(imlib.font.list_paths(), '", "')..'"')
|
common_error(channel, 'Hjælp! Min computer har ingen fonts! Hvorfor er fonts så svære på linux? Jeg har kigget i: "'..table.concat(imlib.font.list_paths(), '", "')..'"')
|
||||||
end
|
end
|
||||||
else
|
elseif user.nick ~= LAST_USER_LOGIN and (LAST_TIME_USER_LOGGED_OUT[user.nick] or 0) + IRC_ALLOWED_TIMEOUT < os.time() then
|
||||||
-- On other join
|
-- On other join
|
||||||
|
-- And that user wasn't the last one to join
|
||||||
|
-- And that user haven't been logged in for IRC_ALLOWED_TIMEOUT seconds.
|
||||||
|
LAST_USER_LOGIN = user.nick
|
||||||
human_delay()
|
human_delay()
|
||||||
bot:sendChat(channel, 'Hej, '..user.nick..'')
|
bot:sendChat(channel, choose(HILSNER):format(user.nick))
|
||||||
end
|
end
|
||||||
|
--
|
||||||
|
io.write ' \r'; io.flush()
|
||||||
|
end)
|
||||||
|
|
||||||
|
bot:hook('OnPart', function(user, channel)
|
||||||
|
assert(user)
|
||||||
|
if user.nick == CONFIG.IRC_NICK then return end
|
||||||
|
LAST_TIME_USER_LOGGED_OUT[user.nick] = os.time()
|
||||||
|
end)
|
||||||
|
|
||||||
|
bot:hook('OnQuit', function(user, message)
|
||||||
|
assert(user)
|
||||||
|
if user.nick == CONFIG.IRC_NICK then return end
|
||||||
|
LAST_TIME_USER_LOGGED_OUT[user.nick] = os.time()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function escape_pattern (text)
|
local function escape_pattern (text)
|
||||||
|
@ -573,18 +615,15 @@ local FORRIGE_FARVEL = 0
|
||||||
local FORRIGE_MEME = 0
|
local FORRIGE_MEME = 0
|
||||||
local BOT_INTRODUCTION = [[Jeg er %s, en eksperimentel meme-robot, designet til at sprede memes. Er dog lidt sky, så kan ikke aflsøre mine memes, du må bare lede.]]
|
local BOT_INTRODUCTION = [[Jeg er %s, en eksperimentel meme-robot, designet til at sprede memes. Er dog lidt sky, så kan ikke aflsøre mine memes, du må bare lede.]]
|
||||||
|
|
||||||
local function handle_message(bot, user, channel, message, is_slow_channel)
|
local function handle_message(bot, user, channel, message, is_fast_channel)
|
||||||
-- Direct commands
|
-- Direct commands
|
||||||
if message:lower():match('^'..escape_pattern(CONFIG.IRC_NICK)..'%f[%A]') then
|
if is_fast_channel == 'direct' then
|
||||||
local msg = message:sub(#CONFIG.IRC_NICK+1)
|
if message:match '^%s*join%s+(#..-)%s*$' then
|
||||||
if msg:match '^%s*join%s+(#..-)%s*$' then
|
local channel = message:match '^%s*join%s+(#..-)%s*$'
|
||||||
local channel = msg:match '^%s*join%s+(#..-)%s*$'
|
|
||||||
bot:sendChat(channel, "Det kan du tro! Jeg skal nok lige kigge indenom "..tostring(channel))
|
bot:sendChat(channel, "Det kan du tro! Jeg skal nok lige kigge indenom "..tostring(channel))
|
||||||
join_channel(channel)
|
join_channel(channel)
|
||||||
else
|
return 'BOT'
|
||||||
bot:sendChat(channel, ERROR_MSG[math.random(#ERROR_MSG)])
|
|
||||||
end
|
end
|
||||||
return 'BOT'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Farvel msg
|
-- Farvel msg
|
||||||
|
@ -603,7 +642,7 @@ local function handle_message(bot, user, channel, message, is_slow_channel)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Bot introduction
|
-- Bot introduction
|
||||||
if message:lower():match('%f[%a]hvem%f[%A]') and (message:lower():match('%f[%a]'..escape_pattern(CONFIG.IRC_NICK)..'%f[%A]') or not is_slow_channel and message:lower():match '%f[%a]du%f[%A]') then
|
if message:lower():match('%f[%a]hvem%f[%A]') and (message:lower():match('%f[%a]'..escape_pattern(CONFIG.IRC_NICK)..'%f[%A]') or is_fast_channel and message:lower():match '%f[%a]du%f[%A]') then
|
||||||
human_delay()
|
human_delay()
|
||||||
local msg = BOT_INTRODUCTION:format(CONFIG.IRC_NICK)
|
local msg = BOT_INTRODUCTION:format(CONFIG.IRC_NICK)
|
||||||
bot:sendChat(channel, msg)
|
bot:sendChat(channel, msg)
|
||||||
|
@ -611,9 +650,13 @@ local function handle_message(bot, user, channel, message, is_slow_channel)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Rest of this function is memes
|
-- Rest of this function is memes
|
||||||
-- Memes are restricted, a bit.
|
-- Memes are restricted, a bit, and wont trigger if:
|
||||||
if is_slow_channel then
|
-- 1. This is a slow channel, and the last meme was recently
|
||||||
if not (FORRIGE_MEME + MEME_INTERVAL < os.time()) then return 'NOMEME' end
|
-- 2. This is a non-direct channel, and the chance of memes are low.
|
||||||
|
if not is_fast_channel and not (FORRIGE_MEME + MEME_INTERVAL < os.time()) then
|
||||||
|
return 'NOMEME'
|
||||||
|
elseif is_fast_channel ~= 'direct' and math.random() >= MEME_CHANCE then
|
||||||
|
return 'LUCK'
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Bait msg
|
-- Bait msg
|
||||||
|
@ -670,11 +713,18 @@ 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_slow_channel = not (user == CONFIG.IRC_NICK or channel == DEBUG_CHANNEL)
|
local is_fast_channel = user == channel == DEBUG_CHANNEL
|
||||||
if channel == CONFIG.IRC_NICK then channel = user.nick end
|
if channel == CONFIG.IRC_NICK then
|
||||||
io.write '...\r'
|
channel = user.nick
|
||||||
io.flush()
|
is_fast_channel = 'direct'
|
||||||
local success, status = pcall(handle_message, bot, user, channel, message, is_slow_channel)
|
end
|
||||||
|
if message:match('^'..escape_pattern(CONFIG.IRC_NICK)..':%s*(.*)$') then
|
||||||
|
message = message:match('^'..escape_pattern(CONFIG.IRC_NICK)..':%s*(.*)$')
|
||||||
|
is_fast_channel = 'direct'
|
||||||
|
end
|
||||||
|
|
||||||
|
io.write '...\r'; io.flush()
|
||||||
|
local success, status = pcall(handle_message, bot, user, channel, message, is_fast_channel)
|
||||||
|
|
||||||
-- Handle error
|
-- Handle error
|
||||||
if not success then
|
if not success then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user