Better merge and made nick configurable.
This commit is contained in:
parent
311ac33807
commit
1e24a12504
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
return {
|
return {
|
||||||
-- IRC connection
|
-- IRC connection
|
||||||
|
IRC_NICK = 'memebot',
|
||||||
|
|
||||||
IRC_SERVER = 'some-domain.com',
|
IRC_SERVER = 'some-domain.com',
|
||||||
IRC_PORT = 6697,
|
IRC_PORT = 6697,
|
||||||
IRC_SECURE = true, -- If using SSL
|
IRC_SECURE = true, -- If using SSL
|
||||||
|
|
40
main.lua
40
main.lua
|
@ -3,13 +3,21 @@
|
||||||
|
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
|
|
||||||
local CONFIG = require 'config'
|
local CONFIG do
|
||||||
|
local success, config_or_error = pcall(require, 'config')
|
||||||
|
if not success then
|
||||||
|
error('Could not load config file: "./config.lua".\n'..config_or_error..'\nCould be that the config files doesn\'t exist. Make sure one exists, and try again.')
|
||||||
|
end
|
||||||
|
CONFIG = config_or_error
|
||||||
|
end
|
||||||
|
|
||||||
if CONFIG.LUA_EXTRA_PATH then package.path = package.path .. CONFIG.LUA_EXTRA_PATH end
|
if CONFIG.LUA_EXTRA_PATH then package.path = package.path .. CONFIG.LUA_EXTRA_PATH end
|
||||||
if CONFIG.LUA_EXTRA_CPATH then package.cpath = package.cpath .. CONFIG.LUA_EXTRA_CPATH end
|
if CONFIG.LUA_EXTRA_CPATH then package.cpath = package.cpath .. CONFIG.LUA_EXTRA_CPATH end
|
||||||
|
|
||||||
local FARVEL_INTERVAL = 90
|
local FARVEL_INTERVAL = 90
|
||||||
|
|
||||||
|
-- TODO: Invite to bogus channels
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Meme utils
|
-- Meme utils
|
||||||
|
|
||||||
|
@ -262,9 +270,7 @@ end
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
local BOT_NICK = 'ro-bot'
|
local bot = irc.new { nick = CONFIG.IRC_NICK }
|
||||||
|
|
||||||
local bot = irc.new { nick = BOT_NICK }
|
|
||||||
|
|
||||||
local FARVEL = {
|
local FARVEL = {
|
||||||
['[Ff]arvel'] = {'ses', 'farvel'},
|
['[Ff]arvel'] = {'ses', 'farvel'},
|
||||||
|
@ -304,12 +310,12 @@ end
|
||||||
local COMP_SENTENCES do
|
local COMP_SENTENCES do
|
||||||
local ORD_MED_ATTITYDE = {
|
local ORD_MED_ATTITYDE = {
|
||||||
bedre = 'positiv',
|
bedre = 'positiv',
|
||||||
dårligere = 'negativ'
|
dårligere = 'negativ',
|
||||||
hurtigere = 'positiv'
|
hurtigere = 'positiv',
|
||||||
langsommere = 'negativt'
|
langsommere = 'negativt',
|
||||||
robust = 'positivt'
|
robust = 'positivt',
|
||||||
}
|
}
|
||||||
local COMP_SENTENCES = {}
|
COMP_SENTENCES = {}
|
||||||
for ord, attityde in pairs(ORD_MED_ATTITYDE) do
|
for ord, attityde in pairs(ORD_MED_ATTITYDE) do
|
||||||
local first, second = '{A}', '{B}'
|
local first, second = '{A}', '{B}'
|
||||||
if attityde == 'negativ' then first, second = second, first end
|
if attityde == 'negativ' then first, second = second, first end
|
||||||
|
@ -373,7 +379,7 @@ local ERROR_MSG = {
|
||||||
}
|
}
|
||||||
|
|
||||||
bot:hook('OnJoin', function(user, channel)
|
bot:hook('OnJoin', function(user, channel)
|
||||||
if user.nick == BOT_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
|
||||||
|
@ -394,8 +400,8 @@ local FORRIGE_FARVEL = 0
|
||||||
|
|
||||||
local function handle_message(bot, user, channel, message)
|
local function handle_message(bot, user, channel, message)
|
||||||
-- Direct commands
|
-- Direct commands
|
||||||
if message:lower():match('^'..escape_pattern(BOT_NICK)..'%f[%A]') then
|
if message:lower():match('^'..escape_pattern(CONFIG.IRC_NICK)..'%f[%A]') then
|
||||||
local msg = message:sub(#BOT_NICK+1)
|
local msg = message:sub(#CONFIG.IRC_NICK+1)
|
||||||
if msg:match '%s*join%s+(#%a)' then
|
if msg:match '%s*join%s+(#%a)' then
|
||||||
local channel = msg:match '^%s*join%s+(#%a+)%s*$'
|
local channel = msg:match '^%s*join%s+(#%a+)%s*$'
|
||||||
bot:sendChat(channel, "Will do! I'll join "..tostring(channel))
|
bot:sendChat(channel, "Will do! I'll join "..tostring(channel))
|
||||||
|
@ -452,7 +458,7 @@ local function handle_message(bot, user, channel, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
bot:hook("OnChat", function(user, channel, message)
|
bot:hook("OnChat", function(user, channel, message)
|
||||||
if channel == BOT_NICK then channel = user.nick end
|
if channel == CONFIG.IRC_NICK then channel = user.nick end
|
||||||
io.write '...\r'
|
io.write '...\r'
|
||||||
io.flush()
|
io.flush()
|
||||||
local success, status = pcall(handle_message, bot, user, channel, message)
|
local success, status = pcall(handle_message, bot, user, channel, message)
|
||||||
|
@ -477,9 +483,6 @@ bot:hook('OnRaw', function (line)
|
||||||
io.write((" [RAW]: %s\n"):format(line))
|
io.write((" [RAW]: %s\n"):format(line))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
-- TODO: Invite to bogus channels
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Main run
|
-- Main run
|
||||||
|
|
||||||
|
@ -490,14 +493,13 @@ bot:connect {
|
||||||
secure = CONFIG.IRC_SECURE,
|
secure = CONFIG.IRC_SECURE,
|
||||||
}
|
}
|
||||||
|
|
||||||
io.write ('Memebot has started up as "'..BOT_NICK..'"\n')
|
io.write ('Memebot has started up as "'..CONFIG.IRC_NICK..'"\n')
|
||||||
|
|
||||||
assert(CONFIG.IRC_CHANNELS == nil or type(CONFIG.IRC_CHANNELS) == 'table')
|
assert(CONFIG.IRC_CHANNELS == nil or type(CONFIG.IRC_CHANNELS) == 'table')
|
||||||
for _, channel in ipairs(CONFIG.IRC_CHANNELS or {}) do
|
for _, channel in ipairs(CONFIG.IRC_CHANNELS or {}) do
|
||||||
bot:join(channel)
|
bot:join(channel)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
bot:think()
|
bot:think()
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
|
@ -507,7 +509,7 @@ end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
if ... then
|
if ... then
|
||||||
error 'Cannot be loaded like library'
|
error 'Cannot load Memebot as a library'
|
||||||
else
|
else
|
||||||
init_memebot()
|
init_memebot()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user