use POE::Component::IRC::Plugin::Logger;
use POE::Component::IRC::Plugin::BotTraffic;
use POE::Component::IRC::Plugin::Connector;
+use POE::Component::IRC::Plugin::AutoJoin;
+use POE::Component::IRC::Plugin::NickReclaim;
use NDIRC::Dispatcher;
+use IO::File;
+
# We registered for all events, this will produce some debug info.
sub _default {
my ($event, $args) = @_[ARG0 .. $#_];
$kernel->sig( USR2 => 'sig_usr2' );
$kernel->sig( INT => 'signal_handler' );
+ $irc->plugin_add( 'NickReclaim', POE::Component::IRC::Plugin::NickReclaim->new() );
+ $irc->plugin_add( 'AutoJoin', POE::Component::IRC::Plugin::NickReclaim->new() );
$irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
$irc->plugin_add('Logger', POE::Component::IRC::Plugin::Logger->new(
Path => 'irclogs',
Strip_formatting => 1,
));
- $heap->{connector} = POE::Component::IRC::Plugin::Connector->new();
+ $heap->{connector} = POE::Component::IRC::Plugin::Connector->new(
+ servers => ['irc.netgamers.org', 'underworld.no.eu.netgamers.org'
+ ,'firefly.no.eu.netgamers.org', 'underworld.ca.us.netgamers.org' ]
+ );
$irc->plugin_add( 'Connector' => $heap->{connector} );
$kernel->signal($session => 'USR2');
$irc->yield( register => 'all' );
- $irc->yield( connect => { } );
+ $irc->yield( connect => { server => 'irc.netgamers.org' } );
$kernel->delay( refresh => 60 );
return;
}
+sub auth {
+ my $heap = $_[HEAP];
+
+ if (my $f = new IO::File 'auth'){
+ my $user = <$f>;
+ chomp $user;
+ my $pass = <$f>;
+ chomp $pass;
+ $heap->{irc}->yield(qbot_auth => $user => $pass);
+ }
+}
+
sub sig_usr1 {
- my $kernel = $_[KERNEL];
+ my ($kernel,$heap) = @_[KERNEL,HEAP];
+
$kernel->yield( 'refresh' );
}
sub sig_usr2 {
my $heap = $_[HEAP];
- open COMMANDS, 'commands';
- my @commands = split /\W+/, do { local $/; <COMMANDS> };
- close COMMANDS;
-
- say "Loading commands from: @commands";
my $disp = new NDIRC::Dispatcher;
- $disp->load(@commands);
- open CHANNELS, 'channels';
- while (<CHANNELS>){
+ if (my $commands = new IO::File 'commands'){
+ my @commands = split /\W+/, do{local $/; <$commands>};
+ say "Loading commands from: @commands";
+ $disp->load(@commands);
+ }
+
+ my $channels = new IO::File 'channels';
+ while (<$channels>){
my ($chan, @types) = split /\s+/;
say "$chan - @types";
$disp->add_channel($chan,\@types);
}
- close CHANNELS;
$heap->{disp} = $disp;
}
given($signal_name){
when ('INT') {
exit unless $heap->{irc}->connected;
+ $heap->{INT} = 1;
$heap->{irc}->yield(quit => 'Bye!');
$kernel->sig_handled();
}
sub irc_disconnected {
my ($sender,$heap) = @_[SENDER,HEAP];
- exit;
+ exit if $heap->{INT};
}
sub irc_001 {
- my ($sender,$heap) = @_[SENDER,HEAP];
+ my ($sender,$heap,$kernel) = @_[SENDER,HEAP,KERNEL];
# Since this is an irc_* event, we can get the component's object by
# accessing the heap of the sender. Then we register and connect to the
print "Connected to ", $irc->server_name(), "\n";
+ $kernel->yield( 'auth' );
+ $irc->yield( mode => $irc->nick_name, '+ix');
+
# we join our channels
$irc->yield( join => $_ ) for grep /^#/, keys %{$heap->{disp}->channels};
return;
use NDIRC::CommonStates;
-use NDIRC::Eos;
-
-my $nickname = 'ndbot';
-my $ircname = 'ND test bot';
-my $server = 'irc.netgamers.org';
+eval "require NDIRC::$ARGV[0]";
# We create a new PoCo-IRC object
my $irc = POE::Component::IRC::Qnet::State->spawn(
- nick => $nickname,
- ircname => $ircname,
- server => $server,
- servers => [$server, 'underworld.no.eu.netgamers.org', ]
+ nick => $ARGV[0],
+ ircname => 'ND bot',
) or die "Oh noooo! $!";
$irc->service_bots(QBOT => 'P@cservice.netgamers.org');
POE::Session->create(
package_states => [
'NDIRC::CommonStates' => [ qw(_default _start irc_001 sig_DIE sig_usr1 sig_usr2
- signal_handler irc_disconnected irc_invite) ],
- 'NDIRC::Eos' => [ qw(irc_public irc_msg refresh irc_join) ],
+ signal_handler irc_disconnected irc_invite auth) ],
+ "NDIRC::$ARGV[0]" => [ qw(irc_public irc_msg refresh irc_join) ],
],
heap => { irc => $irc },
);