Sunday, February 1, 2009

PERL Code to change Google talk status

Code :
The following code changes the status of gmail/gtalk user status.
Requires NET::XMPP module, and with SSL modules installed.

#usage : perl <status>
use strict;
use Net::XMPP;

## Pls fill in these here :)
my $username = "";
my $password = "";

my $hostname = '';
my $port = 5222;
my $componentname = '';
my $connectiontype = 'tcpip';
my $tls = 1;

my $Con = new Net::XMPP::Client(debuglevel=>0);

my $status = $Con->Connect(
hostname => $hostname,
port => $port,
componentname => $componentname,
connectiontype => $connectiontype,
tls => $tls,
timeout => 10);

if (!(defined($status))) {

my $sid = $Con->{SESSION}->{id};
$Con->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;

my @result = $Con->AuthSend(
username => $username,
password => $password,
resource => "neuron");

$Con->Send("<iq type='get' to=''><query xmlns=''/></iq>");

my $iq = $Con->SendAndReceiveWithID("<iq type='get' to='$username\'><query xmlns='google:shared-status'/></iq>");

my ($status,$statuslist,$show) = ("","","");
$status = $1 if($iq->GetXML() =~ m/<status>(.*?)<\/status>/);
$statuslist = $1 if($iq->GetXML() =~ m/(<status-list(.*)<\/status-list>)/);
$show = $1 if($iq->GetXML() =~ m/<show>(.*?)<\/show>/);

my $status = $ARGV[0];

#Change status
$Con->Send("<iq type='set' to='$username\'><query xmlns='google:shared-status'>

perl "my status"

Worked? or Crap?
Lemme know....


Dave Jacoby said...

Worked AND crap?

It's working code, and I am not going to argue with working code. However, I'll point out that it doesn't go well with strict and warnings because you redefine $status three times. Thank you for it. I'll likely poke at it, make it "Modern" a bit, then blog it. Thanks!

Arun Prabhakar said...

okie sure, do let me know of the new code.
Thanx in advance. :)

Dave Jacoby said...

Here's my first pass.

I have to do more work getting credentials out of the code and into a config file.