forked from minetest-mods/irc
Change spaces to tabs
This commit is contained in:
parent
63c2b52c41
commit
3aede000b7
198
CMakeLists.txt
198
CMakeLists.txt
@ -10,63 +10,63 @@ set(MINETEST_IRC_VERSION 0.1.0)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
set(LUA_SRCS
|
||||
src/lua/lapi.c
|
||||
src/lua/lcode.c
|
||||
src/lua/ldebug.c
|
||||
src/lua/ldo.c
|
||||
src/lua/ldump.c
|
||||
src/lua/lfunc.c
|
||||
src/lua/lgc.c
|
||||
src/lua/llex.c
|
||||
src/lua/lmem.c
|
||||
src/lua/lobject.c
|
||||
src/lua/lopcodes.c
|
||||
src/lua/lparser.c
|
||||
src/lua/lstate.c
|
||||
src/lua/lstring.c
|
||||
src/lua/ltable.c
|
||||
src/lua/ltm.c
|
||||
src/lua/lundump.c
|
||||
src/lua/lvm.c
|
||||
src/lua/lzio.c
|
||||
src/lua/lauxlib.c
|
||||
src/lua/lbaselib.c
|
||||
src/lua/ldblib.c
|
||||
src/lua/liolib.c
|
||||
src/lua/lmathlib.c
|
||||
src/lua/loslib.c
|
||||
src/lua/ltablib.c
|
||||
src/lua/lstrlib.c
|
||||
src/lua/loadlib.c
|
||||
src/lua/linit.c
|
||||
src/lua/lapi.c
|
||||
src/lua/lcode.c
|
||||
src/lua/ldebug.c
|
||||
src/lua/ldo.c
|
||||
src/lua/ldump.c
|
||||
src/lua/lfunc.c
|
||||
src/lua/lgc.c
|
||||
src/lua/llex.c
|
||||
src/lua/lmem.c
|
||||
src/lua/lobject.c
|
||||
src/lua/lopcodes.c
|
||||
src/lua/lparser.c
|
||||
src/lua/lstate.c
|
||||
src/lua/lstring.c
|
||||
src/lua/ltable.c
|
||||
src/lua/ltm.c
|
||||
src/lua/lundump.c
|
||||
src/lua/lvm.c
|
||||
src/lua/lzio.c
|
||||
src/lua/lauxlib.c
|
||||
src/lua/lbaselib.c
|
||||
src/lua/ldblib.c
|
||||
src/lua/liolib.c
|
||||
src/lua/lmathlib.c
|
||||
src/lua/loslib.c
|
||||
src/lua/ltablib.c
|
||||
src/lua/lstrlib.c
|
||||
src/lua/loadlib.c
|
||||
src/lua/linit.c
|
||||
)
|
||||
|
||||
set(LUASOCKET_SRCS
|
||||
src/luasocket/compat51.c
|
||||
src/luasocket/luasocket.c
|
||||
src/luasocket/timeout.c
|
||||
src/luasocket/buffer.c
|
||||
src/luasocket/io.c
|
||||
src/luasocket/auxiliar.c
|
||||
src/luasocket/options.c
|
||||
src/luasocket/inet.c
|
||||
src/luasocket/tcp.c
|
||||
src/luasocket/udp.c
|
||||
src/luasocket/except.c
|
||||
src/luasocket/select.c
|
||||
src/luasocket/buffer.c
|
||||
src/luasocket/auxiliar.c
|
||||
src/luasocket/options.c
|
||||
src/luasocket/timeout.c
|
||||
src/luasocket/io.c
|
||||
src/luasocket/mime.c
|
||||
src/luasocket/compat51.c
|
||||
src/luasocket/luasocket.c
|
||||
src/luasocket/timeout.c
|
||||
src/luasocket/buffer.c
|
||||
src/luasocket/io.c
|
||||
src/luasocket/auxiliar.c
|
||||
src/luasocket/options.c
|
||||
src/luasocket/inet.c
|
||||
src/luasocket/tcp.c
|
||||
src/luasocket/udp.c
|
||||
src/luasocket/except.c
|
||||
src/luasocket/select.c
|
||||
src/luasocket/buffer.c
|
||||
src/luasocket/auxiliar.c
|
||||
src/luasocket/options.c
|
||||
src/luasocket/timeout.c
|
||||
src/luasocket/io.c
|
||||
src/luasocket/mime.c
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND LUASOCKET_SRCS src/luasocket/wsocket.c)
|
||||
set(LUASOCKET_EXTRA_LIBS -lwininet)
|
||||
list(APPEND LUASOCKET_SRCS src/luasocket/wsocket.c)
|
||||
set(LUASOCKET_EXTRA_LIBS -lwininet)
|
||||
else()
|
||||
list(APPEND LUASOCKET_SRCS src/luasocket/usocket.c src/luasocket/unix.c)
|
||||
list(APPEND LUASOCKET_SRCS src/luasocket/usocket.c src/luasocket/unix.c)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
@ -76,68 +76,68 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/luasocket)
|
||||
add_library(luasocket_lib MODULE ${LUASOCKET_SRCS} ${LUA_SRCS})
|
||||
|
||||
set_target_properties(luasocket_lib PROPERTIES
|
||||
OUTPUT_NAME luasocket)
|
||||
OUTPUT_NAME luasocket)
|
||||
|
||||
if(WIN32)
|
||||
# When using MinGW32, CMake prefixes DLLs with "lib". Force remove
|
||||
# this prefix regardless of compiler.
|
||||
set_target_properties(luasocket_lib PROPERTIES
|
||||
PREFIX "")
|
||||
if (NOT MSVC) # GCC?
|
||||
# The `-fPIC' flag generates a warning on MinGW32, which combined
|
||||
# with `-Werror' makes that an error though `-fPIC' is ignored.
|
||||
# We use `-fno-PIC' to avoid that.
|
||||
set_target_properties(luasocket_lib PROPERTIES
|
||||
COMPILE_FLAGS "-fno-PIC -Wall -Werror")
|
||||
endif()
|
||||
find_library(ws2_32_lib NAMES ws2_32)
|
||||
target_link_libraries(luasocket_lib ${ws2_32_lib})
|
||||
# When using MinGW32, CMake prefixes DLLs with "lib". Force remove
|
||||
# this prefix regardless of compiler.
|
||||
set_target_properties(luasocket_lib PROPERTIES
|
||||
PREFIX "")
|
||||
if (NOT MSVC) # GCC?
|
||||
# The `-fPIC' flag generates a warning on MinGW32, which combined
|
||||
# with `-Werror' makes that an error though `-fPIC' is ignored.
|
||||
# We use `-fno-PIC' to avoid that.
|
||||
set_target_properties(luasocket_lib PROPERTIES
|
||||
COMPILE_FLAGS "-fno-PIC -Wall -Werror")
|
||||
endif()
|
||||
find_library(ws2_32_lib NAMES ws2_32)
|
||||
target_link_libraries(luasocket_lib ${ws2_32_lib})
|
||||
else() # Possibly Unix
|
||||
set_target_properties(luasocket_lib PROPERTIES
|
||||
COMPILE_FLAGS "-Wall -Werror")
|
||||
set_target_properties(luasocket_lib PROPERTIES
|
||||
COMPILE_FLAGS "-Wall -Werror")
|
||||
endif()
|
||||
|
||||
set(dir ${CMAKE_CURRENT_BINARY_DIR}/irc/)
|
||||
|
||||
if(WIN32)
|
||||
set(lib "${CMAKE_CURRENT_BINARY_DIR}/luasocket.dll")
|
||||
set(lib "${CMAKE_CURRENT_BINARY_DIR}/luasocket.dll")
|
||||
else()
|
||||
set(lib "${CMAKE_CURRENT_BINARY_DIR}/libluasocket.so")
|
||||
set(lib "${CMAKE_CURRENT_BINARY_DIR}/libluasocket.so")
|
||||
endif()
|
||||
|
||||
add_custom_target(pack_mod
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
||||
# LuaIRC
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luairc/irc.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory src/luairc/irc ${dir}/irc
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/LICENSE-LuaIRC.txt ${dir}
|
||||
# LuaIRC
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luairc/irc.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory src/luairc/irc ${dir}/irc
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/LICENSE-LuaIRC.txt ${dir}
|
||||
|
||||
# luasocket
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/ftp.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/http.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/ltn12.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/mime.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/smtp.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/socket.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/tp.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/url.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/LICENSE-luasocket.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${lib} ${dir}
|
||||
# luasocket
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/ftp.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/http.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/ltn12.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/mime.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/smtp.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/socket.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/tp.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/luasocket/url.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/LICENSE-luasocket.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${lib} ${dir}
|
||||
|
||||
# IRC mod
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/init.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/config.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/callback.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/friends.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/chatcmds.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/botcmds.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy README.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/API.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/LICENSE.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/CHANGES.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/TODO.txt ${dir}
|
||||
# IRC mod
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/init.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/config.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/callback.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/friends.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/chatcmds.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy src/botcmds.lua ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy README.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/API.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/LICENSE.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/CHANGES.txt ${dir}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy doc/TODO.txt ${dir}
|
||||
)
|
||||
|
139
src/botcmds.lua
139
src/botcmds.lua
@ -2,91 +2,90 @@
|
||||
mt_irc.bot_commands = { };
|
||||
|
||||
mt_irc.bot_help = function ( from, cmdname )
|
||||
local cmd = mt_irc.bot_commands[cmdname];
|
||||
if (not cmd) then
|
||||
irc.say(from, "Unknown command `"..cmdname.."'");
|
||||
return;
|
||||
end
|
||||
local usage = "Usage: !"..cmdname;
|
||||
if (cmd.params) then usage = usage.." "..cmd.params; end
|
||||
irc.say(from, usage);
|
||||
if (cmd.description) then irc.say(from, " "..cmd.description); end
|
||||
local cmd = mt_irc.bot_commands[cmdname];
|
||||
if (not cmd) then
|
||||
irc.say(from, "Unknown command `"..cmdname.."'");
|
||||
return;
|
||||
end
|
||||
local usage = "Usage: !"..cmdname;
|
||||
if (cmd.params) then usage = usage.." "..cmd.params; end
|
||||
irc.say(from, usage);
|
||||
if (cmd.description) then irc.say(from, " "..cmd.description); end
|
||||
end
|
||||
|
||||
mt_irc.register_bot_command = function ( name, def )
|
||||
if ((not def.func) or (type(def.func) ~= "function")) then
|
||||
error("Wrong bot command definition", 2);
|
||||
end
|
||||
mt_irc.bot_commands[name] = def;
|
||||
if ((not def.func) or (type(def.func) ~= "function")) then
|
||||
error("Wrong bot command definition", 2);
|
||||
end
|
||||
mt_irc.bot_commands[name] = def;
|
||||
end
|
||||
|
||||
mt_irc.register_bot_command("help", {
|
||||
params = "[<command>]";
|
||||
description = "Get help about a command";
|
||||
func = function ( from, args )
|
||||
if (args ~= "") then
|
||||
mt_irc.bot_help(from, args);
|
||||
else
|
||||
local cmdlist = "Available commands:";
|
||||
for name,cmd in pairs(mt_irc.bot_commands) do
|
||||
cmdlist = cmdlist.." "..name;
|
||||
end
|
||||
irc.say(from, cmdlist);
|
||||
irc.say(from, "Use `!help <command name>' to get help about a specific command.");
|
||||
end
|
||||
end;
|
||||
params = "[<command>]";
|
||||
description = "Get help about a command";
|
||||
func = function ( from, args )
|
||||
if (args ~= "") then
|
||||
mt_irc.bot_help(from, args);
|
||||
else
|
||||
local cmdlist = "Available commands:";
|
||||
for name,cmd in pairs(mt_irc.bot_commands) do
|
||||
cmdlist = cmdlist.." "..name;
|
||||
end
|
||||
irc.say(from, cmdlist);
|
||||
irc.say(from, "Use `!help <command name>' to get help about a specific command.");
|
||||
end
|
||||
end;
|
||||
});
|
||||
|
||||
mt_irc.register_bot_command("who", {
|
||||
params = nil;
|
||||
description = "Tell who is playing";
|
||||
func = function ( from, args )
|
||||
local s = "";
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then
|
||||
s = s.." "..k;
|
||||
end
|
||||
end
|
||||
irc.say(from, "Players On Channel:"..s);
|
||||
end;
|
||||
params = nil;
|
||||
description = "Tell who is playing";
|
||||
func = function ( from, args )
|
||||
local s = "";
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then
|
||||
s = s.." "..k;
|
||||
end
|
||||
end
|
||||
irc.say(from, "Players On Channel:"..s);
|
||||
end;
|
||||
});
|
||||
|
||||
mt_irc.register_bot_command("whereis", {
|
||||
params = "<player>";
|
||||
description = "Tell the location of <player>";
|
||||
|
||||
func = function ( from, args )
|
||||
if (args == "") then
|
||||
mt_irc.bot_help(from, "whereis");
|
||||
return;
|
||||
end
|
||||
local list = minetest.env:get_objects_inside_radius({x=0,y=0,z=0}, 100000);
|
||||
for _, obj in ipairs(list) do
|
||||
if (obj:is_player() and (obj:get_player_name() == args)) then
|
||||
local fmt = "Player %s is at (%.2f,%.2f,%.2f)";
|
||||
local pos = obj:getpos();
|
||||
irc.say(from, fmt:format(args, pos.x, pos.y, pos.z));
|
||||
return;
|
||||
end
|
||||
end
|
||||
irc.say(from, "There's No player named `"..args.."'");
|
||||
end;
|
||||
params = "<player>";
|
||||
description = "Tell the location of <player>";
|
||||
func = function ( from, args )
|
||||
if (args == "") then
|
||||
mt_irc.bot_help(from, "whereis");
|
||||
return;
|
||||
end
|
||||
local list = minetest.env:get_objects_inside_radius({x=0,y=0,z=0}, 100000);
|
||||
for _, obj in ipairs(list) do
|
||||
if (obj:is_player() and (obj:get_player_name() == args)) then
|
||||
local fmt = "Player %s is at (%.2f,%.2f,%.2f)";
|
||||
local pos = obj:getpos();
|
||||
irc.say(from, fmt:format(args, pos.x, pos.y, pos.z));
|
||||
return;
|
||||
end
|
||||
end
|
||||
irc.say(from, "There's No player named `"..args.."'");
|
||||
end;
|
||||
});
|
||||
|
||||
local starttime = os.time();
|
||||
|
||||
mt_irc.register_bot_command("uptime", {
|
||||
params = "";
|
||||
description = "Tell how much time the server has been up";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
local t = os.time();
|
||||
local diff = os.difftime(t, starttime);
|
||||
local fmt = "Server has been running for %d:%02d:%02d";
|
||||
irc.say(name, fmt:format(
|
||||
math.floor(diff / 60 / 60),
|
||||
math.mod(math.floor(diff / 60), 60),
|
||||
math.mod(math.floor(diff), 60)
|
||||
));
|
||||
end;
|
||||
params = "";
|
||||
description = "Tell how much time the server has been up";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
local t = os.time();
|
||||
local diff = os.difftime(t, starttime);
|
||||
local fmt = "Server has been running for %d:%02d:%02d";
|
||||
irc.say(name, fmt:format(
|
||||
math.floor(diff / 60 / 60),
|
||||
math.mod(math.floor(diff / 60), 60),
|
||||
math.mod(math.floor(diff), 60)
|
||||
));
|
||||
end;
|
||||
});
|
||||
|
302
src/callback.lua
302
src/callback.lua
@ -15,209 +15,209 @@ local irc = require("irc");
|
||||
mt_irc.callbacks = { };
|
||||
|
||||
mt_irc._callback = function ( name, breakonreturn, ... )
|
||||
local list = mt_irc.callbacks[name];
|
||||
if (not list) then return; end
|
||||
for n = 1, #list do
|
||||
local r = list[n](...);
|
||||
if (breakonreturn and (r ~= nil)) then return r; end
|
||||
end
|
||||
local list = mt_irc.callbacks[name];
|
||||
if (not list) then return; end
|
||||
for n = 1, #list do
|
||||
local r = list[n](...);
|
||||
if (breakonreturn and (r ~= nil)) then return r; end
|
||||
end
|
||||
end
|
||||
|
||||
mt_irc.register_callback = function ( name, func )
|
||||
local list = mt_irc.callbacks[name];
|
||||
if (not list) then
|
||||
list = { };
|
||||
mt_irc.callbacks[name] = list;
|
||||
end
|
||||
list[#list + 1] = func;
|
||||
local list = mt_irc.callbacks[name];
|
||||
if (not list) then
|
||||
list = { };
|
||||
mt_irc.callbacks[name] = list;
|
||||
end
|
||||
list[#list + 1] = func;
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function ( player )
|
||||
local name = player:get_player_name();
|
||||
mt_irc.connected_players[name] = mt_irc.auto_join;
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
mt_irc.say("*** "..name.." joined the game");
|
||||
local name = player:get_player_name();
|
||||
mt_irc.connected_players[name] = mt_irc.auto_join;
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
mt_irc.say("*** "..name.." joined the game");
|
||||
end);
|
||||
|
||||
minetest.register_on_leaveplayer(function ( player )
|
||||
local name = player:get_player_name();
|
||||
mt_irc.connected_players[name] = nil;
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
mt_irc.say("*** "..name.." left the game");
|
||||
local name = player:get_player_name();
|
||||
mt_irc.connected_players[name] = nil;
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
mt_irc.say("*** "..name.." left the game");
|
||||
end);
|
||||
|
||||
irc.register_callback("connect", function ( )
|
||||
mt_irc.got_motd = true;
|
||||
irc.join(mt_irc.channel);
|
||||
mt_irc.got_motd = true;
|
||||
irc.join(mt_irc.channel);
|
||||
end);
|
||||
|
||||
irc.register_callback("channel_msg", function ( channel, from, message )
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
local t = {
|
||||
name=(from or "<BUG:no one is saying this>");
|
||||
message=(message or "<BUG:there is no message>");
|
||||
server=mt_irc.server;
|
||||
port=mt_irc.port;
|
||||
channel=mt_irc.channel;
|
||||
};
|
||||
local text = mt_irc.message_format_in:gsub("%$%(([^)]+)%)", t)
|
||||
if (mt_irc._callback("channel_msg", from, message, text)) then return; end
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
local t = {
|
||||
name=(from or "<BUG:no one is saying this>");
|
||||
message=(message or "<BUG:there is no message>");
|
||||
server=mt_irc.server;
|
||||
port=mt_irc.port;
|
||||
channel=mt_irc.channel;
|
||||
};
|
||||
local text = mt_irc.message_format_in:gsub("%$%(([^)]+)%)", t)
|
||||
if (mt_irc._callback("channel_msg", from, message, text)) then return; end
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
end);
|
||||
|
||||
local function bot_command ( from, message )
|
||||
|
||||
local pos = message:find(" ", 1, true);
|
||||
local cmd, args;
|
||||
if (pos) then
|
||||
cmd = message:sub(1, pos - 1);
|
||||
args = message:sub(pos + 1);
|
||||
else
|
||||
cmd = message;
|
||||
args = "";
|
||||
end
|
||||
local pos = message:find(" ", 1, true);
|
||||
local cmd, args;
|
||||
if (pos) then
|
||||
cmd = message:sub(1, pos - 1);
|
||||
args = message:sub(pos + 1);
|
||||
else
|
||||
cmd = message;
|
||||
args = "";
|
||||
end
|
||||
|
||||
if (not mt_irc.bot_commands[cmd]) then
|
||||
mt_irc.say(from, "Unknown command `"..cmd.."'. Try `!help'.");
|
||||
return;
|
||||
end
|
||||
if (not mt_irc.bot_commands[cmd]) then
|
||||
mt_irc.say(from, "Unknown command `"..cmd.."'. Try `!help'.");
|
||||
return;
|
||||
end
|
||||
|
||||
mt_irc.bot_commands[cmd].func(from, args);
|
||||
mt_irc.bot_commands[cmd].func(from, args);
|
||||
|
||||
end
|
||||
|
||||
irc.register_callback("private_msg", function ( from, message )
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
local player_to;
|
||||
local msg;
|
||||
if (message:sub(1, 1) == "@") then
|
||||
local pos = message:find(" ", 1, true);
|
||||
if (not pos) then return; end
|
||||
player_to = message:sub(2, pos - 1);
|
||||
msg = message:sub(pos + 1);
|
||||
elseif (message:sub(1, 1) == "!") then
|
||||
bot_command(from, message:sub(2));
|
||||
return;
|
||||
else
|
||||
irc.say(from, 'Message not sent! Please use "!help" to see possible commands.');
|
||||
irc.say(from, ' Or use the "@playername Message" syntax to send a private message.');
|
||||
return;
|
||||
end
|
||||
if (not mt_irc.connected_players[player_to]) then
|
||||
irc.say(from, "User `"..player_to.."' is not connected to IRC.");
|
||||
return;
|
||||
end
|
||||
local t = {
|
||||
name=(from or "<BUG:no one is saying this>");
|
||||
message=(msg or "<BUG:there is no message>");
|
||||
server=mt_irc.server;
|
||||
port=mt_irc.port;
|
||||
channel=mt_irc.channel;
|
||||
};
|
||||
local text = mt_irc.message_format_in:expandvars(t);
|
||||
if (mt_irc._callback("private_msg", from, player_to, message, text)) then return; end
|
||||
minetest.chat_send_player(player_to, "PRIVATE: "..text);
|
||||
mt_irc.say(from, "Message sent!")
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
local player_to;
|
||||
local msg;
|
||||
if (message:sub(1, 1) == "@") then
|
||||
local pos = message:find(" ", 1, true);
|
||||
if (not pos) then return; end
|
||||
player_to = message:sub(2, pos - 1);
|
||||
msg = message:sub(pos + 1);
|
||||
elseif (message:sub(1, 1) == "!") then
|
||||
bot_command(from, message:sub(2));
|
||||
return;
|
||||
else
|
||||
irc.say(from, 'Message not sent! Please use "!help" to see possible commands.');
|
||||
irc.say(from, ' Or use the "@playername Message" syntax to send a private message.');
|
||||
return;
|
||||
end
|
||||
if (not mt_irc.connected_players[player_to]) then
|
||||
irc.say(from, "User `"..player_to.."' is not connected to IRC.");
|
||||
return;
|
||||
end
|
||||
local t = {
|
||||
name=(from or "<BUG:no one is saying this>");
|
||||
message=(msg or "<BUG:there is no message>");
|
||||
server=mt_irc.server;
|
||||
port=mt_irc.port;
|
||||
channel=mt_irc.channel;
|
||||
};
|
||||
local text = mt_irc.message_format_in:expandvars(t);
|
||||
if (mt_irc._callback("private_msg", from, player_to, message, text)) then return; end
|
||||
minetest.chat_send_player(player_to, "PRIVATE: "..text);
|
||||
mt_irc.say(from, "Message sent!")
|
||||
end);
|
||||
|
||||
irc.register_callback("kick", function(chaninfo, nick, kicker)
|
||||
if nick == mt_irc.server_nick then
|
||||
minetest.chat_send_all("IRC: Bot was kicked by "..kicker..".");
|
||||
mt_irc.got_motd = false;
|
||||
mt_irc.connect_ok = false;
|
||||
irc.quit("Kicked");
|
||||
end
|
||||
if nick == mt_irc.server_nick then
|
||||
minetest.chat_send_all("IRC: Bot was kicked by "..kicker..".");
|
||||
mt_irc.got_motd = false;
|
||||
mt_irc.connect_ok = false;
|
||||
irc.quit("Kicked");
|
||||
end
|
||||
end);
|
||||
|
||||
irc.register_callback("nick_change", function ( from, old_nick )
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
mt_irc._callback("nick_change", false, old_nick, from);
|
||||
local text = "["..old_nick.." changed his nick to "..from.."]";
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
mt_irc._callback("nick_change", false, old_nick, from);
|
||||
local text = "["..old_nick.." changed his nick to "..from.."]";
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
end);
|
||||
|
||||
irc.register_callback("join", function ( servinfo, from )
|
||||
local text = "*** "..from.." joined "..mt_irc.channel;
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
local text = "*** "..from.." joined "..mt_irc.channel;
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
end);
|
||||
|
||||
irc.register_callback("part", function ( servinfo, from, part_msg )
|
||||
mt_irc._callback("part", false, from, part_msg);
|
||||
local text
|
||||
if part_msg then
|
||||
text = "*** "..from.." left "..mt_irc.channel.." ("..part_msg..")";
|
||||
else
|
||||
text = "*** "..from.." left "..mt_irc.channel;
|
||||
end
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
mt_irc._callback("part", false, from, part_msg);
|
||||
local text
|
||||
if part_msg then
|
||||
text = "*** "..from.." left "..mt_irc.channel.." ("..part_msg..")";
|
||||
else
|
||||
text = "*** "..from.." left "..mt_irc.channel;
|
||||
end
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
end);
|
||||
|
||||
irc.register_callback("channel_act", function ( servinfo, from, message)
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
local text = "*** "..from.." "..message;
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
local text = "*** "..from.." "..message;
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, text); end
|
||||
end
|
||||
end);
|
||||
|
||||
minetest.register_on_chat_message(function ( name, message )
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
if (message:sub(1, 1) == "/") then return; end
|
||||
if (not mt_irc.connected_players[name]) then return; end
|
||||
if (not minetest.check_player_privs(name, {shout=true})) then
|
||||
return;
|
||||
end
|
||||
if (not mt_irc.buffered_messages) then
|
||||
mt_irc.buffered_messages = { };
|
||||
end
|
||||
mt_irc.buffered_messages[#mt_irc.buffered_messages + 1] = {
|
||||
name = name;
|
||||
message = message;
|
||||
};
|
||||
if (not mt_irc.connect_ok) then return; end
|
||||
if (message:sub(1, 1) == "/") then return; end
|
||||
if (not mt_irc.connected_players[name]) then return; end
|
||||
if (not minetest.check_player_privs(name, {shout=true})) then
|
||||
return;
|
||||
end
|
||||
if (not mt_irc.buffered_messages) then
|
||||
mt_irc.buffered_messages = { };
|
||||
end
|
||||
mt_irc.buffered_messages[#mt_irc.buffered_messages + 1] = {
|
||||
name = name;
|
||||
message = message;
|
||||
};
|
||||
end);
|
||||
|
||||
minetest.register_on_shutdown(function ( )
|
||||
irc.quit("Game shutting down.");
|
||||
for n = 1, 5 do
|
||||
irc.poll();
|
||||
end
|
||||
irc.quit("Game shutting down.");
|
||||
for n = 1, 5 do
|
||||
irc.poll();
|
||||
end
|
||||
end);
|
||||
|
||||
irc.handlers.on_error = function (...) --( from, respond_to )
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, "IRC: Bot had a network error. Reconnecting in 5 seconds..."); end
|
||||
end
|
||||
for _, v in ipairs({...}) do
|
||||
minetest.chat_send_all(dump(v));
|
||||
end
|
||||
irc.quit("Network error");
|
||||
for n = 1, 5 do
|
||||
irc.poll();
|
||||
end
|
||||
mt_irc.got_motd = false;
|
||||
mt_irc.connect_ok = false;
|
||||
minetest.after(5, mt_irc.connect);
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then minetest.chat_send_player(k, "IRC: Bot had a network error. Reconnecting in 5 seconds..."); end
|
||||
end
|
||||
for _, v in ipairs({...}) do
|
||||
minetest.chat_send_all(dump(v));
|
||||
end
|
||||
irc.quit("Network error");
|
||||
for n = 1, 5 do
|
||||
irc.poll();
|
||||
end
|
||||
mt_irc.got_motd = false;
|
||||
mt_irc.connect_ok = false;
|
||||
minetest.after(5, mt_irc.connect);
|
||||
end
|
||||
|
||||
irc.handlers.on_err_nicknameinuse = function ( from, respond_to )
|
||||
irc.quit("Nick in use");
|
||||
for n = 1, 5 do
|
||||
irc.poll();
|
||||
end
|
||||
mt_irc.got_motd = false;
|
||||
mt_irc.connect_ok = false;
|
||||
local n = (tonumber(mt_irc.server_nick:sub(-1)) or 0) + 1;
|
||||
if (n == 10) then n = 1; end
|
||||
mt_irc.server_nick = mt_irc.server_nick:sub(1, -2)..n;
|
||||
mt_irc.connect();
|
||||
irc.quit("Nick in use");
|
||||
for n = 1, 5 do
|
||||
irc.poll();
|
||||
end
|
||||
mt_irc.got_motd = false;
|
||||
mt_irc.connect_ok = false;
|
||||
local n = (tonumber(mt_irc.server_nick:sub(-1)) or 0) + 1;
|
||||
if (n == 10) then n = 1; end
|
||||
mt_irc.server_nick = mt_irc.server_nick:sub(1, -2)..n;
|
||||
mt_irc.connect();
|
||||
end
|
||||
|
||||
-- TESTING
|
||||
|
162
src/chatcmds.lua
162
src/chatcmds.lua
@ -14,87 +14,87 @@
|
||||
local irc = require("irc");
|
||||
|
||||
minetest.register_chatcommand("irc_msg", {
|
||||
params = "<name> <message>";
|
||||
description = "Send a private message to an IRC user";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
if (not mt_irc.connect_ok) then
|
||||
minetest.chat_send_player(name, "IRC: You are not connected, use /irc_connect.");
|
||||
return;
|
||||
end
|
||||
local found, _, toname, msg = param:find("^([^%s#]+)%s(.+)");
|
||||
if not found then
|
||||
minetest.chat_send_player(name, "Invalid usage, see /help irc_msg.");
|
||||
return;
|
||||
end
|
||||
local t = {name=name, message=msg};
|
||||
local text = mt_irc.message_format_out:expandvars(t);
|
||||
mt_irc.say(toname, text);
|
||||
minetest.chat_send_player(name, "Message sent!")
|
||||
end;
|
||||
params = "<name> <message>";
|
||||
description = "Send a private message to an IRC user";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
if (not mt_irc.connect_ok) then
|
||||
minetest.chat_send_player(name, "IRC: You are not connected, use /irc_connect.");
|
||||
return;
|
||||
end
|
||||
local found, _, toname, msg = param:find("^([^%s#]+)%s(.+)");
|
||||
if not found then
|
||||
minetest.chat_send_player(name, "Invalid usage, see /help irc_msg.");
|
||||
return;
|
||||
end
|
||||
local t = {name=name, message=msg};
|
||||
local text = mt_irc.message_format_out:expandvars(t);
|
||||
mt_irc.say(toname, text);
|
||||
minetest.chat_send_player(name, "Message sent!")
|
||||
end;
|
||||
});
|
||||
|
||||
minetest.register_chatcommand("irc_connect", {
|
||||
params = "";
|
||||
description = "Connect to the IRC server";
|
||||
privs = { irc_admin=true; };
|
||||
func = function ( name, param )
|
||||
if (mt_irc.connect_ok) then
|
||||
minetest.chat_send_player(name, "IRC: You are already connected.");
|
||||
return;
|
||||
end
|
||||
mt_irc.connect();
|
||||
minetest.chat_send_player(name, "IRC: You are now connected.");
|
||||
irc.say(mt_irc.channel, name.." joined the channel.");
|
||||
end;
|
||||
params = "";
|
||||
description = "Connect to the IRC server";
|
||||
privs = { irc_admin=true; };
|
||||
func = function ( name, param )
|
||||
if (mt_irc.connect_ok) then
|
||||
minetest.chat_send_player(name, "IRC: You are already connected.");
|
||||
return;
|
||||
end
|
||||
mt_irc.connect();
|
||||
minetest.chat_send_player(name, "IRC: You are now connected.");
|
||||
irc.say(mt_irc.channel, name.." joined the channel.");
|
||||
end;
|
||||
});
|
||||
|
||||
minetest.register_chatcommand("irc_disconnect", {
|
||||
params = "";
|
||||
description = "Disconnect from the IRC server";
|
||||
privs = { irc_admin=true; };
|
||||
func = function ( name, param )
|
||||
if (not mt_irc.connect_ok) then
|
||||
minetest.chat_send_player(name, "IRC: You are not connected.");
|
||||
return;
|
||||
end
|
||||
irc.quit("Manual BOT Disconnection");
|
||||
minetest.chat_send_player(name, "IRC: You are now disconnected.");
|
||||
mt_irc.connect_ok = false;
|
||||
end;
|
||||
params = "";
|
||||
description = "Disconnect from the IRC server";
|
||||
privs = { irc_admin=true; };
|
||||
func = function ( name, param )
|
||||
if (not mt_irc.connect_ok) then
|
||||
minetest.chat_send_player(name, "IRC: You are not connected.");
|
||||
return;
|
||||
end
|
||||
irc.quit("Manual BOT Disconnection");
|
||||
minetest.chat_send_player(name, "IRC: You are now disconnected.");
|
||||
mt_irc.connect_ok = false;
|
||||
end;
|
||||
});
|
||||
|
||||
minetest.register_chatcommand("irc_reconnect", {
|
||||
params = "";
|
||||
description = "Reconnect to the IRC server";
|
||||
privs = { irc_admin=true; };
|
||||
func = function ( name, param )
|
||||
if (mt_irc.connect_ok) then
|
||||
irc.quit("Reconnecting BOT...");
|
||||
minetest.chat_send_player(name, "IRC: Reconnecting bot...");
|
||||
mt_irc.got_motd = true;
|
||||
mt_irc.connect_ok = false;
|
||||
end
|
||||
mt_irc.connect();
|
||||
end;
|
||||
params = "";
|
||||
description = "Reconnect to the IRC server";
|
||||
privs = { irc_admin=true; };
|
||||
func = function ( name, param )
|
||||
if (mt_irc.connect_ok) then
|
||||
irc.quit("Reconnecting BOT...");
|
||||
minetest.chat_send_player(name, "IRC: Reconnecting bot...");
|
||||
mt_irc.got_motd = true;
|
||||
mt_irc.connect_ok = false;
|
||||
end
|
||||
mt_irc.connect();
|
||||
end;
|
||||
});
|
||||
|
||||
minetest.register_chatcommand("join", {
|
||||
params = "";
|
||||
description = "Join the IRC channel";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
mt_irc.join(name);
|
||||
end;
|
||||
params = "";
|
||||
description = "Join the IRC channel";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
mt_irc.join(name);
|
||||
end;
|
||||
});
|
||||
|
||||
minetest.register_chatcommand("part", {
|
||||
params = "";
|
||||
description = "Part the IRC channel";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
mt_irc.part(name);
|
||||
end;
|
||||
params = "";
|
||||
description = "Part the IRC channel";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
mt_irc.part(name);
|
||||
end;
|
||||
});
|
||||
|
||||
minetest.register_chatcommand("me", {
|
||||
@ -102,23 +102,23 @@ minetest.register_chatcommand("me", {
|
||||
description = "chat action (eg. /me orders a pizza)";
|
||||
privs = { shout=true };
|
||||
func = function(name, param)
|
||||
minetest.chat_send_all("* "..name.." "..param);
|
||||
irc.say(mt_irc.channel, "* "..name.." "..param);
|
||||
minetest.chat_send_all("* "..name.." "..param);
|
||||
irc.say(mt_irc.channel, "* "..name.." "..param);
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("who", {
|
||||
-- TODO: This duplicates code from !who
|
||||
params = "";
|
||||
description = "Tell who is currently on the channel";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
local s = "";
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then
|
||||
s = s.." "..k;
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(name, "Players On Channel:"..s);
|
||||
end;
|
||||
-- TODO: This duplicates code from !who
|
||||
params = "";
|
||||
description = "Tell who is currently on the channel";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
local s = "";
|
||||
for k, v in pairs(mt_irc.connected_players) do
|
||||
if (v) then
|
||||
s = s.." "..k;
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(name, "Players On Channel:"..s);
|
||||
end;
|
||||
});
|
||||
|
@ -61,12 +61,12 @@ mt_irc.auto_connect = not minetest.setting_getbool("mt_irc.disable_auto_connect"
|
||||
|
||||
-- Set default server nick if not specified.
|
||||
if (not mt_irc.server_nick) then
|
||||
local pr = PseudoRandom(os.time());
|
||||
-- Workaround for bad distribution in minetest PRNG implementation.
|
||||
local fmt = "minetest-%02X%02X%02X";
|
||||
mt_irc.server_nick = fmt:format(
|
||||
pr:next(0, 255),
|
||||
pr:next(0, 255),
|
||||
pr:next(0, 255)
|
||||
);
|
||||
local pr = PseudoRandom(os.time());
|
||||
-- Workaround for bad distribution in minetest PRNG implementation.
|
||||
local fmt = "minetest-%02X%02X%02X";
|
||||
mt_irc.server_nick = fmt:format(
|
||||
pr:next(0, 255),
|
||||
pr:next(0, 255),
|
||||
pr:next(0, 255)
|
||||
);
|
||||
end
|
||||
|
126
src/init.lua
126
src/init.lua
@ -30,82 +30,82 @@ local irc = require 'irc';
|
||||
irc.DEBUG = ((mt_irc.debug and true) or false);
|
||||
|
||||
minetest.register_privilege("irc_admin", {
|
||||
description = "Allow IRC administrative tasks to be performed.";
|
||||
give_to_singleplayer = true;
|
||||
description = "Allow IRC administrative tasks to be performed.";
|
||||
give_to_singleplayer = true;
|
||||
});
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if (not mt_irc.connect_ok) then return end
|
||||
mt_irc.cur_time = mt_irc.cur_time + dtime
|
||||
if (mt_irc.cur_time >= mt_irc.dtime) then
|
||||
if (mt_irc.buffered_messages) then
|
||||
for _, msg in ipairs(mt_irc.buffered_messages) do
|
||||
local t = {
|
||||
name=(msg.name or "<BUG:no one is saying this>"),
|
||||
message=(msg.message or "<BUG:there is no message>")
|
||||
}
|
||||
local text = mt_irc.message_format_out:expandvars(t)
|
||||
irc.say(mt_irc.channel, text)
|
||||
end
|
||||
mt_irc.buffered_messages = nil
|
||||
end
|
||||
irc.poll()
|
||||
mt_irc.cur_time = mt_irc.cur_time - mt_irc.dtime
|
||||
end
|
||||
if (not mt_irc.connect_ok) then return end
|
||||
mt_irc.cur_time = mt_irc.cur_time + dtime
|
||||
if (mt_irc.cur_time >= mt_irc.dtime) then
|
||||
if (mt_irc.buffered_messages) then
|
||||
for _, msg in ipairs(mt_irc.buffered_messages) do
|
||||
local t = {
|
||||
name=(msg.name or "<BUG:no one is saying this>"),
|
||||
message=(msg.message or "<BUG:there is no message>")
|
||||
}
|
||||
local text = mt_irc.message_format_out:expandvars(t)
|
||||
irc.say(mt_irc.channel, text)
|
||||
end
|
||||
mt_irc.buffered_messages = nil
|
||||
end
|
||||
irc.poll()
|
||||
mt_irc.cur_time = mt_irc.cur_time - mt_irc.dtime
|
||||
end
|
||||
end)
|
||||
|
||||
mt_irc.part = function ( name )
|
||||
if (not mt_irc.connected_players[name]) then
|
||||
minetest.chat_send_player(name, "IRC: You are not in the channel.");
|
||||
return;
|
||||
end
|
||||
mt_irc.connected_players[name] = nil;
|
||||
minetest.chat_send_player(name, "IRC: You are now out of the channel.");
|
||||
if (not mt_irc.connected_players[name]) then
|
||||
minetest.chat_send_player(name, "IRC: You are not in the channel.");
|
||||
return;
|
||||
end
|
||||
mt_irc.connected_players[name] = nil;
|
||||
minetest.chat_send_player(name, "IRC: You are now out of the channel.");
|
||||
end
|
||||
|
||||
mt_irc.join = function ( name )
|
||||
if (mt_irc.connected_players[name]) then
|
||||
minetest.chat_send_player(name, "IRC: You are already in the channel.");
|
||||
return;
|
||||
end
|
||||
mt_irc.connected_players[name] = true;
|
||||
minetest.chat_send_player(name, "IRC: You are now in the channel.");
|
||||
if (mt_irc.connected_players[name]) then
|
||||
minetest.chat_send_player(name, "IRC: You are already in the channel.");
|
||||
return;
|
||||
end
|
||||
mt_irc.connected_players[name] = true;
|
||||
minetest.chat_send_player(name, "IRC: You are now in the channel.");
|
||||
end
|
||||
|
||||
mt_irc.connect = function ( )
|
||||
mt_irc.connect_ok = irc.connect({
|
||||
network = mt_irc.server;
|
||||
port = mt_irc.port;
|
||||
nick = mt_irc.server_nick;
|
||||
pass = mt_irc.password;
|
||||
timeout = mt_irc.timeout;
|
||||
channel = mt_irc.channel;
|
||||
});
|
||||
if (not mt_irc.connect_ok) then
|
||||
local s = "DEBUG: irc.connect failed";
|
||||
minetest.debug(s);
|
||||
minetest.chat_send_all(s);
|
||||
return;
|
||||
end
|
||||
while (not mt_irc.got_motd) do
|
||||
irc.poll();
|
||||
end
|
||||
mt_irc.connect_ok = irc.connect({
|
||||
network = mt_irc.server;
|
||||
port = mt_irc.port;
|
||||
nick = mt_irc.server_nick;
|
||||
pass = mt_irc.password;
|
||||
timeout = mt_irc.timeout;
|
||||
channel = mt_irc.channel;
|
||||
});
|
||||
if (not mt_irc.connect_ok) then
|
||||
local s = "DEBUG: irc.connect failed";
|
||||
minetest.debug(s);
|
||||
minetest.chat_send_all(s);
|
||||
return;
|
||||
end
|
||||
while (not mt_irc.got_motd) do
|
||||
irc.poll();
|
||||
end
|
||||
end
|
||||
|
||||
mt_irc.say = function ( to, msg )
|
||||
if (not msg) then
|
||||
msg = to;
|
||||
to = mt_irc.channel;
|
||||
end
|
||||
to = to or mt_irc.channel;
|
||||
msg = msg or "";
|
||||
local msg2 = mt_irc._callback("msg_out", true, to, msg);
|
||||
if ((type(msg2) == "boolean") and (not msg2)) then
|
||||
return;
|
||||
elseif (msg2 ~= nil) then
|
||||
msg = tostring(msg);
|
||||
end
|
||||
irc.say(to, msg);
|
||||
if (not msg) then
|
||||
msg = to;
|
||||
to = mt_irc.channel;
|
||||
end
|
||||
to = to or mt_irc.channel;
|
||||
msg = msg or "";
|
||||
local msg2 = mt_irc._callback("msg_out", true, to, msg);
|
||||
if ((type(msg2) == "boolean") and (not msg2)) then
|
||||
return;
|
||||
elseif (msg2 ~= nil) then
|
||||
msg = tostring(msg);
|
||||
end
|
||||
irc.say(to, msg);
|
||||
end
|
||||
|
||||
mt_irc.irc = irc;
|
||||
@ -114,7 +114,7 @@ mt_irc.irc = irc;
|
||||
|
||||
-- Requested by Exio
|
||||
string.expandvars = function ( s, vars )
|
||||
return s:gsub("%$%(([^)]+)%)", vars);
|
||||
return s:gsub("%$%(([^)]+)%)", vars);
|
||||
end
|
||||
|
||||
dofile(MODPATH.."/callback.lua");
|
||||
@ -123,5 +123,5 @@ dofile(MODPATH.."/botcmds.lua");
|
||||
dofile(MODPATH.."/friends.lua");
|
||||
|
||||
if (mt_irc.auto_connect) then
|
||||
mt_irc.connect()
|
||||
mt_irc.connect()
|
||||
end
|
||||
|
1054
src/luairc/irc.lua
1054
src/luairc/irc.lua
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user