2013-01-08 16:50:47 +01:00
|
|
|
|
2012-12-01 04:06:15 +01:00
|
|
|
-- IRC Mod for Minetest
|
2013-01-08 16:50:47 +01:00
|
|
|
-- By Diego Martínez <kaeza@users.sf.net>
|
2012-12-01 04:06:15 +01:00
|
|
|
--
|
|
|
|
-- This mod allows to tie a Minetest server to an IRC channel.
|
|
|
|
--
|
|
|
|
-- This program is free software. It comes without any warranty, to
|
|
|
|
-- the extent permitted by applicable law. You can redistribute it
|
|
|
|
-- and/or modify it under the terms of the Do What The Fuck You Want
|
|
|
|
-- To Public License, Version 2, as published by Sam Hocevar. See
|
|
|
|
-- http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
|
|
--
|
|
|
|
|
2012-12-14 23:33:44 +01:00
|
|
|
local MODPATH = minetest.get_modpath("irc");
|
2012-12-01 04:06:15 +01:00
|
|
|
|
2012-12-14 23:33:44 +01:00
|
|
|
mt_irc = { };
|
2012-12-01 04:06:15 +01:00
|
|
|
|
2012-12-14 23:33:44 +01:00
|
|
|
dofile(MODPATH.."/config.lua");
|
2012-12-01 04:06:15 +01:00
|
|
|
|
2012-12-14 23:33:44 +01:00
|
|
|
mt_irc.cur_time = 0;
|
|
|
|
mt_irc.buffered_messages = { };
|
2012-12-16 16:56:02 +01:00
|
|
|
mt_irc.connected_players = { };
|
2012-12-22 04:16:28 +01:00
|
|
|
mt_irc.modpath = MODPATH;
|
2012-12-01 04:06:15 +01:00
|
|
|
|
|
|
|
package.path = MODPATH.."/?.lua;"..package.path;
|
|
|
|
package.cpath = MODPATH.."/lib?.so;"..MODPATH.."/?.dll;"..package.cpath;
|
|
|
|
|
|
|
|
local irc = require 'irc';
|
|
|
|
|
2012-12-14 23:33:44 +01:00
|
|
|
irc.DEBUG = ((mt_irc.debug and true) or false);
|
|
|
|
|
2012-12-16 16:56:02 +01:00
|
|
|
minetest.register_privilege("irc_admin", {
|
|
|
|
description = "Allow IRC administrative tasks to be performed.";
|
|
|
|
give_to_singleplayer = true;
|
|
|
|
});
|
2012-12-01 04:06:15 +01:00
|
|
|
|
2013-04-20 06:07:06 +02:00
|
|
|
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
|
|
|
|
end)
|
|
|
|
|
2012-12-22 04:16:28 +01:00
|
|
|
mt_irc.part = function ( name )
|
2012-12-16 16:56:02 +01:00
|
|
|
if (not mt_irc.connected_players[name]) then
|
2012-12-22 04:16:28 +01:00
|
|
|
minetest.chat_send_player(name, "IRC: You are not in the channel.");
|
2012-12-16 16:56:02 +01:00
|
|
|
return;
|
|
|
|
end
|
2013-03-28 11:41:24 +01:00
|
|
|
mt_irc.connected_players[name] = nil;
|
2012-12-22 04:16:28 +01:00
|
|
|
minetest.chat_send_player(name, "IRC: You are now out of the channel.");
|
|
|
|
end
|
2012-12-16 16:56:02 +01:00
|
|
|
|
2012-12-22 04:16:28 +01:00
|
|
|
mt_irc.join = function ( name )
|
2013-03-28 11:41:24 +01:00
|
|
|
if (mt_irc.connected_players[name]) then
|
|
|
|
minetest.chat_send_player(name, "IRC: You are already in the channel.");
|
|
|
|
return;
|
2012-12-22 04:16:28 +01:00
|
|
|
end
|
2013-03-28 11:41:24 +01:00
|
|
|
mt_irc.connected_players[name] = true;
|
|
|
|
minetest.chat_send_player(name, "IRC: You are now in the channel.");
|
2012-12-22 04:16:28 +01:00
|
|
|
end
|
2012-12-16 16:56:02 +01:00
|
|
|
|
2012-12-22 04:16:28 +01:00
|
|
|
mt_irc.connect = function ( )
|
2012-12-26 22:13:00 +01:00
|
|
|
mt_irc.connect_ok = irc.connect({
|
2012-12-16 16:56:02 +01:00
|
|
|
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;
|
|
|
|
});
|
2012-12-18 05:50:53 +01:00
|
|
|
if (not mt_irc.connect_ok) then
|
|
|
|
local s = "DEBUG: irc.connect failed";
|
2012-12-22 04:16:28 +01:00
|
|
|
minetest.debug(s);
|
2012-12-18 05:50:53 +01:00
|
|
|
minetest.chat_send_all(s);
|
2013-01-05 15:48:35 +01:00
|
|
|
return;
|
2012-12-18 05:50:53 +01:00
|
|
|
end
|
2013-01-05 15:48:35 +01:00
|
|
|
while (not mt_irc.got_motd) do
|
|
|
|
irc.poll();
|
|
|
|
end
|
2012-12-16 16:56:02 +01:00
|
|
|
end
|
2012-12-22 04:16:28 +01:00
|
|
|
|
2012-12-28 12:41:10 +01:00
|
|
|
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 "";
|
2013-03-29 03:29:23 +01:00
|
|
|
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
|
2012-12-28 12:41:10 +01:00
|
|
|
irc.say(to, msg);
|
|
|
|
end
|
|
|
|
|
2013-01-08 16:50:47 +01:00
|
|
|
mt_irc.irc = irc;
|
2012-12-31 16:53:01 +01:00
|
|
|
|
2013-01-11 17:20:30 +01:00
|
|
|
-- Misc helpers
|
|
|
|
|
|
|
|
-- Requested by Exio
|
|
|
|
string.expandvars = function ( s, vars )
|
|
|
|
return s:gsub("%$%(([^)]+)%)", vars);
|
|
|
|
end
|
|
|
|
|
2012-12-22 04:16:28 +01:00
|
|
|
dofile(MODPATH.."/callback.lua");
|
|
|
|
dofile(MODPATH.."/chatcmds.lua");
|
2012-12-26 20:56:21 +01:00
|
|
|
dofile(MODPATH.."/botcmds.lua");
|
2012-12-22 04:16:28 +01:00
|
|
|
dofile(MODPATH.."/friends.lua");
|
|
|
|
|
|
|
|
if (mt_irc.auto_connect) then
|
|
|
|
mt_irc.connect()
|
|
|
|
end
|