Better merge and made nick configurable.
This commit is contained in:
parent
311ac33807
commit
1e24a12504
|
@ -1,6 +1,8 @@
|
|||
|
||||
return {
|
||||
-- IRC connection
|
||||
IRC_NICK = 'memebot',
|
||||
|
||||
IRC_SERVER = 'some-domain.com',
|
||||
IRC_PORT = 6697,
|
||||
IRC_SECURE = true, -- If using SSL
|
||||
|
|
40
main.lua
40
main.lua
|
@ -3,13 +3,21 @@
|
|||
|
||||
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_CPATH then package.cpath = package.cpath .. CONFIG.LUA_EXTRA_CPATH end
|
||||
|
||||
local FARVEL_INTERVAL = 90
|
||||
|
||||
-- TODO: Invite to bogus channels
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Meme utils
|
||||
|
||||
|
@ -262,9 +270,7 @@ end
|
|||
|
||||
----
|
||||
|
||||
local BOT_NICK = 'ro-bot'
|
||||
|
||||
local bot = irc.new { nick = BOT_NICK }
|
||||
local bot = irc.new { nick = CONFIG.IRC_NICK }
|
||||
|
||||
local FARVEL = {
|
||||
['[Ff]arvel'] = {'ses', 'farvel'},
|
||||
|
@ -304,12 +310,12 @@ end
|
|||
local COMP_SENTENCES do
|
||||
local ORD_MED_ATTITYDE = {
|
||||
bedre = 'positiv',
|
||||
dårligere = 'negativ'
|
||||
hurtigere = 'positiv'
|
||||
langsommere = 'negativt'
|
||||
robust = 'positivt'
|
||||
dårligere = 'negativ',
|
||||
hurtigere = 'positiv',
|
||||
langsommere = 'negativt',
|
||||
robust = 'positivt',
|
||||
}
|
||||
local COMP_SENTENCES = {}
|
||||
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
|
||||
|
@ -373,7 +379,7 @@ local ERROR_MSG = {
|
|||
}
|
||||
|
||||
bot:hook('OnJoin', function(user, channel)
|
||||
if user.nick == BOT_NICK then
|
||||
if user.nick == CONFIG.IRC_NICK then
|
||||
-- On self join
|
||||
io.write(string.format(' !! Joined %s\n', channel))
|
||||
if #imlib.font.list_fonts() == 0 then
|
||||
|
@ -394,8 +400,8 @@ 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
|
||||
local msg = message:sub(#BOT_NICK+1)
|
||||
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*$'
|
||||
bot:sendChat(channel, "Will do! I'll join "..tostring(channel))
|
||||
|
@ -452,7 +458,7 @@ local function handle_message(bot, user, channel, message)
|
|||
end
|
||||
|
||||
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.flush()
|
||||
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))
|
||||
end)
|
||||
|
||||
|
||||
-- TODO: Invite to bogus channels
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Main run
|
||||
|
||||
|
@ -490,14 +493,13 @@ bot:connect {
|
|||
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')
|
||||
for _, channel in ipairs(CONFIG.IRC_CHANNELS or {}) do
|
||||
bot:join(channel)
|
||||
end
|
||||
|
||||
|
||||
while true do
|
||||
bot:think()
|
||||
sleep(0.5)
|
||||
|
@ -507,7 +509,7 @@ end
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
if ... then
|
||||
error 'Cannot be loaded like library'
|
||||
error 'Cannot load Memebot as a library'
|
||||
else
|
||||
init_memebot()
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user