mirror of
https://github.com/minetest-mods/irc.git
synced 2024-12-27 17:20:20 +01:00
Rename "mt_irc" namespace to "irc"
The underlying IRC library is now available as irc.lib.
This commit is contained in:
parent
e87d2e5bf2
commit
706a6fbe27
@ -1,24 +1,26 @@
|
|||||||
IRC Mod API
|
IRC Mod API
|
||||||
-----------
|
===========
|
||||||
|
|
||||||
This file documents the Minetest IRC mod API.
|
This file documents the Minetest IRC mod API.
|
||||||
|
|
||||||
BASICS
|
Basics
|
||||||
------
|
------
|
||||||
In order to allow your mod to interface with this mod, you must add 'irc'
|
|
||||||
(without the quotes) to your mod's 'depends.txt' file.
|
In order to allow your mod to interface with this mod, you must add `irc`
|
||||||
|
to your mod's `depends.txt` file.
|
||||||
|
|
||||||
|
|
||||||
REFERENCE
|
Reference
|
||||||
---------
|
---------
|
||||||
|
|
||||||
mt_irc:say([name, ]message)
|
irc:say([name,] message)
|
||||||
Sends <message> to either the channel (if <name> is nil or not specified),
|
Sends <message> to either the channel (if <name> is nil or not specified),
|
||||||
or to the given user (if <name> is specified).
|
or to the given user (if <name> is specified).
|
||||||
Example:
|
Example:
|
||||||
mt_irc:say("Hello, Channel!")
|
irc:say("Hello, Channel!")
|
||||||
mt_irc:say("john1234", "How are you?")
|
irc:say("john1234", "How are you?")
|
||||||
|
|
||||||
mt_irc:register_bot_command(name, cmdDef)
|
irc:register_bot_command(name, cmdDef)
|
||||||
Registers a new bot command named <name>.
|
Registers a new bot command named <name>.
|
||||||
When an user sends a private message to the bot with the command name, the
|
When an user sends a private message to the bot with the command name, the
|
||||||
command's function is called.
|
command's function is called.
|
||||||
@ -35,29 +37,29 @@ mt_irc:register_bot_command(name, cmdDef)
|
|||||||
end,
|
end,
|
||||||
};
|
};
|
||||||
Example:
|
Example:
|
||||||
mt_irc:register_bot_command("hello", {
|
irc:register_bot_command("hello", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Greet user",
|
description = "Greet user",
|
||||||
func = function(user, param)
|
func = function(user, param)
|
||||||
mt_irc:say(user.nick, "Hello!")
|
irc:say(user.nick, "Hello!")
|
||||||
end,
|
end,
|
||||||
});
|
});
|
||||||
|
|
||||||
mt_irc.joined_players[name]
|
irc.joined_players[name]
|
||||||
This table holds the players who are currently on the channel (may be less
|
This table holds the players who are currently on the channel (may be less
|
||||||
than the players in the game). It is modified by the /part and /join chat
|
than the players in the game). It is modified by the /part and /join chat
|
||||||
commands.
|
commands.
|
||||||
Example:
|
Example:
|
||||||
if mt_irc.joined_players["joe"] then
|
if irc.joined_players["joe"] then
|
||||||
-- Joe is talking on IRC
|
-- Joe is talking on IRC
|
||||||
end
|
end
|
||||||
|
|
||||||
mt_irc:register_hook(name, func)
|
irc:register_hook(name, func)
|
||||||
Registers a function to be called when an event happens. <name> is the name
|
Registers a function to be called when an event happens. <name> is the name
|
||||||
of the event, and <func> is the function to be called. See HOOKS below
|
of the event, and <func> is the function to be called. See HOOKS below
|
||||||
for more information
|
for more information
|
||||||
Example:
|
Example:
|
||||||
mt_irc:register_hook("OnSend", function(line)
|
irc:register_hook("OnSend", function(line)
|
||||||
print("SEND: "..line)
|
print("SEND: "..line)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -69,18 +71,18 @@ string.expandvars(string, vars)
|
|||||||
are left verbatim in the string.
|
are left verbatim in the string.
|
||||||
Example:
|
Example:
|
||||||
local tpl = "$(foo) $(bar) $(baz)"
|
local tpl = "$(foo) $(bar) $(baz)"
|
||||||
local s = tpl:expandvars({ foo=1, bar="Hello" })
|
local s = tpl:expandvars({foo=1, bar="Hello"})
|
||||||
assert(s == "1 Hello $(baz)")
|
assert(s == "1 Hello $(baz)")
|
||||||
|
|
||||||
In addition, all the configuration options decribed in `README.txt' are
|
In addition, all the configuration options decribed in `README.txt` are
|
||||||
available to other mods, though they should be considered "read only". Do
|
available to other mods, though they should be considered read-only. Do
|
||||||
not modify these settings at runtime or you will most likely crash the
|
not modify these settings at runtime or you might crash the server!
|
||||||
server!
|
|
||||||
|
|
||||||
|
|
||||||
HOOKS
|
Hooks
|
||||||
---------
|
-----
|
||||||
The 'mt_irc:register_hook' function can register functions to be called
|
|
||||||
|
The `irc:register_hook` function can register functions to be called
|
||||||
when some events happen. The events supported are the same as the LuaIRC
|
when some events happen. The events supported are the same as the LuaIRC
|
||||||
ones with a few added (mostly for internal use).
|
ones with a few added (mostly for internal use).
|
||||||
See src/LuaIRC/doc/irc.luadoc for more information.
|
See src/LuaIRC/doc/irc.luadoc for more information.
|
54
botcmds.lua
54
botcmds.lua
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
mt_irc.bot_commands = {}
|
irc.bot_commands = {}
|
||||||
|
|
||||||
function mt_irc:check_botcmd(msg)
|
function irc:check_botcmd(msg)
|
||||||
local prefix = mt_irc.config.command_prefix
|
local prefix = irc.config.command_prefix
|
||||||
local nick = mt_irc.conn.nick:lower()
|
local nick = irc.conn.nick:lower()
|
||||||
local text = msg.args[2]
|
local text = msg.args[2]
|
||||||
local nickpart = text:sub(1, #nick + 2):lower()
|
local nickpart = text:sub(1, #nick + 2):lower()
|
||||||
|
|
||||||
@ -21,19 +21,19 @@ function mt_irc:check_botcmd(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc:bot_command(msg, text)
|
function irc:bot_command(msg, text)
|
||||||
if text:sub(1, 1) == "@" then
|
if text:sub(1, 1) == "@" then
|
||||||
local found, _, player_to, message = text:find("^.([^%s]+)%s(.+)$")
|
local found, _, player_to, message = text:find("^.([^%s]+)%s(.+)$")
|
||||||
if not minetest.get_player_by_name(player_to) then
|
if not minetest.get_player_by_name(player_to) then
|
||||||
mt_irc:reply("User '"..player_to.."' is not in the game.")
|
irc:reply("User '"..player_to.."' is not in the game.")
|
||||||
return
|
return
|
||||||
elseif not mt_irc.joined_players[player_to] then
|
elseif not irc.joined_players[player_to] then
|
||||||
mt_irc:reply("User '"..player_to.."' is not using IRC.")
|
irc: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)
|
||||||
mt_irc:reply("Message sent!")
|
irc:reply("Message sent!")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local pos = text:find(" ", 1, true)
|
local pos = text:find(" ", 1, true)
|
||||||
@ -56,7 +56,7 @@ function mt_irc:bot_command(msg, text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc:register_bot_command(name, def)
|
function irc: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
|
||||||
@ -66,23 +66,23 @@ function mt_irc:register_bot_command(name, def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
mt_irc:register_bot_command("help", {
|
irc:register_bot_command("help", {
|
||||||
params = "<command>",
|
params = "<command>",
|
||||||
description = "Get help about a command",
|
description = "Get help about a command",
|
||||||
func = function(user, args)
|
func = function(user, args)
|
||||||
if args == "" then
|
if args == "" then
|
||||||
mt_irc:reply("No command name specified. Use 'list' for a list of commands")
|
irc:reply("No command name specified. Use 'list' for a list of commands")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local cmd = mt_irc.bot_commands[args]
|
local cmd = irc.bot_commands[args]
|
||||||
if not cmd then
|
if not cmd then
|
||||||
mt_irc:reply("Unknown command '"..cmdname.."'.")
|
irc:reply("Unknown command '"..cmdname.."'.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
mt_irc:reply(("Usage: %c%s %s -- %s"):format(
|
irc:reply(("Usage: %c%s %s -- %s"):format(
|
||||||
mt_irc.config.command_prefix,
|
irc.config.command_prefix,
|
||||||
args,
|
args,
|
||||||
cmd.params or "<no parameters>",
|
cmd.params or "<no parameters>",
|
||||||
cmd.description or "<no description>"))
|
cmd.description or "<no description>"))
|
||||||
@ -90,48 +90,48 @@ mt_irc:register_bot_command("help", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
mt_irc:register_bot_command("list", {
|
irc:register_bot_command("list", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "List available commands.",
|
description = "List available commands.",
|
||||||
func = function(user, args)
|
func = function(user, args)
|
||||||
local cmdlist = "Available commands: "
|
local cmdlist = "Available commands: "
|
||||||
for name, cmd in pairs(mt_irc.bot_commands) do
|
for name, cmd in pairs(irc.bot_commands) do
|
||||||
cmdlist = cmdlist..name..", "
|
cmdlist = cmdlist..name..", "
|
||||||
end
|
end
|
||||||
mt_irc:reply(cmdlist.." -- Use 'help <command name>' to get"
|
irc:reply(cmdlist.." -- Use 'help <command name>' to get"
|
||||||
.." help about a specific command.")
|
.." help about a specific command.")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
mt_irc:register_bot_command("whereis", {
|
irc:register_bot_command("whereis", {
|
||||||
params = "<player>",
|
params = "<player>",
|
||||||
description = "Tell the location of <player>",
|
description = "Tell the location of <player>",
|
||||||
func = function(user, args)
|
func = function(user, args)
|
||||||
if args == "" then
|
if args == "" then
|
||||||
mt_irc:bot_help(user, "whereis")
|
irc:bot_help(user, "whereis")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local player = minetest.env:get_player_by_name(args)
|
local player = minetest.env:get_player_by_name(args)
|
||||||
if player then
|
if player then
|
||||||
local fmt = "Player %s is at (%.2f,%.2f,%.2f)"
|
local fmt = "Player %s is at (%.2f,%.2f,%.2f)"
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
mt_irc:reply(fmt:format(args, pos.x, pos.y, pos.z))
|
irc:reply(fmt:format(args, pos.x, pos.y, pos.z))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
mt_irc:reply("There is no player named '"..args.."'")
|
irc:reply("There is no player named '"..args.."'")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
local starttime = os.time()
|
local starttime = os.time()
|
||||||
mt_irc:register_bot_command("uptime", {
|
irc: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(user, args)
|
func = function(user, args)
|
||||||
local cur_time = os.time()
|
local cur_time = os.time()
|
||||||
local diff = os.difftime(cur_time, starttime)
|
local diff = os.difftime(cur_time, starttime)
|
||||||
local fmt = "Server has been running for %d:%02d:%02d"
|
local fmt = "Server has been running for %d:%02d:%02d"
|
||||||
mt_irc:reply(fmt:format(
|
irc:reply(fmt:format(
|
||||||
math.floor(diff / 60 / 60),
|
math.floor(diff / 60 / 60),
|
||||||
math.mod(math.floor(diff / 60), 60),
|
math.mod(math.floor(diff / 60), 60),
|
||||||
math.mod(math.floor(diff), 60)
|
math.mod(math.floor(diff), 60)
|
||||||
@ -140,7 +140,7 @@ mt_irc:register_bot_command("uptime", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
mt_irc:register_bot_command("players", {
|
irc:register_bot_command("players", {
|
||||||
description = "List the players on the server",
|
description = "List the players on the server",
|
||||||
func = function(user, args)
|
func = function(user, args)
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
@ -148,7 +148,7 @@ mt_irc:register_bot_command("players", {
|
|||||||
for _, player in pairs(players) do
|
for _, player in pairs(players) do
|
||||||
table.insert(names, player:get_player_name())
|
table.insert(names, player:get_player_name())
|
||||||
end
|
end
|
||||||
mt_irc:reply("Connected players: "
|
irc:reply("Connected players: "
|
||||||
..table.concat(names, ", "))
|
..table.concat(names, ", "))
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
16
callback.lua
16
callback.lua
@ -4,25 +4,25 @@
|
|||||||
|
|
||||||
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 mt_irc.connected and mt_irc.config.send_join_part then
|
if irc.connected and irc.config.send_join_part then
|
||||||
mt_irc:say("*** "..name.." joined the game")
|
irc:say("*** "..name.." joined the game")
|
||||||
end
|
end
|
||||||
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()
|
||||||
if mt_irc.connected and mt_irc.config.send_join_part then
|
if irc.connected and irc.config.send_join_part then
|
||||||
mt_irc:say("*** "..name.." left the game")
|
irc:say("*** "..name.." left the game")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
minetest.register_on_chat_message(function(name, message)
|
minetest.register_on_chat_message(function(name, message)
|
||||||
if not mt_irc.connected
|
if not irc.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 mt_irc.joined_players[name]
|
or not irc.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
|
||||||
@ -30,11 +30,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
|
||||||
mt_irc:say(mt_irc:playerMessage(name, message))
|
irc:say(irc:playerMessage(name, message))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
minetest.register_on_shutdown(function()
|
minetest.register_on_shutdown(function()
|
||||||
mt_irc:disconnect("Game shutting down.")
|
irc:disconnect("Game shutting down.")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
28
chatcmds.lua
28
chatcmds.lua
@ -10,7 +10,7 @@ minetest.register_chatcommand("irc_msg", {
|
|||||||
description = "Send a private message to an IRC user",
|
description = "Send a private message to an IRC user",
|
||||||
privs = {shout=true},
|
privs = {shout=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if not mt_irc.connected then
|
if not irc.connected then
|
||||||
minetest.chat_send_player(name, "Not connected to IRC. Use /irc_connect to connect.")
|
minetest.chat_send_player(name, "Not connected to IRC. Use /irc_connect to connect.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -21,7 +21,7 @@ minetest.register_chatcommand("irc_msg", {
|
|||||||
end
|
end
|
||||||
local toname_l = toname:lower()
|
local toname_l = toname:lower()
|
||||||
local validNick = false
|
local validNick = false
|
||||||
for nick, user in pairs(mt_irc.conn.channels[mt_irc.config.channel].users) do
|
for nick, user in pairs(irc.conn.channels[irc.config.channel].users) do
|
||||||
if nick:lower() == toname_l then
|
if nick:lower() == toname_l then
|
||||||
validNick = true
|
validNick = true
|
||||||
break
|
break
|
||||||
@ -35,7 +35,7 @@ minetest.register_chatcommand("irc_msg", {
|
|||||||
"You can not message that user. (Hint: They have to be in the channel)")
|
"You can not message that user. (Hint: They have to be in the channel)")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
mt_irc:say(toname, mt_irc:playerMessage(name, message))
|
irc:say(toname, irc:playerMessage(name, message))
|
||||||
minetest.chat_send_player(name, "Message sent!")
|
minetest.chat_send_player(name, "Message sent!")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -46,7 +46,7 @@ minetest.register_chatcommand("irc_names", {
|
|||||||
description = "List the users in IRC.",
|
description = "List the users in IRC.",
|
||||||
func = function(name, params)
|
func = function(name, params)
|
||||||
local users = { }
|
local users = { }
|
||||||
for k, v in pairs(mt_irc.conn.channels[mt_irc.config.channel].users) do
|
for k, v in pairs(irc.conn.channels[irc.config.channel].users) do
|
||||||
table.insert(users, k)
|
table.insert(users, k)
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(name, "Users in IRC: "..table.concat(users, ", "))
|
minetest.chat_send_player(name, "Users in IRC: "..table.concat(users, ", "))
|
||||||
@ -58,12 +58,12 @@ minetest.register_chatcommand("irc_connect", {
|
|||||||
description = "Connect to the IRC server.",
|
description = "Connect to the IRC server.",
|
||||||
privs = {irc_admin=true},
|
privs = {irc_admin=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if mt_irc.connected then
|
if irc.connected then
|
||||||
minetest.chat_send_player(name, "You are already connected to IRC.")
|
minetest.chat_send_player(name, "You are already connected to IRC.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(name, "IRC: Connecting...")
|
minetest.chat_send_player(name, "IRC: Connecting...")
|
||||||
mt_irc:connect()
|
irc:connect()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -73,14 +73,14 @@ minetest.register_chatcommand("irc_disconnect", {
|
|||||||
description = "Disconnect from the IRC server.",
|
description = "Disconnect from the IRC server.",
|
||||||
privs = {irc_admin=true},
|
privs = {irc_admin=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if not mt_irc.connected then
|
if not irc.connected then
|
||||||
minetest.chat_send_player(name, "You are not connected to IRC.")
|
minetest.chat_send_player(name, "You are not connected to IRC.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if params == "" then
|
if params == "" then
|
||||||
params = "Manual disconnect by "..name
|
params = "Manual disconnect by "..name
|
||||||
end
|
end
|
||||||
mt_irc:disconnect(param)
|
irc:disconnect(param)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -89,12 +89,12 @@ minetest.register_chatcommand("irc_reconnect", {
|
|||||||
description = "Reconnect to the IRC server.",
|
description = "Reconnect to the IRC server.",
|
||||||
privs = {irc_admin=true},
|
privs = {irc_admin=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if not mt_irc.connected then
|
if not irc.connected then
|
||||||
minetest.chat_send_player(name, "You are not connected to IRC.")
|
minetest.chat_send_player(name, "You are not connected to IRC.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
mt_irc:disconnect("Reconnecting...")
|
irc:disconnect("Reconnecting...")
|
||||||
mt_irc:connect()
|
irc:connect()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -104,11 +104,11 @@ minetest.register_chatcommand("irc_quote", {
|
|||||||
description = "Send a raw command to the IRC server.",
|
description = "Send a raw command to the IRC server.",
|
||||||
privs = {irc_admin=true},
|
privs = {irc_admin=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if not mt_irc.connected then
|
if not irc.connected then
|
||||||
minetest.chat_send_player(name, "You are not connected to IRC.")
|
minetest.chat_send_player(name, "You are not connected to IRC.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
mt_irc:queue(param)
|
irc:queue(param)
|
||||||
minetest.chat_send_player(name, "Command sent!")
|
minetest.chat_send_player(name, "Command sent!")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -117,6 +117,6 @@ minetest.register_chatcommand("irc_quote", {
|
|||||||
local oldme = minetest.chatcommands["me"].func
|
local oldme = minetest.chatcommands["me"].func
|
||||||
minetest.chatcommands["me"].func = function(name, param, ...)
|
minetest.chatcommands["me"].func = function(name, param, ...)
|
||||||
oldme(name, param, ...)
|
oldme(name, param, ...)
|
||||||
mt_irc:say(("* %s %s"):format(name, param))
|
irc:say(("* %s %s"):format(name, param))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
10
config.lua
10
config.lua
@ -2,7 +2,7 @@
|
|||||||
-- See LICENSE.txt for details.
|
-- See LICENSE.txt for details.
|
||||||
|
|
||||||
|
|
||||||
mt_irc.config = {}
|
irc.config = {}
|
||||||
|
|
||||||
local function setting(stype, name, default)
|
local function setting(stype, name, default)
|
||||||
local value
|
local value
|
||||||
@ -16,7 +16,7 @@ local function setting(stype, name, default)
|
|||||||
if value == nil then
|
if value == nil then
|
||||||
value = default
|
value = default
|
||||||
end
|
end
|
||||||
mt_irc.config[name] = value
|
irc.config[name] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
@ -27,7 +27,7 @@ setting("string", "nick") -- Nickname (default "MT-<hash>", <hash> 6 random hexi
|
|||||||
setting("string", "server", "irc.freenode.net") -- Server to connect on joinplayer
|
setting("string", "server", "irc.freenode.net") -- Server to connect on joinplayer
|
||||||
setting("number", "port", 6667) -- Port to connect on joinplayer
|
setting("number", "port", 6667) -- Port to connect on joinplayer
|
||||||
setting("string", "NSPass") -- NickServ password
|
setting("string", "NSPass") -- NickServ password
|
||||||
setting("string", "sasl.user", mt_irc.config.nick) -- SASL username
|
setting("string", "sasl.user", irc.config.nick) -- SASL username
|
||||||
setting("string", "sasl.pass") -- SASL password
|
setting("string", "sasl.pass") -- SASL password
|
||||||
setting("string", "channel", "##mt-irc-mod") -- Channel to join
|
setting("string", "channel", "##mt-irc-mod") -- Channel to join
|
||||||
setting("string", "key") -- Key for the channel
|
setting("string", "key") -- Key for the channel
|
||||||
@ -47,10 +47,10 @@ setting("bool", "auto_join", true) -- Whether to automatically show players in
|
|||||||
setting("bool", "auto_connect", true) -- Whether to automatically connect to the server on mod load
|
setting("bool", "auto_connect", true) -- Whether to automatically connect to the server on mod load
|
||||||
|
|
||||||
-- Generate a random nickname if one isn't specified.
|
-- Generate a random nickname if one isn't specified.
|
||||||
if not mt_irc.config.nick then
|
if not irc.config.nick then
|
||||||
local pr = PseudoRandom(os.time())
|
local pr = PseudoRandom(os.time())
|
||||||
-- Workaround for bad distribution in minetest PRNG implementation.
|
-- Workaround for bad distribution in minetest PRNG implementation.
|
||||||
mt_irc.config.nick = ("MT-%02X%02X%02X"):format(
|
irc.config.nick = ("MT-%02X%02X%02X"):format(
|
||||||
pr:next(0, 255),
|
pr:next(0, 255),
|
||||||
pr:next(0, 255),
|
pr:next(0, 255),
|
||||||
pr:next(0, 255)
|
pr:next(0, 255)
|
||||||
|
140
hooks.lua
140
hooks.lua
@ -2,8 +2,8 @@
|
|||||||
-- See LICENSE.txt for details.
|
-- See LICENSE.txt for details.
|
||||||
|
|
||||||
|
|
||||||
mt_irc.hooks = {}
|
irc.hooks = {}
|
||||||
mt_irc.registered_hooks = {}
|
irc.registered_hooks = {}
|
||||||
|
|
||||||
|
|
||||||
-- TODO: Add proper conversion from CP1252 to UTF-8.
|
-- TODO: Add proper conversion from CP1252 to UTF-8.
|
||||||
@ -21,7 +21,7 @@ local function normalize(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc:doHook(conn)
|
function irc:doHook(conn)
|
||||||
for name, hook in pairs(self.registered_hooks) do
|
for name, hook in pairs(self.registered_hooks) do
|
||||||
for _, func in pairs(hook) do
|
for _, func in pairs(hook) do
|
||||||
conn:hook(name, func)
|
conn:hook(name, func)
|
||||||
@ -30,59 +30,59 @@ function mt_irc:doHook(conn)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc:register_hook(name, func)
|
function irc:register_hook(name, func)
|
||||||
self.registered_hooks[name] = self.registered_hooks[name] or {}
|
self.registered_hooks[name] = self.registered_hooks[name] or {}
|
||||||
table.insert(self.registered_hooks[name], func)
|
table.insert(self.registered_hooks[name], func)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.raw(line)
|
function irc.hooks.raw(line)
|
||||||
if mt_irc.config.debug then
|
if irc.config.debug then
|
||||||
print("RECV: "..line)
|
print("RECV: "..line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.send(line)
|
function irc.hooks.send(line)
|
||||||
if mt_irc.config.debug then
|
if irc.config.debug then
|
||||||
print("SEND: "..line)
|
print("SEND: "..line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.chat(msg)
|
function irc.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
|
||||||
mt_irc.conn:invoke("OnCTCP", msg)
|
irc.conn:invoke("OnCTCP", msg)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if channel == mt_irc.conn.nick then
|
if channel == irc.conn.nick then
|
||||||
mt_irc.last_from = msg.user.nick
|
irc.last_from = msg.user.nick
|
||||||
mt_irc.conn:invoke("PrivateMessage", msg)
|
irc.conn:invoke("PrivateMessage", msg)
|
||||||
else
|
else
|
||||||
mt_irc.last_from = channel
|
irc.last_from = channel
|
||||||
mt_irc.conn:invoke("OnChannelChat", msg)
|
irc.conn:invoke("OnChannelChat", msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.ctcp(msg)
|
function irc.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)
|
||||||
mt_irc:queue(irc.msgs.notice(msg.user.nick,
|
irc:queue(irc.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] == mt_irc.config.channel then
|
if command == "ACTION" and msg.args[1] == irc.config.channel then
|
||||||
local action = text:sub(8, -1)
|
local action = text:sub(8, -1)
|
||||||
mt_irc:sendLocal(("* %s@IRC %s"):format(msg.user.nick, action))
|
irc:sendLocal(("* %s@IRC %s"):format(msg.user.nick, action))
|
||||||
elseif command == "VERSION" then
|
elseif command == "VERSION" then
|
||||||
reply(("Minetest IRC mod version %s.")
|
reply(("Minetest IRC mod version %s.")
|
||||||
:format(mt_irc.version))
|
:format(irc.version))
|
||||||
elseif command == "PING" then
|
elseif command == "PING" then
|
||||||
reply(args[2])
|
reply(args[2])
|
||||||
elseif command == "TIME" then
|
elseif command == "TIME" then
|
||||||
@ -91,7 +91,7 @@ function mt_irc.hooks.ctcp(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.channelChat(msg)
|
function irc.hooks.channelChat(msg)
|
||||||
local text = normalize(msg.args[2])
|
local text = normalize(msg.args[2])
|
||||||
|
|
||||||
-- Support multiple servers in a channel better by converting:
|
-- Support multiple servers in a channel better by converting:
|
||||||
@ -107,58 +107,58 @@ function mt_irc.hooks.channelChat(msg)
|
|||||||
local foundaction, _, actionnick, actionmessage =
|
local foundaction, _, actionnick, actionmessage =
|
||||||
text:find("^%* ([^%s]+) (.*)$")
|
text:find("^%* ([^%s]+) (.*)$")
|
||||||
|
|
||||||
mt_irc:check_botcmd(msg)
|
irc:check_botcmd(msg)
|
||||||
|
|
||||||
if text:sub(1, 5) == "[off]" then
|
if text:sub(1, 5) == "[off]" then
|
||||||
return
|
return
|
||||||
elseif foundchat then
|
elseif foundchat then
|
||||||
mt_irc:sendLocal(("<%s@%s> %s")
|
irc:sendLocal(("<%s@%s> %s")
|
||||||
:format(chatnick, msg.user.nick, chatmessage))
|
:format(chatnick, msg.user.nick, chatmessage))
|
||||||
elseif foundjoin then
|
elseif foundjoin then
|
||||||
mt_irc:sendLocal(("*** %s joined %s")
|
irc:sendLocal(("*** %s joined %s")
|
||||||
:format(joinnick, msg.user.nick))
|
:format(joinnick, msg.user.nick))
|
||||||
elseif foundleave then
|
elseif foundleave then
|
||||||
mt_irc:sendLocal(("*** %s left %s")
|
irc:sendLocal(("*** %s left %s")
|
||||||
:format(leavenick, msg.user.nick))
|
:format(leavenick, msg.user.nick))
|
||||||
elseif foundaction then
|
elseif foundaction then
|
||||||
mt_irc:sendLocal(("* %s@%s %s")
|
irc:sendLocal(("* %s@%s %s")
|
||||||
:format(actionnick, msg.user.nick, actionmessage))
|
:format(actionnick, msg.user.nick, actionmessage))
|
||||||
else
|
else
|
||||||
mt_irc:sendLocal(("<%s@IRC> %s"):format(msg.user.nick, text))
|
irc:sendLocal(("<%s@IRC> %s"):format(msg.user.nick, text))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.pm(msg)
|
function irc.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 = mt_irc.config.command_prefix
|
local prefix = irc.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
|
||||||
mt_irc:bot_command(msg, text)
|
irc:bot_command(msg, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.kick(channel, target, prefix, reason)
|
function irc.hooks.kick(channel, target, prefix, reason)
|
||||||
if target == mt_irc.conn.nick then
|
if target == irc.conn.nick then
|
||||||
minetest.chat_send_all("IRC: kicked from "..channel.." by "..prefix.nick..".")
|
minetest.chat_send_all("IRC: kicked from "..channel.." by "..prefix.nick..".")
|
||||||
mt_irc:disconnect("Kicked")
|
irc:disconnect("Kicked")
|
||||||
else
|
else
|
||||||
mt_irc:sendLocal(("-!- %s was kicked from %s by %s [%s]")
|
irc:sendLocal(("-!- %s was kicked from %s by %s [%s]")
|
||||||
:format(target, channel, prefix.nick, reason))
|
:format(target, channel, prefix.nick, reason))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.notice(user, target, message)
|
function irc.hooks.notice(user, target, message)
|
||||||
if user.nick and target == mt_irc.config.channel then
|
if user.nick and target == irc.config.channel then
|
||||||
mt_irc:sendLocal("-"..user.nick.."@IRC- "..message)
|
irc:sendLocal("-"..user.nick.."@IRC- "..message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.mode(user, target, modes, ...)
|
function irc.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
|
||||||
@ -173,37 +173,37 @@ function mt_irc.hooks.mode(user, target, modes, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.nick(user, newNick)
|
function irc.hooks.nick(user, newNick)
|
||||||
mt_irc:sendLocal(("-!- %s is now known as %s")
|
irc:sendLocal(("-!- %s is now known as %s")
|
||||||
:format(user.nick, newNick))
|
:format(user.nick, newNick))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.join(user, channel)
|
function irc.hooks.join(user, channel)
|
||||||
mt_irc:sendLocal(("-!- %s joined %s")
|
irc:sendLocal(("-!- %s joined %s")
|
||||||
:format(user.nick, channel))
|
:format(user.nick, channel))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.part(user, channel, reason)
|
function irc.hooks.part(user, channel, reason)
|
||||||
reason = reason or ""
|
reason = reason or ""
|
||||||
mt_irc:sendLocal(("-!- %s has left %s [%s]")
|
irc:sendLocal(("-!- %s has left %s [%s]")
|
||||||
:format(user.nick, channel, reason))
|
:format(user.nick, channel, reason))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.quit(user, reason)
|
function irc.hooks.quit(user, reason)
|
||||||
mt_irc:sendLocal(("-!- %s has quit [%s]")
|
irc:sendLocal(("-!- %s has quit [%s]")
|
||||||
:format(user.nick, reason))
|
:format(user.nick, reason))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.disconnect(message, isError)
|
function irc.hooks.disconnect(message, isError)
|
||||||
mt_irc.connected = false
|
irc.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, mt_irc.connect, mt_irc)
|
minetest.after(60, irc.connect, irc)
|
||||||
else
|
else
|
||||||
minetest.log("action", "IRC: Disconnected.")
|
minetest.log("action", "IRC: Disconnected.")
|
||||||
minetest.chat_send_all("IRC: Disconnected.")
|
minetest.chat_send_all("IRC: Disconnected.")
|
||||||
@ -211,13 +211,13 @@ function mt_irc.hooks.disconnect(message, isError)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc.hooks.preregister(conn)
|
function irc.hooks.preregister(conn)
|
||||||
if not (mt_irc.config["sasl.user"] and mt_irc.config["sasl.pass"]) then return end
|
if not (irc.config["sasl.user"] and irc.config["sasl.pass"]) then return end
|
||||||
local authString = mt_irc.b64e(
|
local authString = irc.b64e(
|
||||||
("%s\x00%s\x00%s"):format(
|
("%s\x00%s\x00%s"):format(
|
||||||
mt_irc.config["sasl.user"],
|
irc.config["sasl.user"],
|
||||||
mt_irc.config["sasl.user"],
|
irc.config["sasl.user"],
|
||||||
mt_irc.config["sasl.pass"])
|
irc.config["sasl.pass"])
|
||||||
)
|
)
|
||||||
conn:send("CAP REQ sasl")
|
conn:send("CAP REQ sasl")
|
||||||
conn:send("AUTHENTICATE PLAIN")
|
conn:send("AUTHENTICATE PLAIN")
|
||||||
@ -226,19 +226,19 @@ function mt_irc.hooks.preregister(conn)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
mt_irc:register_hook("PreRegister", mt_irc.hooks.preregister)
|
irc:register_hook("PreRegister", irc.hooks.preregister)
|
||||||
mt_irc:register_hook("OnRaw", mt_irc.hooks.raw)
|
irc:register_hook("OnRaw", irc.hooks.raw)
|
||||||
mt_irc:register_hook("OnSend", mt_irc.hooks.send)
|
irc:register_hook("OnSend", irc.hooks.send)
|
||||||
mt_irc:register_hook("DoPrivmsg", mt_irc.hooks.chat)
|
irc:register_hook("DoPrivmsg", irc.hooks.chat)
|
||||||
mt_irc:register_hook("OnPart", mt_irc.hooks.part)
|
irc:register_hook("OnPart", irc.hooks.part)
|
||||||
mt_irc:register_hook("OnKick", mt_irc.hooks.kick)
|
irc:register_hook("OnKick", irc.hooks.kick)
|
||||||
mt_irc:register_hook("OnJoin", mt_irc.hooks.join)
|
irc:register_hook("OnJoin", irc.hooks.join)
|
||||||
mt_irc:register_hook("OnQuit", mt_irc.hooks.quit)
|
irc:register_hook("OnQuit", irc.hooks.quit)
|
||||||
mt_irc:register_hook("NickChange", mt_irc.hooks.nick)
|
irc:register_hook("NickChange", irc.hooks.nick)
|
||||||
mt_irc:register_hook("OnCTCP", mt_irc.hooks.ctcp)
|
irc:register_hook("OnCTCP", irc.hooks.ctcp)
|
||||||
mt_irc:register_hook("PrivateMessage", mt_irc.hooks.pm)
|
irc:register_hook("PrivateMessage", irc.hooks.pm)
|
||||||
mt_irc:register_hook("OnNotice", mt_irc.hooks.notice)
|
irc:register_hook("OnNotice", irc.hooks.notice)
|
||||||
mt_irc:register_hook("OnChannelChat", mt_irc.hooks.channelChat)
|
irc:register_hook("OnChannelChat", irc.hooks.channelChat)
|
||||||
mt_irc:register_hook("OnModeChange", mt_irc.hooks.mode)
|
irc:register_hook("OnModeChange", irc.hooks.mode)
|
||||||
mt_irc:register_hook("OnDisconnect", mt_irc.hooks.disconnect)
|
irc:register_hook("OnDisconnect", irc.hooks.disconnect)
|
||||||
|
|
||||||
|
28
init.lua
28
init.lua
@ -10,7 +10,7 @@ package.path =
|
|||||||
-- For LuaIRC to find its files
|
-- For LuaIRC to find its files
|
||||||
..modpath.."/?.lua"
|
..modpath.."/?.lua"
|
||||||
|
|
||||||
mt_irc = {
|
irc = {
|
||||||
version = "0.2.0",
|
version = "0.2.0",
|
||||||
connected = false,
|
connected = false,
|
||||||
cur_time = 0,
|
cur_time = 0,
|
||||||
@ -20,7 +20,9 @@ mt_irc = {
|
|||||||
modpath = modpath,
|
modpath = modpath,
|
||||||
lib = require("irc"),
|
lib = require("irc"),
|
||||||
}
|
}
|
||||||
local irc = mt_irc.lib
|
|
||||||
|
-- Compatibility
|
||||||
|
mt_irc = irc
|
||||||
|
|
||||||
dofile(modpath.."/config.lua")
|
dofile(modpath.."/config.lua")
|
||||||
dofile(modpath.."/messages.lua")
|
dofile(modpath.."/messages.lua")
|
||||||
@ -29,10 +31,10 @@ dofile(modpath.."/callback.lua")
|
|||||||
dofile(modpath.."/chatcmds.lua")
|
dofile(modpath.."/chatcmds.lua")
|
||||||
dofile(modpath.."/botcmds.lua")
|
dofile(modpath.."/botcmds.lua")
|
||||||
dofile(modpath.."/util.lua")
|
dofile(modpath.."/util.lua")
|
||||||
if mt_irc.config.enable_player_part then
|
if irc.config.enable_player_part then
|
||||||
dofile(modpath.."/player_part.lua")
|
dofile(modpath.."/player_part.lua")
|
||||||
else
|
else
|
||||||
setmetatable(mt_irc.joined_players, {__index = function(index) return true end})
|
setmetatable(irc.joined_players, {__index = function(index) return true end})
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_privilege("irc_admin", {
|
minetest.register_privilege("irc_admin", {
|
||||||
@ -42,9 +44,9 @@ minetest.register_privilege("irc_admin", {
|
|||||||
|
|
||||||
local stepnum = 0
|
local stepnum = 0
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime) return mt_irc:step(dtime) end)
|
minetest.register_globalstep(function(dtime) return irc:step(dtime) end)
|
||||||
|
|
||||||
function mt_irc:step(dtime)
|
function irc:step(dtime)
|
||||||
if stepnum == 3 then
|
if stepnum == 3 then
|
||||||
if self.config.auto_connect then
|
if self.config.auto_connect then
|
||||||
self:connect()
|
self:connect()
|
||||||
@ -63,12 +65,12 @@ function mt_irc:step(dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc:connect()
|
function irc:connect()
|
||||||
if self.connected then
|
if self.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
|
||||||
self.conn = irc.new({
|
self.conn = irc.lib.new({
|
||||||
nick = self.config.nick,
|
nick = self.config.nick,
|
||||||
username = "Minetest",
|
username = "Minetest",
|
||||||
realname = "Minetest",
|
realname = "Minetest",
|
||||||
@ -102,7 +104,7 @@ function mt_irc:connect()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc:disconnect(message)
|
function irc:disconnect(message)
|
||||||
if self.connected then
|
if self.connected then
|
||||||
--The OnDisconnect hook will clear self.connected and print a disconnect message
|
--The OnDisconnect hook will clear self.connected and print a disconnect message
|
||||||
self.conn:disconnect(message)
|
self.conn:disconnect(message)
|
||||||
@ -110,7 +112,7 @@ function mt_irc:disconnect(message)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc:say(to, message)
|
function irc:say(to, message)
|
||||||
if not message then
|
if not message then
|
||||||
message = to
|
message = to
|
||||||
to = self.config.channel
|
to = self.config.channel
|
||||||
@ -121,18 +123,18 @@ function mt_irc:say(to, message)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mt_irc:reply(message)
|
function irc:reply(message)
|
||||||
if not self.last_from then
|
if not self.last_from then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self:say(self.last_from, message)
|
self:say(self.last_from, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mt_irc:send(msg)
|
function irc:send(msg)
|
||||||
self.conn:send(msg)
|
self.conn:send(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mt_irc:queue(msg)
|
function irc:queue(msg)
|
||||||
self.conn:queue(msg)
|
self.conn:queue(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
-- 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.
|
||||||
|
|
||||||
mt_irc.msgs = mt_irc.lib.msgs
|
irc.msgs = irc.lib.msgs
|
||||||
|
|
||||||
function mt_irc:sendLocal(message)
|
function irc:sendLocal(message)
|
||||||
minetest.chat_send_all(message)
|
minetest.chat_send_all(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mt_irc:playerMessage(name, message)
|
function irc:playerMessage(name, message)
|
||||||
return ("<%s> %s"):format(name, message)
|
return ("<%s> %s"):format(name, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
-- See LICENSE.txt for details.
|
-- See LICENSE.txt for details.
|
||||||
|
|
||||||
|
|
||||||
function mt_irc:player_part(name)
|
function irc:player_part(name)
|
||||||
if not self.joined_players[name] then
|
if not self.joined_players[name] then
|
||||||
minetest.chat_send_player(name, "IRC: You are not in the channel.")
|
minetest.chat_send_player(name, "IRC: You are not in the channel.")
|
||||||
return
|
return
|
||||||
@ -11,7 +11,7 @@ function mt_irc:player_part(name)
|
|||||||
minetest.chat_send_player(name, "IRC: You are now out of the channel.")
|
minetest.chat_send_player(name, "IRC: You are now out of the channel.")
|
||||||
end
|
end
|
||||||
|
|
||||||
function mt_irc:player_join(name)
|
function irc:player_join(name)
|
||||||
if self.joined_players[name] then
|
if self.joined_players[name] then
|
||||||
minetest.chat_send_player(name, "IRC: You are already in the channel.")
|
minetest.chat_send_player(name, "IRC: You are already in the channel.")
|
||||||
return
|
return
|
||||||
@ -25,7 +25,7 @@ minetest.register_chatcommand("join", {
|
|||||||
description = "Join the IRC channel",
|
description = "Join the IRC channel",
|
||||||
privs = {shout=true},
|
privs = {shout=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
mt_irc:player_join(name)
|
irc:player_join(name)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ minetest.register_chatcommand("part", {
|
|||||||
description = "Part the IRC channel",
|
description = "Part the IRC channel",
|
||||||
privs = {shout=true},
|
privs = {shout=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
mt_irc:player_part(name)
|
irc:player_part(name)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ minetest.register_chatcommand("who", {
|
|||||||
privs = {},
|
privs = {},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local s = ""
|
local s = ""
|
||||||
for name, _ in pairs(mt_irc.joined_players) do
|
for name, _ in pairs(irc.joined_players) do
|
||||||
s = s..", "..name
|
s = s..", "..name
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(name, "Players On Channel:"..s)
|
minetest.chat_send_player(name, "Players On Channel:"..s)
|
||||||
@ -52,16 +52,16 @@ 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()
|
||||||
mt_irc.joined_players[name] = mt_irc.config.auto_join
|
irc.joined_players[name] = irc.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()
|
||||||
mt_irc.joined_players[name] = nil
|
irc.joined_players[name] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function mt_irc:sendLocal(message)
|
function irc:sendLocal(message)
|
||||||
for name, _ in pairs(self.joined_players) do
|
for name, _ in pairs(self.joined_players) do
|
||||||
minetest.chat_send_player(name, message)
|
minetest.chat_send_player(name, message)
|
||||||
end
|
end
|
||||||
|
2
util.lua
2
util.lua
@ -1,6 +1,6 @@
|
|||||||
--Base 64 encode -- for SASL authentication
|
--Base 64 encode -- for SASL authentication
|
||||||
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||||
function mt_irc.b64e(data)
|
function irc.b64e(data)
|
||||||
return ((data:gsub('.', function(x)
|
return ((data:gsub('.', function(x)
|
||||||
local r,b='',x:byte()
|
local r,b='',x:byte()
|
||||||
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
|
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
|
||||||
|
Loading…
Reference in New Issue
Block a user