irc2 updates

master
flux 2019-07-25 01:53:22 +00:00
parent 68db07eeb8
commit 8507a9b80f
11 changed files with 238 additions and 247 deletions

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "src/LuaIRC"] [submodule "src/LuaIRC"]
path = irc path = irc
url = https://github.com/ShadowNinja/LuaIRC.git url = https://github.com/BlockySurvival/LuaIRC2.git

View File

@ -1,5 +1,5 @@
irc.bot_commands = {} irc2.bot_commands = {}
-- From RFC1459: -- From RFC1459:
-- "Because of IRCs scandanavian origin, the characters {}| are -- "Because of IRCs scandanavian origin, the characters {}| are
@ -15,9 +15,9 @@ local function nickequals(nick1, nick2)
return irclower(nick1) == irclower(nick2) return irclower(nick1) == irclower(nick2)
end end
function irc.check_botcmd(msg) function irc2.check_botcmd(msg)
local prefix = irc.config.command_prefix local prefix = irc2.config.command_prefix
local nick = irc.conn.nick local nick = irc2.conn.nick
local text = msg.args[2] local text = msg.args[2]
local nickpart = text:sub(1, #nick) local nickpart = text:sub(1, #nick)
local suffix = text:sub(#nick+1, #nick+2) local suffix = text:sub(#nick+1, #nick+2)
@ -25,18 +25,18 @@ function irc.check_botcmd(msg)
-- First check for a nick prefix -- First check for a nick prefix
if nickequals(nickpart, nick) if nickequals(nickpart, nick)
and (suffix == ": " or suffix == ", ") then and (suffix == ": " or suffix == ", ") then
irc.bot_command(msg, text:sub(#nick + 3)) irc2.bot_command(msg, text:sub(#nick + 3))
return true return true
-- Then check for the configured prefix -- Then check for the configured prefix
elseif prefix and text:sub(1, #prefix):lower() == prefix:lower() then elseif prefix and text:sub(1, #prefix):lower() == prefix:lower() then
irc.bot_command(msg, text:sub(#prefix + 1)) irc2.bot_command(msg, text:sub(#prefix + 1))
return true return true
end end
return false return false
end end
function irc.bot_command(msg, text) function irc2.bot_command(msg, text)
-- Remove leading whitespace -- Remove leading whitespace
text = text:match("^%s*(.*)") text = text:match("^%s*(.*)")
if text:sub(1, 1) == "@" then if text:sub(1, 1) == "@" then
@ -44,15 +44,15 @@ function irc.bot_command(msg, text)
if not player_to then if not player_to then
return return
elseif not minetest.get_player_by_name(player_to) then elseif not minetest.get_player_by_name(player_to) then
irc.reply("User '"..player_to.."' is not in the game.") irc2.reply("User '"..player_to.."' is not in the game.")
return return
elseif not irc.joined_players[player_to] then elseif not irc2.joined_players[player_to] then
irc.reply("User '"..player_to.."' is not using IRC.") irc2.reply("User '"..player_to.."' is not using IRC.")
return return
end end
minetest.chat_send_player(player_to, minetest.chat_send_player(player_to,
"PM from "..msg.user.nick.."@IRC: "..message, false) "PM from "..msg.user.nick.."@IRC: "..message, false)
irc.reply("Message sent!") irc2.reply("Message sent!")
return return
end end
local pos = text:find(" ", 1, true) local pos = text:find(" ", 1, true)
@ -65,36 +65,36 @@ function irc.bot_command(msg, text)
args = "" args = ""
end end
if not irc.bot_commands[cmd] then if not irc2.bot_commands[cmd] then
irc.reply("Unknown command '"..cmd.."'. Try 'help'." irc2.reply("Unknown command '"..cmd.."'. Try 'help'."
.." Or use @playername <message> to send a private message") .." Or use @playername <message> to send a private message")
return return
end end
local _, message = irc.bot_commands[cmd].func(msg.user, args) local _, message = irc2.bot_commands[cmd].func(msg.user, args)
if message then if message then
irc.reply(message) irc2.reply(message)
end end
end end
function irc.register_bot_command(name, def) function irc2.register_bot_command(name, def)
if (not def.func) or (type(def.func) ~= "function") then if (not def.func) or (type(def.func) ~= "function") then
error("Erroneous bot command definition. def.func missing.", 2) error("Erroneous bot command definition. def.func missing.", 2)
elseif name:sub(1, 1) == "@" then elseif name:sub(1, 1) == "@" then
error("Erroneous bot command name. Command name begins with '@'.", 2) error("Erroneous bot command name. Command name begins with '@'.", 2)
end end
irc.bot_commands[name] = def irc2.bot_commands[name] = def
end end
irc.register_bot_command("help", { irc2.register_bot_command("help", {
params = "<command>", params = "<command>",
description = "Get help about a command", description = "Get help about a command",
func = function(_, args) func = function(_, args)
if args == "" then if args == "" then
local cmdlist = { } local cmdlist = { }
for name in pairs(irc.bot_commands) do for name in pairs(irc2.bot_commands) do
cmdlist[#cmdlist+1] = name cmdlist[#cmdlist+1] = name
end end
return true, "Available commands: "..table.concat(cmdlist, ", ") return true, "Available commands: "..table.concat(cmdlist, ", ")
@ -102,13 +102,13 @@ irc.register_bot_command("help", {
.." help about a specific command." .." help about a specific command."
end end
local cmd = irc.bot_commands[args] local cmd = irc2.bot_commands[args]
if not cmd then if not cmd then
return false, "Unknown command '"..args.."'." return false, "Unknown command '"..args.."'."
end end
return true, ("Usage: %s%s %s -- %s"):format( return true, ("Usage: %s%s %s -- %s"):format(
irc.config.command_prefix or "", irc2.config.command_prefix or "",
args, args,
cmd.params or "<no parameters>", cmd.params or "<no parameters>",
cmd.description or "<no description>") cmd.description or "<no description>")
@ -116,7 +116,7 @@ irc.register_bot_command("help", {
}) })
irc.register_bot_command("list", { irc2.register_bot_command("list", {
params = "", params = "",
description = "List available commands.", description = "List available commands.",
func = function() func = function()
@ -126,7 +126,7 @@ irc.register_bot_command("list", {
}) })
irc.register_bot_command("whereis", { irc2.register_bot_command("whereis", {
params = "<player>", params = "<player>",
description = "Tell the location of <player>", description = "Tell the location of <player>",
func = function(_, args) func = function(_, args)
@ -137,7 +137,7 @@ irc.register_bot_command("whereis", {
if not player then if not player then
return false, "There is no player named '"..args.."'" return false, "There is no player named '"..args.."'"
end end
local fmt = "Player %s is at [CENSORED]" local fmt = "Player %s is at (%.2f,%.2f,%.2f)"
local pos = player:getpos() local pos = player:getpos()
return true, fmt:format(args, pos.x, pos.y, pos.z) return true, fmt:format(args, pos.x, pos.y, pos.z)
end end
@ -145,7 +145,7 @@ irc.register_bot_command("whereis", {
local starttime = os.time() local starttime = os.time()
irc.register_bot_command("uptime", { irc2.register_bot_command("uptime", {
description = "Tell how much time the server has been up", description = "Tell how much time the server has been up",
func = function() func = function()
local cur_time = os.time() local cur_time = os.time()
@ -160,7 +160,7 @@ irc.register_bot_command("uptime", {
}) })
irc.register_bot_command("players", { irc2.register_bot_command("players", {
description = "List the players on the server", description = "List the players on the server",
func = function() func = function()
local players = minetest.get_connected_players() local players = minetest.get_connected_players()

View File

@ -4,26 +4,26 @@
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
if irc.connected and irc.config.send_join_part then if irc2.connected and irc2.config.send_join_part then
irc.say("*** "..name.." joined the game") irc2.say("*** "..name.." joined the game")
end end
end) end)
minetest.register_on_leaveplayer(function(player, timed_out) minetest.register_on_leaveplayer(function(player, timed_out)
local name = player:get_player_name() local name = player:get_player_name()
if irc.connected and irc.config.send_join_part then if irc2.connected and irc2.config.send_join_part then
irc.say("*** "..name.." left the game".. irc2.say("*** "..name.." left the game"..
(timed_out and " (Timed out)" or "")) (timed_out and " (Timed out)" or ""))
end end
end) end)
minetest.register_on_chat_message(function(name, message) minetest.register_on_chat_message(function(name, message)
if not irc.connected if not irc2.connected
or message:sub(1, 1) == "/" or message:sub(1, 1) == "/"
or message:sub(1, 5) == "[off]" or message:sub(1, 5) == "[off]"
or not irc.joined_players[name] or not irc2.joined_players[name]
or (not minetest.check_player_privs(name, {shout=true})) then or (not minetest.check_player_privs(name, {shout=true})) then
return return
end end
@ -31,11 +31,11 @@ minetest.register_on_chat_message(function(name, message)
if nl then if nl then
message = message:sub(1, nl - 1) message = message:sub(1, nl - 1)
end end
irc.say(irc.playerMessage(name, core.strip_colors(message))) irc2.say(irc2.playerMessage(name, core.strip_colors(message)))
end) end)
minetest.register_on_shutdown(function() minetest.register_on_shutdown(function()
irc.disconnect("Game shutting down.") irc2.disconnect("Game shutting down.")
end) end)

View File

@ -5,22 +5,22 @@
-- Feature-specific commands (like /join) are in their own files. -- Feature-specific commands (like /join) are in their own files.
minetest.register_chatcommand("irc_msg", { minetest.register_chatcommand("irc2_msg", {
params = "<name> <message>", params = "<name> <message>",
description = "Send a private message to an IRC user", description = "Send a private message to a freenode IRC user",
privs = {shout=true}, privs = {shout=true},
func = function(name, param) func = function(name, param)
if not irc.connected then if not irc2.connected then
return false, "Not connected to IRC. Use /irc_connect to connect." return false, "Not connected to freenode IRC. Use /irc2_connect to connect."
end end
local found, _, toname, message = param:find("^([^%s]+)%s(.+)") local found, _, toname, message = param:find("^([^%s]+)%s(.+)")
if not found then if not found then
return false, "Invalid usage, see /help irc_msg." return false, "Invalid usage, see /help irc2_msg."
end end
local toname_l = toname:lower() local toname_l = toname:lower()
local validNick = false local validNick = false
local hint = "They have to be in the channel" local hint = "They have to be in the channel"
for nick in pairs(irc.conn.channels[irc.config.channel].users) do for nick in pairs(irc2.conn.channels[irc2.config.channel].users) do
if nick:lower() == toname_l then if nick:lower() == toname_l then
validNick = true validNick = true
break break
@ -33,80 +33,80 @@ minetest.register_chatcommand("irc_msg", {
if not validNick then if not validNick then
return false, "You can not message that user. ("..hint..")" return false, "You can not message that user. ("..hint..")"
end end
irc.say(toname, irc.playerMessage(name, message)) irc2.say(toname, irc2.playerMessage(name, message))
return true, "Message sent!" return true, "Message sent!"
end end
}) })
minetest.register_chatcommand("irc_names", { minetest.register_chatcommand("irc2_names", {
params = "", params = "",
description = "List the users in IRC.", description = "List the users in freenode IRC.",
func = function() func = function()
if not irc.connected then if not irc2.connected then
return false, "Not connected to IRC. Use /irc_connect to connect." return false, "Not connected to freenode IRC. Use /irc2_connect to connect."
end end
local users = { } local users = { }
for nick in pairs(irc.conn.channels[irc.config.channel].users) do for nick in pairs(irc2.conn.channels[irc2.config.channel].users) do
table.insert(users, nick) table.insert(users, nick)
end end
return true, "Users in IRC: "..table.concat(users, ", ") return true, "Users in freenode IRC: "..table.concat(users, ", ")
end end
}) })
minetest.register_chatcommand("irc_connect", { minetest.register_chatcommand("irc2_connect", {
description = "Connect to the IRC server.", description = "Connect to the freenode IRC server.",
privs = {irc_admin=true}, privs = {irc2_admin=true},
func = function(name) func = function(name)
if irc.connected then if irc2.connected then
return false, "You are already connected to IRC." return false, "You are already connected to freenode IRC."
end end
minetest.chat_send_player(name, "IRC: Connecting...") minetest.chat_send_player(name, "IRC: Connecting...")
irc.connect() irc2.connect()
end end
}) })
minetest.register_chatcommand("irc_disconnect", { minetest.register_chatcommand("irc2_disconnect", {
params = "[message]", params = "[message]",
description = "Disconnect from the IRC server.", description = "Disconnect from freenode IRC.",
privs = {irc_admin=true}, privs = {irc2_admin=true},
func = function(name, param) func = function(name, param)
if not irc.connected then if not irc2.connected then
return false, "Not connected to IRC. Use /irc_connect to connect." return false, "Not connected to freenode IRC. Use /irc2_connect to connect."
end end
if param == "" then if param == "" then
param = "Manual disconnect by "..name param = "Manual disconnect by "..name
end end
irc.disconnect(param) irc2.disconnect(param)
end end
}) })
minetest.register_chatcommand("irc_reconnect", { minetest.register_chatcommand("irc2_reconnect", {
description = "Reconnect to the IRC server.", description = "Reconnect to freenode IRC.",
privs = {irc_admin=true}, privs = {irc2_admin=true},
func = function(name) func = function(name)
if not irc.connected then if not irc2.connected then
return false, "Not connected to IRC. Use /irc_connect to connect." return false, "Not connected to freenode IRC. Use /irc2_connect to connect."
end end
minetest.chat_send_player(name, "IRC: Reconnecting...") minetest.chat_send_player(name, "IRC: Reconnecting...")
irc.disconnect("Reconnecting...") irc2.disconnect("Reconnecting...")
irc.connect() irc2.connect()
end end
}) })
minetest.register_chatcommand("irc_quote", { minetest.register_chatcommand("irc2_quote", {
params = "<command>", params = "<command>",
description = "Send a raw command to the IRC server.", description = "Send a raw command freenode IRC.",
privs = {irc_admin=true}, privs = {irc2_admin=true},
func = function(name, param) func = function(name, param)
if not irc.connected then if not irc2.connected then
return false, "Not connected to IRC. Use /irc_connect to connect." return false, "Not connected to freenode IRC. Use /irc2_connect to connect."
end end
irc.queue(param) irc2.queue(param)
minetest.chat_send_player(name, "Command sent!") minetest.chat_send_player(name, "Command sent!")
end end
}) })
@ -115,11 +115,11 @@ minetest.register_chatcommand("irc_quote", {
local oldme = minetest.chatcommands["me"].func local oldme = minetest.chatcommands["me"].func
-- luacheck: ignore -- luacheck: ignore
minetest.chatcommands["me"].func = function(name, param, ...) minetest.chatcommands["me"].func = function(name, param, ...)
irc.say(("* %s %s"):format(name, param)) irc2.say(("* %s %s"):format(name, param))
return oldme(name, param, ...) return oldme(name, param, ...)
end end
if irc.config.send_kicks and minetest.chatcommands["kick"] then if irc2.config.send_kicks and minetest.chatcommands["kick"] then
local oldkick = minetest.chatcommands["kick"].func local oldkick = minetest.chatcommands["kick"].func
-- luacheck: ignore -- luacheck: ignore
minetest.chatcommands["kick"].func = function(name, param, ...) minetest.chatcommands["kick"].func = function(name, param, ...)
@ -127,7 +127,7 @@ if irc.config.send_kicks and minetest.chatcommands["kick"] then
if not plname then if not plname then
return false, "Usage: /kick player [reason]" return false, "Usage: /kick player [reason]"
end end
irc.say(("*** Kicked %s.%s"):format(name, irc2.say(("*** Kicked %s.%s"):format(name,
reason~="" and " Reason: "..reason or "")) reason~="" and " Reason: "..reason or ""))
return oldkick(name, param, ...) return oldkick(name, param, ...)
end end

View File

@ -2,37 +2,25 @@
-- See LICENSE.txt for details. -- See LICENSE.txt for details.
irc.config = {} irc2.config = {}
local function setting(stype, name, default, required) local function setting(stype, name, default, required)
local value local value
if minetest.settings and minetest.settings.get and minetest.settings.get_bool then if stype == "bool" then
-- The current methods for getting settings value = minetest.setting_getbool("irc2."..name)
if stype == "bool" then elseif stype == "string" then
value = minetest.settings:get_bool("irc."..name) value = minetest.setting_get("irc2."..name)
elseif stype == "string" then elseif stype == "number" then
value = minetest.settings:get("irc."..name) value = tonumber(minetest.setting_get("irc2."..name))
elseif stype == "number" then
value = tonumber(minetest.settings:get("irc."..name))
end
else
-- The old methods for getting settings for backward compatibility. Deprecated on 0.4.16+
if stype == "bool" then
value = minetest.setting_getbool("irc."..name)
elseif stype == "string" then
value = minetest.setting_get("irc."..name)
elseif stype == "number" then
value = tonumber(minetest.setting_get("irc."..name))
end
end end
if value == nil then if value == nil then
if required then if required then
error("Required configuration option irc.".. error("Required configuration option irc2."..
name.." missing.") name.." missing.")
end end
value = default value = default
end end
irc.config[name] = value irc2.config[name] = value
end end
------------------------- -------------------------
@ -43,7 +31,7 @@ setting("string", "nick", nil, true) -- Nickname
setting("string", "server", nil, true) -- Server address to connect to setting("string", "server", nil, true) -- Server address to connect to
setting("number", "port", 6667) -- Server port to connect to setting("number", "port", 6667) -- Server port to connect to
setting("string", "NSPass") -- NickServ password setting("string", "NSPass") -- NickServ password
setting("string", "sasl.user", irc.config.nick) -- SASL username setting("string", "sasl.user", irc2.config.nick) -- SASL username
setting("string", "username", "Minetest") -- Username/ident setting("string", "username", "Minetest") -- Username/ident
setting("string", "realname", "Minetest") -- Real name/GECOS setting("string", "realname", "Minetest") -- Real name/GECOS
setting("string", "sasl.pass") -- SASL password setting("string", "sasl.pass") -- SASL password

148
hooks.lua
View File

@ -6,8 +6,8 @@ local ie = ...
-- MIME is part of LuaSocket -- MIME is part of LuaSocket
local b64e = ie.require("mime").b64 local b64e = ie.require("mime").b64
irc.hooks = {} irc2.hooks = {}
irc.registered_hooks = {} irc2.registered_hooks = {}
local stripped_chars = "[\2\31]" local stripped_chars = "[\2\31]"
@ -20,8 +20,8 @@ local function normalize(text)
end end
function irc.doHook(conn) function irc2.doHook(conn)
for name, hook in pairs(irc.registered_hooks) do for name, hook in pairs(irc2.registered_hooks) do
for _, func in pairs(hook) do for _, func in pairs(hook) do
conn:hook(name, func) conn:hook(name, func)
end end
@ -29,39 +29,39 @@ function irc.doHook(conn)
end end
function irc.register_hook(name, func) function irc2.register_hook(name, func)
irc.registered_hooks[name] = irc.registered_hooks[name] or {} irc2.registered_hooks[name] = irc2.registered_hooks[name] or {}
table.insert(irc.registered_hooks[name], func) table.insert(irc2.registered_hooks[name], func)
end end
function irc.hooks.raw(line) function irc2.hooks.raw(line)
if irc.config.debug then if irc2.config.debug then
print("RECV: "..line) print("RECV: "..line)
end end
end end
function irc.hooks.send(line) function irc2.hooks.send(line)
if irc.config.debug then if irc2.config.debug then
print("SEND: "..line) print("SEND: "..line)
end end
end end
function irc.hooks.chat(msg) function irc2.hooks.chat(msg)
local channel, text = msg.args[1], msg.args[2] local channel, text = msg.args[1], msg.args[2]
if text:sub(1, 1) == string.char(1) then if text:sub(1, 1) == string.char(1) then
irc.conn:invoke("OnCTCP", msg) irc2.conn:invoke("OnCTCP", msg)
return return
end end
if channel == irc.conn.nick then if channel == irc2.conn.nick then
irc.last_from = msg.user.nick irc2.last_from = msg.user.nick
irc.conn:invoke("PrivateMessage", msg) irc2.conn:invoke("PrivateMessage", msg)
else else
irc.last_from = channel irc2.last_from = channel
irc.conn:invoke("OnChannelChat", msg) irc2.conn:invoke("OnChannelChat", msg)
end end
end end
@ -74,22 +74,22 @@ local function get_core_version()
end end
function irc.hooks.ctcp(msg) function irc2.hooks.ctcp(msg)
local text = msg.args[2]:sub(2, -2) -- Remove ^C local text = msg.args[2]:sub(2, -2) -- Remove ^C
local args = text:split(' ') local args = text:split(' ')
local command = args[1]:upper() local command = args[1]:upper()
local function reply(s) local function reply(s)
irc.queue(irc.msgs.notice(msg.user.nick, irc2.queue(irc2.msgs.notice(msg.user.nick,
("\1%s %s\1"):format(command, s))) ("\1%s %s\1"):format(command, s)))
end end
if command == "ACTION" and msg.args[1] == irc.config.channel then if command == "ACTION" and msg.args[1] == irc2.config.channel then
local action = text:sub(8, -1) local action = text:sub(8, -1)
irc.sendLocal(("* %s@xeroxIRC %s"):format(msg.user.nick, action)) irc2.sendLocal(("* %s@freenode %s"):format(msg.user.nick, action))
elseif command == "VERSION" then elseif command == "VERSION" then
reply(("Minetest version %s, IRC mod version %s.") reply(("Minetest version %s, IRC mod version %s.")
:format(get_core_version(), irc.version)) :format(get_core_version(), irc2.version))
elseif command == "PING" then elseif command == "PING" then
reply(args[2]) reply(args[2])
elseif command == "TIME" then elseif command == "TIME" then
@ -98,15 +98,15 @@ function irc.hooks.ctcp(msg)
end end
function irc.hooks.channelChat(msg) function irc2.hooks.channelChat(msg)
local text = normalize(msg.args[2]) local text = normalize(msg.args[2])
irc.check_botcmd(msg) irc2.check_botcmd(msg)
-- Don't let a user impersonate someone else by using the nick "IRC" -- Don't let a user impersonate someone else by using the nick "IRC"
local fake = msg.user.nick:lower():match("^[il|]rc$") local fake = msg.user.nick:lower():match("^[il|]rc$")
if fake then if fake then
irc.sendLocal("<"..msg.user.nick.."@xeroxIRC> "..text) irc2.sendLocal("<"..msg.user.nick.."@freenode> "..text)
return return
elseif msg.user.nick == "BlockyRelay" then elseif msg.user.nick == "BlockyRelay" then
return return
@ -128,53 +128,53 @@ function irc.hooks.channelChat(msg)
if text:sub(1, 5) == "[off]" then if text:sub(1, 5) == "[off]" then
return return
elseif foundchat then elseif foundchat then
irc.sendLocal(("<%s@%s> %s") irc2.sendLocal(("<%s@%s> %s")
:format(chatnick, msg.user.nick, chatmessage)) :format(chatnick, msg.user.nick, chatmessage))
elseif foundjoin then elseif foundjoin then
irc.sendLocal(("*** %s joined %s") irc2.sendLocal(("*** %s joined %s")
:format(joinnick, msg.user.nick)) :format(joinnick, msg.user.nick))
elseif foundleave then elseif foundleave then
irc.sendLocal(("*** %s left %s") irc2.sendLocal(("*** %s left %s")
:format(leavenick, msg.user.nick)) :format(leavenick, msg.user.nick))
elseif foundaction then elseif foundaction then
irc.sendLocal(("* %s@%s %s") irc2.sendLocal(("* %s@%s %s")
:format(actionnick, msg.user.nick, actionmessage)) :format(actionnick, msg.user.nick, actionmessage))
else else
irc.sendLocal(("<%s@xeroxIRC> %s"):format(msg.user.nick, text)) irc2.sendLocal(("<%s@freenode> %s"):format(msg.user.nick, text))
end end
end end
function irc.hooks.pm(msg) function irc2.hooks.pm(msg)
-- Trim prefix if it is found -- Trim prefix if it is found
local text = msg.args[2] local text = msg.args[2]
local prefix = irc.config.command_prefix local prefix = irc2.config.command_prefix
if prefix and text:sub(1, #prefix) == prefix then if prefix and text:sub(1, #prefix) == prefix then
text = text:sub(#prefix + 1) text = text:sub(#prefix + 1)
end end
irc.bot_command(msg, text) irc2.bot_command(msg, text)
end end
function irc.hooks.kick(channel, target, prefix, reason) function irc2.hooks.kick(channel, target, prefix, reason)
if target == irc.conn.nick then if target == irc2.conn.nick then
minetest.chat_send_all("IRC: kicked from "..channel.." (xeroxIRC) by "..prefix.nick..".") minetest.chat_send_all("IRC: kicked from "..channel.." (freenode) by "..prefix.nick..".")
irc.disconnect("Kicked") irc2.disconnect("Kicked")
else else
irc.sendLocal(("-!- %s was kicked from %s (xeroxIRC) by %s [%s]") irc2.sendLocal(("-!- %s was kicked from %s (freenode) by %s [%s]")
:format(target, channel, prefix.nick, reason)) :format(target, channel, prefix.nick, reason))
end end
end end
function irc.hooks.notice(user, target, message) function irc2.hooks.notice(user, target, message)
if user.nick and target == irc.config.channel then if user.nick and target == irc2.config.channel then
irc.sendLocal("-"..user.nick.."@xeroxIRC- "..message) irc2.sendLocal("-"..user.nick.."@freenode- "..message)
end end
end end
function irc.hooks.mode(user, target, modes, ...) function irc2.hooks.mode(user, target, modes, ...)
local by = "" local by = ""
if user.nick then if user.nick then
by = " by "..user.nick by = " by "..user.nick
@ -189,37 +189,37 @@ function irc.hooks.mode(user, target, modes, ...)
end end
function irc.hooks.nick(user, newNick) function irc2.hooks.nick(user, newNick)
irc.sendLocal(("-!- %s is now known as %s") irc2.sendLocal(("-!- %s is now known as %s")
:format(user.nick, newNick)) :format(user.nick, newNick))
end end
function irc.hooks.join(user, channel) function irc2.hooks.join(user, channel)
irc.sendLocal(("-!- %s joined %s (xeroxIRC)") irc2.sendLocal(("-!- %s joined %s (freenode)")
:format(user.nick, channel)) :format(user.nick, channel))
end end
function irc.hooks.part(user, channel, reason) function irc2.hooks.part(user, channel, reason)
reason = reason or "" reason = reason or ""
irc.sendLocal(("-!- %s has left %s (xeroxIRC) [%s]") irc2.sendLocal(("-!- %s has left %s (freenode) [%s]")
:format(user.nick, channel, reason)) :format(user.nick, channel, reason))
end end
function irc.hooks.quit(user, reason) function irc2.hooks.quit(user, reason)
irc.sendLocal(("-!- %s has quit xeroxIRC [%s]") irc2.sendLocal(("-!- %s has quit freenode [%s]")
:format(user.nick, reason)) :format(user.nick, reason))
end end
function irc.hooks.disconnect(_, isError) function irc2.hooks.disconnect(_, isError)
irc.connected = false irc2.connected = false
if isError then if isError then
minetest.log("error", "IRC: Error: Disconnected, reconnecting in one minute.") minetest.log("error", "IRC: Error: Disconnected, reconnecting in one minute.")
minetest.chat_send_all("IRC: Error: Disconnected, reconnecting in one minute.") minetest.chat_send_all("IRC: Error: Disconnected, reconnecting in one minute.")
minetest.after(60, irc.connect, irc) minetest.after(60, irc2.connect, irc2)
else else
minetest.log("action", "IRC: Disconnected.") minetest.log("action", "IRC: Disconnected.")
minetest.chat_send_all("IRC: Disconnected.") minetest.chat_send_all("IRC: Disconnected.")
@ -227,13 +227,13 @@ function irc.hooks.disconnect(_, isError)
end end
function irc.hooks.preregister(conn) function irc2.hooks.preregister(conn)
if not (irc.config["sasl.user"] and irc.config["sasl.pass"]) then return end if not (irc2.config["sasl.user"] and irc2.config["sasl.pass"]) then return end
local authString = b64e( local authString = b64e(
("%s\x00%s\x00%s"):format( ("%s\x00%s\x00%s"):format(
irc.config["sasl.user"], irc2.config["sasl.user"],
irc.config["sasl.user"], irc2.config["sasl.user"],
irc.config["sasl.pass"]) irc2.config["sasl.pass"])
) )
conn:send("CAP REQ sasl") conn:send("CAP REQ sasl")
conn:send("AUTHENTICATE PLAIN") conn:send("AUTHENTICATE PLAIN")
@ -242,19 +242,19 @@ function irc.hooks.preregister(conn)
end end
irc.register_hook("PreRegister", irc.hooks.preregister) irc2.register_hook("PreRegister", irc2.hooks.preregister)
irc.register_hook("OnRaw", irc.hooks.raw) irc2.register_hook("OnRaw", irc2.hooks.raw)
irc.register_hook("OnSend", irc.hooks.send) irc2.register_hook("OnSend", irc2.hooks.send)
irc.register_hook("DoPrivmsg", irc.hooks.chat) irc2.register_hook("DoPrivmsg", irc2.hooks.chat)
irc.register_hook("OnPart", irc.hooks.part) irc2.register_hook("OnPart", irc2.hooks.part)
irc.register_hook("OnKick", irc.hooks.kick) irc2.register_hook("OnKick", irc2.hooks.kick)
irc.register_hook("OnJoin", irc.hooks.join) irc2.register_hook("OnJoin", irc2.hooks.join)
irc.register_hook("OnQuit", irc.hooks.quit) irc2.register_hook("OnQuit", irc2.hooks.quit)
irc.register_hook("NickChange", irc.hooks.nick) irc2.register_hook("NickChange", irc2.hooks.nick)
irc.register_hook("OnCTCP", irc.hooks.ctcp) irc2.register_hook("OnCTCP", irc2.hooks.ctcp)
irc.register_hook("PrivateMessage", irc.hooks.pm) irc2.register_hook("PrivateMessage", irc2.hooks.pm)
irc.register_hook("OnNotice", irc.hooks.notice) irc2.register_hook("OnNotice", irc2.hooks.notice)
irc.register_hook("OnChannelChat", irc.hooks.channelChat) irc2.register_hook("OnChannelChat", irc2.hooks.channelChat)
irc.register_hook("OnModeChange", irc.hooks.mode) irc2.register_hook("OnModeChange", irc2.hooks.mode)
irc.register_hook("OnDisconnect", irc.hooks.disconnect) irc2.register_hook("OnDisconnect", irc2.hooks.disconnect)

111
init.lua
View File

@ -28,7 +28,6 @@ if not rawget(_G, "jit") and package.config:sub(1, 1) == "/" then
";/usr/share/lua/5.1/?/init.lua" ";/usr/share/lua/5.1/?/init.lua"
ie.package.cpath = ie.package.cpath.. ie.package.cpath = ie.package.cpath..
";/usr/lib/lua/5.1/?.so" ";/usr/lib/lua/5.1/?.so"
ie.package.cpath = "/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;"..ie.package.cpath
end end
-- Temporarily set require so that LuaIRC can access it -- Temporarily set require so that LuaIRC can access it
@ -41,7 +40,7 @@ rawset(_G, "module", ie.module)
local lib = ie.require("irc") local lib = ie.require("irc")
irc = { irc2 = {
version = "0.2.0", version = "0.2.0",
connected = false, connected = false,
cur_time = 0, cur_time = 0,
@ -53,7 +52,7 @@ irc = {
} }
-- Compatibility -- Compatibility
rawset(_G, "mt_irc", irc) rawset(_G, "mt_irc2", irc2)
local getinfo = debug.getinfo local getinfo = debug.getinfo
local warned = { } local warned = { }
@ -69,7 +68,7 @@ local function warn_deprecated(k)
end end
-- This is a hack. -- This is a hack.
setmetatable(irc, { setmetatable(irc2, {
__newindex = function(t, k, v) __newindex = function(t, k, v)
if type(v) == "function" then if type(v) == "function" then
local f = v local f = v
@ -97,33 +96,28 @@ dofile(modpath.."/botcmds.lua")
require = old_require require = old_require
rawset(_G, "module", old_module) rawset(_G, "module", old_module)
if irc.config.enable_player_part then if irc2.config.enable_player_part then
dofile(modpath.."/player_part.lua") dofile(modpath.."/player_part.lua")
else else
setmetatable(irc.joined_players, {__index = function() return true end}) setmetatable(irc2.joined_players, {__index = function() return true end})
end end
minetest.register_privilege("irc_admin", {
description = "Allow IRC administrative tasks to be performed.",
give_to_singleplayer = true
})
local stepnum = 0 local stepnum = 0
minetest.register_globalstep(function(dtime) return irc.step(dtime) end) minetest.register_globalstep(function(dtime) return irc2.step(dtime) end)
function irc.step() function irc2.step()
if stepnum == 3 then if stepnum == 3 then
if irc.config.auto_connect then if irc2.config.auto_connect then
irc.connect() irc2.connect()
end end
end end
stepnum = stepnum + 1 stepnum = stepnum + 1
if not irc.connected then return end if not irc2.connected then return end
-- Hooks will manage incoming messages and errors -- Hooks will manage incoming messages and errors
local good, err = xpcall(function() irc.conn:think() end, debug.traceback) local good, err = xpcall(function() irc2.conn:think() end, debug.traceback)
if not good then if not good then
print(err) print(err)
return return
@ -131,17 +125,17 @@ function irc.step()
end end
function irc.connect() function irc2.connect()
if irc.connected then if irc2.connected then
minetest.log("error", "IRC: Ignoring attempt to connect when already connected.") minetest.log("error", "IRC: Ignoring attempt to connect when already connected.")
return return
end end
irc.conn = irc.lib.new({ irc2.conn = irc2.lib.new({
nick = irc.config.nick, nick = irc2.config.nick,
username = irc.config.username, username = irc2.config.username,
realname = irc.config.realname, realname = irc2.config.realname,
}) })
irc.doHook(irc.conn) irc2.doHook(irc2.conn)
-- We need to swap the `require` function again since -- We need to swap the `require` function again since
-- LuaIRC `require`s `ssl` if `irc.secure` is true. -- LuaIRC `require`s `ssl` if `irc.secure` is true.
@ -149,13 +143,13 @@ function irc.connect()
require = ie.require require = ie.require
local good, message = pcall(function() local good, message = pcall(function()
irc.conn:connect({ irc2.conn:connect({
host = irc.config.server, host = irc2.config.server,
port = irc.config.port, port = irc2.config.port,
password = irc.config.password, password = irc2.config.password,
timeout = irc.config.timeout, timeout = irc2.config.timeout,
reconnect = irc.config.reconnect, reconnect = irc2.config.reconnect,
secure = irc.config.secure secure = irc2.config.secure
}) })
end) end)
@ -163,57 +157,66 @@ function irc.connect()
if not good then if not good then
minetest.log("error", ("IRC: Connection error: %s: %s -- Reconnecting in %d seconds...") minetest.log("error", ("IRC: Connection error: %s: %s -- Reconnecting in %d seconds...")
:format(irc.config.server, message, irc.config.reconnect)) :format(irc2.config.server, message, irc2.config.reconnect))
minetest.after(irc.config.reconnect, function() irc.connect() end) minetest.after(irc2.config.reconnect, function() irc2.connect() end)
return return
end end
if irc.config.NSPass then if irc2.config.NSPass then
irc.conn:queue(irc.msgs.privmsg( irc2.conn:queue(irc2.msgs.privmsg(
"NickServ", "IDENTIFY "..irc.config.NSPass)) "NickServ", "IDENTIFY "..irc2.config.NSPass))
end end
irc.conn:join(irc.config.channel, irc.config.key) irc2.conn:join(irc2.config.channel, irc2.config.key)
irc.connected = true irc2.connected = true
minetest.log("action", "IRC: Connected!") minetest.log("action", "IRC: Connected!")
minetest.chat_send_all("IRC: Connected!") minetest.chat_send_all("IRC: Connected!")
end end
function irc.disconnect(message) function irc2.disconnect(message)
if irc.connected then if irc2.connected then
--The OnDisconnect hook will clear irc.connected and print a disconnect message --The OnDisconnect hook will clear irc.connected and print a disconnect message
irc.conn:disconnect(message) irc2.conn:disconnect(message)
end end
end end
function irc.say(to, message) function irc2.say(to, message)
if not message then if not message then
message = to message = to
to = irc.config.channel to = irc2.config.channel
end end
to = to or irc.config.channel to = to or irc2.config.channel
irc.queue(irc.msgs.privmsg(to, message)) irc2.queue(irc2.msgs.privmsg(to, message))
end end
function irc.reply(message) function irc2.reply(message)
if not irc.last_from then if not irc2.last_from then
return return
end end
message = message:gsub("[\r\n%z]", " \\n ") message = message:gsub("[\r\n%z]", " \\n ")
irc.say(irc.last_from, message) irc2.say(irc2.last_from, message)
end end
function irc.send(msg) function irc2.send(msg)
if not irc.connected then return end if not irc2.connected then return end
irc.conn:send(msg) irc2.conn:send(msg)
end end
function irc.queue(msg) function irc2.queue(msg)
if not irc.connected then return end if not irc2.connected then return end
irc.conn:queue(msg) irc2.conn:queue(msg)
end end
-- Cloaking fix
local irc_sendLocal = irc2.sendLocal
function irc2.sendLocal(msg)
for _, player in ipairs(cloaking.get_cloaked_players()) do
minetest.chat_send_player(player, msg)
end
return irc_sendLocal(msg)
end

2
irc

@ -1 +1 @@
Subproject commit e49a52ede1a58ddd94854657bc5098b0ac5d0677 Subproject commit 3baffb6bd3821b3e45b74a78e3564a9e7063b931

View File

@ -1,17 +1,17 @@
-- This file is licensed under the terms of the BSD 2-clause license. -- This file is licensed under the terms of the BSD 2-clause license.
-- See LICENSE.txt for details. -- See LICENSE.txt for details.
irc.msgs = irc.lib.msgs irc2.msgs = irc2.lib.msgs
function irc.logChat(message) function irc2.logChat(message)
minetest.log("action", "IRC CHAT: "..message) minetest.log("action", "IRC CHAT: "..message)
end end
function irc.sendLocal(message) function irc2.sendLocal(message)
minetest.chat_send_all(message) minetest.chat_send_all(message)
irc.logChat(message) irc2.logChat(message)
end end
function irc.playerMessage(name, message) function irc2.playerMessage(name, message)
return ("<%s> %s"):format(name, message) return ("<%s> %s"):format(name, message)
end end

View File

@ -1 +1 @@
name = irc name = irc2

View File

@ -2,19 +2,19 @@
-- See LICENSE.txt for details. -- See LICENSE.txt for details.
function irc.player_part(name) function irc2.player_part(name)
if not irc.joined_players[name] then if not irc2.joined_players[name] then
return false, "You are not in the channel" return false, "You are not in the channel"
end end
irc.joined_players[name] = nil irc2.joined_players[name] = nil
return true, "You left the channel" return true, "You left the channel"
end end
function irc.player_join(name) function irc2.player_join(name)
if irc.joined_players[name] then if irc2.joined_players[name] then
return false, "You are already in the channel" return false, "You are already in the channel"
end end
irc.joined_players[name] = true irc2.joined_players[name] = true
return true, "You joined the channel" return true, "You joined the channel"
end end
@ -23,7 +23,7 @@ minetest.register_chatcommand("join", {
description = "Join the IRC channel", description = "Join the IRC channel",
privs = {shout=true}, privs = {shout=true},
func = function(name) func = function(name)
return irc.player_join(name) return irc2.player_join(name)
end end
}) })
@ -31,7 +31,7 @@ minetest.register_chatcommand("part", {
description = "Part the IRC channel", description = "Part the IRC channel",
privs = {shout=true}, privs = {shout=true},
func = function(name) func = function(name)
return irc.player_part(name) return irc2.player_part(name)
end end
}) })
@ -40,7 +40,7 @@ minetest.register_chatcommand("who", {
privs = {}, privs = {},
func = function() func = function()
local out, n = { }, 0 local out, n = { }, 0
for plname in pairs(irc.joined_players) do for plname in pairs(irc2.joined_players) do
n = n + 1 n = n + 1
out[n] = plname out[n] = plname
end end
@ -52,18 +52,18 @@ minetest.register_chatcommand("who", {
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
irc.joined_players[name] = irc.config.auto_join irc2.joined_players[name] = irc2.config.auto_join
end) end)
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
irc.joined_players[name] = nil irc2.joined_players[name] = nil
end) end)
function irc.sendLocal(message) function irc2.sendLocal(message)
for name, _ in pairs(irc.joined_players) do for name, _ in pairs(irc2.joined_players) do
minetest.chat_send_player(name, message) minetest.chat_send_player(name, message)
end end
irc.logChat(message) irc2.logChat(message)
end end