By "Some people" you were politely avoiding mentioning my nick :-P
By "trouble" I was pointing out that: a) I had to learn an entirely new manner of coding in perl (Xchat's interface, and hook-programming in general, which seems backwards relative to procedural or OO programming), b) the curve combined with less-than-stellar documentation for the Xchat interface resulted in surprises which were difficult to overcome. I suspect it took me about 5 or 6 hours to get to a working Xchat script (though if I knew what I was doing, it likely would have been less than one hour), whereas if the interface were to be using CGI on the server side, a quick LWP or WWW::Mechanize script would have been whipped out in a matter of five minutes. (In fact, you probably would have had one already for testing with.) Granted, this would be far more work for you than the current method... :-)
However, I did get something that seems to work. It doesn't fully auto-login. I haven't yet figured out how to get it to run as I do my initial connect to the FreeNode server, but just typing "/cblog" is sufficiently easy to remember. For others who use Xchat, here is what I ended up with:
#! /usr/bin/perl
use strict;
use warnings;
my $name = 'cbstream';
my $version = 0.01;
my %conf = (
cbstream => {
pmuser => 'Tanktalus',
pmpassword => 'myperlmonkspasswordisreallylongbuteasyt
+oremember',
},
);
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-logi
+n'; 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 perlmo
+nks 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;
}
You'll obviously have to change the user and password near the top.
Save this to a file with a .pl extention in your xchat directory (for me on unix, it's ~/.xchat2, on Windows it should be something like "C:\Documents and Settings\youruser\Application Data\X-Chat 2"). I think that will get it autoloading, though I've not really tested to be sure. Then you can just type "/cblog" to log in to cbstream.
The surprising bit was that I couldn't merge the "join" command with the "say plogin" command in the same routine. They had to be separate. I also haven't figured out how to leave #cbstream-login, nor close its tab. Nor close the private-message tab opened when cbstream responds telling me I'm now persistently logged in. Thanks, ambrus.
Update: closing tabs is fine... restoring your last tab is interestingly not. Added code to handle the closing of tabs - though it happens too quick, so I've opted to copy the message over to the #cbstream tab (it doesn't get sent to the IRC server, so your secret of using IRC for CB remains safe). |