Esta es una contribucion al fabuloso proyecto Pybuddy.
http://code.google.com/p/pybuddy/wiki/PluginForPidgin
#######
# GPL v3
# Andres Basile <basile@gmail.com>
#
# i-buddy.pl -> plugin for Pidgin
# It should be located on: ~/.purple/plugins/i-buddy.pl
# then [re]start Pidgin.
# Go to Tools -> Plugins -> i-buddy
# and enable it.
#
use Purple;
%PLUGIN_INFO = (
perl_api_version => 2,
name => "i-buddy",
version => "0.1",
summary => "Plugin to control i-buddy USB gadget",
description => "In order to work, pybuddy must be working and listening on localhost port 8888.\nFollow the instructions here:\nhttp://code.google.com/p/pybuddy/wiki/Installation\n",
author => "Andres Basile <basile\@gmail.com>",
url => "https://sites.google.com/site/basile/devel/perl-1/pybuddy",
load => "plugin_load",
unload => "plugin_unload"
);
sub plugin_init {
return %PLUGIN_INFO;
}
sub plugin_load {
my $plugin = shift;
$buddy_handle = Purple::BuddyList::get_handle();
Purple::Signal::connect($buddy_handle, "buddy-status-changed", $plugin, \&buddy_status, "buddy-status-changed");
$received_msg_handle = Purple::Conversations::get_handle();
Purple::Signal::connect($received_msg_handle, "received-im-msg", $plugin, \&received_msg, "received-im-msg");
Purple::Debug::info("i-buddy", "plugin_load()\n");
}
sub plugin_unload {
my $plugin = shift;
Purple::Debug::info("i-buddy", "plugin_unload()");
}
sub buddy_status {
my ($buddy, $old_status, $status) = @_;
open(MY_PIPE, "| nc -q0 -u localhost 8888");
if ( $status->get_name() =~ /Available/i ) {
print MY_PIPE "MACRO_HEART2";
}
elsif ( $status->get_name() =~ /Do\ Not\ Disturb/i )
{
print MY_PIPE "MACRO_RED";
}
elsif ( $status->get_name() =~ /Extended\ away/i )
{
print MY_PIPE "MACRO_YELLOW";
}
elsif ( $status->get_name() =~ /Away/i )
{
print MY_PIPE "MACRO_BLUE";
}
elsif ( $status->get_name() =~ /Offline/i )
{
print MY_PIPE "MACRO_VIOLET";
}
else {
}
close(MY_PIPE);
Purple::Debug::info("i-buddy", "Status changed for \"".$buddy->get_alias()."\" to \"".$status->get_name()."\"\n");
}
sub received_msg {
my ($account, $sender, $msg, $conversation, $flag) = @_;
open(MY_PIPE, "| nc -q0 -u localhost 8888");
print MY_PIPE "DEMO";
close(MY_PIPE);
Purple::Debug::info("i-buddy", "Received msg on \"".$account->get_username()."\" from \"".$sender." -> ".$msg." <- type ".$conversation->get_type()." flag ".$flag."\"\n");
}