Auto Away Notifier for Pidgin in Perl


Whenever I am away from laptop my chat buddies leave me lots message and finally lots of “You there???”. So I thought of making a script that would inform my buddies that I am away when someone sends me a message.
This method works with Pigin API.
I have used /proc/acpi/button/lid/C267/state file to find if the lib of the laptop is closed or not. This file may vary in your laptop. So try to find the find the file in your computer that stores the status of the lid. It should be a file in /proc/acpi/button/lid/ folder and replace the file accordingly in your computer.
The Content of /proc/acpi/button/lid/C267/state is state: open and state: closed when the lid was closed.

We save this file as /usr/lib/purple-2/autonotifier.pl and use chmod +x /usr/lib/purple-2/test.pl to give the plugin execute permission. Now restart the Pidgin if it is running or open pidgin and go to Tools->Plugins and you should see a plugin named “Auto Away Plugin”. Activate it and that’s it.
I have used /sys/class/leds/b43-phy0::radio/brightness file to notify me if there is any messages while i was away. It uses my Wi-fi light to notify me. When there is a message then the Wi-fi light blinks. This too is computer specific so find the file that controls any of the unused leds and replace that file too.

use Purple;
%PLUGIN_INFO = (
perl_api_version => 2,
name => "Auto Away Plugin",
version => "0.1",
summary => "Auto Away Notifier",
description => "Auto Away Notifier in Perl",
author => "R.Srijith <rsrijith007@gmail.com",
url => "http://sriunplugged.blogspot.com",
load => "plugin_load",
unload => "plugin_unload"
);
sub plugin_init {
return %PLUGIN_INFO;
}</div>
<div class="prog">

sub im_received {

my ($account, $sender, $message, $conv, $flags) = @_;
Purple::Debug::info("autonotify", "Message recievedn");
$conv1 = Purple::Conversation->new(1, $account, $sender);
open FILE, ">>/home/rsrijith/logs/autonotifier.txt" or die $!;
open LID, "</proc/acpi/button/lid/C267/state" or die $!;
#$message=~s/<.*>//g;
while(<LID>)
{
if($_ =~ m/closed/)
{
print FILE "$sender:$messagen";
$im = $conv1->get_im_data();
if ($im) { print "ok.n"; } else { print "fail.n"; }
system('(if [ ! -e /var/lock/autoremind ];  then   while grep -m 1 -q closed /proc/acpi/button/lid/C267/state;   do    touch /var/lock/autoremind;    sleep 1;    echo -n 0 >/sys/class/leds/b43-phy0::radio/brightness;    sleep 1;echo -n 1 >/sys/class/leds/b43-phy0::radio/brightness;   done;  if [ -e /var/lock/autoremind ];  then   rm /var/lock/autoremind;  fi; fi)&');
$im->send("This is an automated response system: R Srijith is not at the desk rite now.");
}
}
close FILE;
}

sub plugin_load {
$plugin = shift;
$conversation_handle = Purple::Conversations::get_handle();
Purple::Signal::connect($conversation_handle, "received-im-msg", $plugin, &im_received, $data);
Purple::Debug::info("autonotify", "Auto Notify Loadedn");
}

sub plugin_unload {
Purple::Debug::info("autonotify", "Auto Notify Unloadedn");
}

So try it out and comment me on how it went.


, , , , , , , , , , ,

  1. #1 by Wolf on April 4, 2009 - 7:41 am

    Perl is the best scripting language for Text processing and handle regex. I have posted few articles related to those at my blog

    http://icfun.blogspot.com/search/label/perl

    Also Perl’s Cpan has lots of support that I don’t even need to think extra while developing project. I didn’t find such help on other programming language except Java and .NET

  2. #2 by Ab on December 1, 2011 - 8:54 pm

    Hi Srijith,

    Thanks for the plugin, I tried using this – my plugin would pick up a random message from a file and send the message in response. following is the code
    use Purple;

    %PLUGIN_INFO = (
    perl_api_version => 2,
    name => “Auto Away Plugin”,
    version => “0.1″,
    summary => “Auto Away Notifier”,
    description => “Auto Away Notifier in Perl”,
    author => “R.Srijith “http://sriunplugged.blogspot.com”,
    load => “plugin_load”,
    unload => “plugin_unload”
    );

    my @list ;
    my $listSize ;

    sub plugin_init {
    return %PLUGIN_INFO;
    }

    sub im_received {

    my ($account, $sender, $message, $conv, $flags) = @_;

    Purple::Debug::info(“autonotify”, “Message recievedn”);
    $conv1 = Purple::Conversation->new(1, $account, $sender);
    Purple::Debug::info(“autonotify”, “Created conversationn”);

    $msg = $list[rand($listSize)];
    my $im = $conv1->get_im_data();
    Purple::Debug::info(“autonotify”, “Got conversationn”);
    $im->send($msg);
    Purple::Debug::info(“autonotify”, “sent conversationn”);
    }

    sub plugin_load {
    $plugin = shift;
    open FF, “< /home/user1/.purple/messagelist";
    while()
    {
    #print “$_n”;
    push(@list,$_);
    $listSize = @list;
    close FF;
    $conversation_handle = Purple::Conversations::get_handle();
    Purple::Signal::connect($conversation_handle, “received-im-msg”, $plugin, &im_received, $data);
    Purple::Debug::info(“autonotify”, “Auto Notify Loadedn”);
    }

    sub plugin_unload {
    Purple::Debug::info(“autonotify”, “Auto Notify Unloadedn”);
    }

    Somehow the response is being send intermittently. Almost 5% of the time only the reply message returns to the sender. Although the message box opened by the autonotifier shows that the message is sent , but it never reaches the other side.
    Any quick pointer would help a lot.

    THanks

  3. #3 by Ab on December 1, 2011 - 9:16 pm

    Sorry – there is a copy paste error in the above

    the plugin load looks like this
    sub plugin_load {
    $plugin = shift;
    open FF, “< /home/mdabdul/.purple/an";
    while()
    {
    #print “$_n”;
    push(@list,$_);
    }
    $listSize = @list;
    close FF;
    $conversation_handle = Purple::Conversations::get_handle();
    Purple::Signal::connect($conversation_handle, “received-im-msg”, $plugin, &im_received, $data);
    Purple::Debug::info(“autonotify”, “Auto Notify Loadedn”);

(will not be published)


  1. 锘縜utorepair