mirror of
https://github.com/minetest-mods/irc.git
synced 2025-07-01 07:30:30 +02:00
added callbacks to block or otherwise process messages from other mods
This commit is contained in:
@ -13,6 +13,26 @@
|
||||
|
||||
local irc = require("irc");
|
||||
|
||||
mt_irc.callbacks = { };
|
||||
|
||||
mt_irc._callback = function ( name, ... )
|
||||
local list = mt_irc.callbacks[name];
|
||||
if (not list) then return; end
|
||||
for n = 1, #list do
|
||||
local r = list[n](...);
|
||||
if (r) 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;
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function ( player )
|
||||
|
||||
mt_irc.say(mt_irc.channel, "*** "..player:get_player_name().." joined the game");
|
||||
@ -35,6 +55,7 @@ irc.register_callback("channel_msg", function ( channel, from, message )
|
||||
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
|
||||
@ -89,7 +110,8 @@ irc.register_callback("private_msg", function ( from, message )
|
||||
port=mt_irc.port;
|
||||
channel=mt_irc.channel;
|
||||
};
|
||||
local text = mt_irc.message_format_in:gsub("%$%(([^)]+)%)", t)
|
||||
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);
|
||||
end);
|
||||
|
||||
|
@ -30,7 +30,7 @@ minetest.register_chatcommand("msg", {
|
||||
name=name;
|
||||
message=msg;
|
||||
};
|
||||
local text = mt_irc.message_format_out:gsub("%$%(([^)]+)%)", t)
|
||||
local text = mt_irc.message_format_out:expandvars(t);
|
||||
irc.send("PRIVMSG", name, text);
|
||||
end;
|
||||
});
|
||||
|
@ -116,7 +116,7 @@ mt_irc.connect = function ( )
|
||||
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:gsub("%$%(([^)]+)%)", t)
|
||||
local text = mt_irc.message_format_out:expandvars(t);
|
||||
irc.say(mt_irc.channel, text);
|
||||
end
|
||||
mt_irc.buffered_messages = nil;
|
||||
@ -145,6 +145,13 @@ end
|
||||
|
||||
mt_irc.irc = irc;
|
||||
|
||||
-- Misc helpers
|
||||
|
||||
-- Requested by Exio
|
||||
string.expandvars = function ( s, vars )
|
||||
return s:gsub("%$%(([^)]+)%)", vars);
|
||||
end
|
||||
|
||||
dofile(MODPATH.."/callback.lua");
|
||||
dofile(MODPATH.."/chatcmds.lua");
|
||||
dofile(MODPATH.."/botcmds.lua");
|
||||
|
Reference in New Issue
Block a user