From af949de741f6dfd775773a73d65718e9a7830663 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Fri, 8 Jun 2018 11:27:44 +0200 Subject: [PATCH] =?UTF-8?q?Flere=20sammenligningsord=20og=20tilf=C3=B8jet?= =?UTF-8?q?=20interval=20mellem=20farvel=20reaktioner.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.lua | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/main.lua b/main.lua index 08bf810..af2faab 100644 --- a/main.lua +++ b/main.lua @@ -9,6 +9,8 @@ local MEME_OUTPUT = OUTPUT_PATH..'meme.png' local SERVER_DIR = '/var/shots/b/' local IMAGE_URL_DIR = 'https://dcav.pw/b' +local FARVEL_INTERVAL = 90 + -------------------------------------------------------------------------------- -- Meme utils @@ -289,11 +291,23 @@ local function reverse (l0) return l end -local COMP_SENTENCES = { - '{A} er bedre end {B}', - '{A} er meget bedre end {B}', - '{B} er dårligere end {A}', -} +local COMP_SENTENCES do + local ORD_MED_ATTITYDE = { + bedre = 'positiv', + dårligere = 'negativ' + hurtigere = 'positiv' + langsommere = 'negativt' + robust = 'positivt' + } + local COMP_SENTENCES = {} + for ord, attityde in pairs(ORD_MED_ATTITYDE) do + local first, second = '{A}', '{B}' + if attityde == 'negativ' then first, second = second, first end + for _, fmt in ipairs { '%s er %s end %s', '%s er mere %s end %s', '%s er meget %s end %s', '%s %s end %s' } do + table.insert(COMP_SENTENCES, fmt:format(first, ord, second)) + end + end +end for sentence_i, sentence in ipairs(COMP_SENTENCES) do local A_pos, B_pos = sentence:find '{A}', sentence:find '{B}' @@ -364,6 +378,8 @@ local function escape_pattern (text) return text:gsub('[+-?*]', '%%%1') end +local FORRIGE_FARVEL = 0 + local function handle_message(bot, user, channel, message) -- Direct commands if message:lower():match('^'..escape_pattern(BOT_NICK)..'%f[%A]') then @@ -386,14 +402,17 @@ local function handle_message(bot, user, channel, message) end -- Farvel msg - for farvel_fmt, possible_answeres in pairs(FARVEL) do - if message:match('%f[%a]'..farvel_fmt..'%f[%A]') then - human_delay() - local answer = possible_answeres[math.random(#possible_answeres)] - .. (math.random() < 0.5 and ', '..user.nick or '') - .. (math.random() < 0.5 and '!' or '') - bot:sendChat(channel, answer) - return 'SES' + if FORRIGE_FARVEL + FARVEL_INTERVAL < os.time() then + for farvel_fmt, possible_answeres in pairs(FARVEL) do + if message:match('%f[%a]'..farvel_fmt..'%f[%A]') then + human_delay() + local answer = possible_answeres[math.random(#possible_answeres)] + .. (math.random() < 0.5 and ', '..user.nick or '') + .. (math.random() < 0.5 and '!' or '') + bot:sendChat(channel, answer) + FORRIGE_FARVEL = os.time() + return 'SES' + end end end