diff --git a/lib/Bot/IRC/ReJoin.pm b/lib/Bot/IRC/ReJoin.pm new file mode 100644 index 0000000..7912756 --- /dev/null +++ b/lib/Bot/IRC/ReJoin.pm @@ -0,0 +1,52 @@ +package Bot::IRC::ReJoin; +# Re-Join to channel on /kick + +use 5.018; +use strict; +use warnings; +use utf8; +use open qw (:std :utf8); +use English qw ( -no_match_vars ); +use Encode qw (_utf8_on); + +our $VERSION = '1.35'; # VERSION + +# Most gears are spinning here. +sub init { + my ($bot) = @_; + + $bot->hook ( + { + command => 'KICK', + }, + + sub { + my $bot = shift; + my $msg = shift; + + # fix some utf8 flags, that are lost + _utf8_on $msg->{forum}; + _utf8_on $msg->{full_text}; + _utf8_on $msg->{user}; + + my ($who, $why) = split / \:/, $msg->{text}, 2; + + if ($who eq $bot->{nick}) { + $bot->note ("I was kicked from $msg->{forum} by $msg->{nick} with reason $why"); + sleep 5; + $bot->join ($msg->{forum}); + $bot->note ("Re-joining to $msg->{forum}"); + } + + return 1; + }, + ); + + return 1; +} + +1; + +__END__ + +# vim: set ft=perl noet ai ts=4 sw=4 sts=4: \ No newline at end of file diff --git a/lib/IRCBot.pm b/lib/IRCBot.pm index 2cc2fe1..8e5fb31 100644 --- a/lib/IRCBot.pm +++ b/lib/IRCBot.pm @@ -36,7 +36,7 @@ sub RunIRCBot { }, ); - $bot->load ('OnMessage'); # our main plugin that handles all the incomming messages, mostly + $bot->load ('OnMessage', 'ReJoin'); # our main plugin that handles all the incomming messages, mostly $bot->helps( about => 'I am just another chatty bot.', );