#! /usr/bin/perl use strict; use warnings; my $name = 'cbstream'; my $version = 0.01; my %conf = ( cbstream => { pmuser => 'Tanktalus', pmpassword => 'myperlmonkspasswordisreallylongbuteasytoremember', }, ); sub _get_conf { my $conf = shift; my @var = @_; if (@var > 1) { if (exists $conf->{$var[0]}) { my $rc = _get_conf($conf->{$var[0]}, @var[1..$#var]); return defined $rc ? $rc : $conf->{$var[-1]}; } } $conf->{$var[-1]}; } sub get_conf { my @var = @_; return _get_conf(\%conf, @var); } Xchat::register($name, $version); Xchat::hook_print('You Join', \&JoinCBStreamLogin); Xchat::hook_command('cblog', sub { Xchat::command 'join #cbstream-login'; Xchat::EAT_ALL }); Xchat::hook_server('PRIVMSG', \&LeaveCBStreamLogin); # once logged in, tell cbstream what our id and pw is. sub JoinCBStreamLogin { my $info = shift; if (Xchat::get_info('network') eq 'FreeNode') { if ($info->[1] eq '#cbstream-login') { my $id = get_conf('cbstream','pmuser'); my $pw = get_conf('cbstream','pmpassword'); if ($id and $pw) { Xchat::command("say plogin $id $pw"); } return Xchat::EAT_NONE; } } Xchat::EAT_NONE; } sub LeaveCBStreamLogin { my $msg = shift; my $nth = shift; if (Xchat::get_info('network') eq 'FreeNode') { LOG Dumper($msg); if ($msg->[0] =~ /^:cbstream!/ and $msg->[1] eq 'PRIVMSG' and lc $msg->[2] eq lc Xchat::get_info('nick') and $nth->[3] =~ /You are now persistently logged in as perlmonks user/) { Xchat::set_context('cbstream'); Xchat::command('close'); Xchat::set_context('#cbstream-login'); Xchat::command('close'); Xchat::set_context('#cbstream'); (my $msg = $nth->[3]) =~ s/^:\+//; Xchat::print("CBLOGIN: $nth->[3]"); return Xchat::EAT_ALL; } } return Xchat::EAT_NONE; }