From 8c826f263964eb39549f33a1191c08022ce5782f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Sun, 6 Jan 2013 07:15:16 -0200 Subject: [PATCH] Added auto-reconnection if bot is kicked --- src/callback.lua | 14 ++++++++++++++ src/chatcmds.lua | 1 + 2 files changed, 15 insertions(+) diff --git a/src/callback.lua b/src/callback.lua index 163c711..3244bdb 100644 --- a/src/callback.lua +++ b/src/callback.lua @@ -79,6 +79,17 @@ irc.register_callback("private_msg", function ( from, message ) minetest.chat_send_player(player_to, "PRIVATE: "..text); end); +irc.register_callback("kick", function ( chaninfo, to, from ) + if (mt_irc.connect_ok) then + mt_irc.connect_ok = false; + minetest.chat_send_all("IRC: Bot was kicked by "..from..". Reconnecting bot in 5 seconds..."); + mt_irc.got_motd = true; + mt_irc.connect_ok = false; + irc.quit("Kicked"); + minetest.after(5, mt_irc.connect); + end +end); + irc.register_callback("nick_change", function ( from, old_nick ) if (not mt_irc.connect_ok) then return; end end); @@ -108,4 +119,7 @@ end); minetest.register_on_shutdown(function ( ) irc.quit("Game shutting down."); + for n = 1, 5 do + irc.poll(); + end end); diff --git a/src/chatcmds.lua b/src/chatcmds.lua index 4320e5f..95803fd 100644 --- a/src/chatcmds.lua +++ b/src/chatcmds.lua @@ -59,6 +59,7 @@ minetest.register_chatcommand("irc_reconnect", { 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();