2012-12-22 04:16:28 +01:00
|
|
|
|
2013-01-08 16:50:47 +01:00
|
|
|
-- IRC Mod for Minetest
|
|
|
|
-- By Diego Martínez <kaeza@users.sf.net>
|
|
|
|
--
|
|
|
|
-- 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.
|
|
|
|
--
|
|
|
|
|
|
|
|
local irc = require("irc");
|
|
|
|
|
2013-04-20 20:45:11 +02:00
|
|
|
minetest.register_chatcommand("irc_msg", {
|
2012-12-22 04:16:28 +01:00
|
|
|
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
|
2013-04-20 20:45:11 +02:00
|
|
|
minetest.chat_send_player(name, "IRC: You are not connected, use /irc_connect.");
|
2012-12-22 04:16:28 +01:00
|
|
|
return;
|
|
|
|
end
|
2013-04-20 21:29:43 +02:00
|
|
|
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};
|
2013-01-11 17:20:30 +01:00
|
|
|
local text = mt_irc.message_format_out:expandvars(t);
|
2013-04-20 21:29:43 +02:00
|
|
|
mt_irc.say(toname, text);
|
|
|
|
minetest.chat_send_player(name, "Message sent!")
|
2012-12-22 04:16:28 +01:00
|
|
|
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
|
2012-12-26 07:37:46 +01:00
|
|
|
mt_irc.connect();
|
2012-12-22 04:16:28 +01:00
|
|
|
minetest.chat_send_player(name, "IRC: You are now connected.");
|
|
|
|
irc.say(mt_irc.channel, name.." joined the channel.");
|
|
|
|
end;
|
|
|
|
});
|
|
|
|
|
2012-12-31 16:53:01 +01:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
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...");
|
2013-01-06 10:15:16 +01:00
|
|
|
mt_irc.got_motd = true;
|
2012-12-31 16:53:01 +01:00
|
|
|
mt_irc.connect_ok = false;
|
|
|
|
end
|
|
|
|
mt_irc.connect();
|
|
|
|
end;
|
|
|
|
});
|
|
|
|
|
2012-12-22 04:16:28 +01:00
|
|
|
minetest.register_chatcommand("join", {
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
minetest.register_chatcommand("me", {
|
|
|
|
params = "<action>";
|
|
|
|
description = "chat action (eg. /me orders a pizza)";
|
|
|
|
privs = { shout=true };
|
|
|
|
func = function(name, param)
|
2012-12-22 21:22:45 +01:00
|
|
|
minetest.chat_send_all("* "..name.." "..param);
|
|
|
|
irc.say(mt_irc.channel, "* "..name.." "..param);
|
2012-12-22 04:16:28 +01:00
|
|
|
end,
|
|
|
|
})
|
2012-12-27 02:29:22 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
});
|