Executing a command when file transfer completes or fails.

Discussion about Perl, TCL or Python scripts and C/C++ plugins (using and writing them).

Executing a command

Postby Chemizt » 17 Oct 2009 20:04

Hi!

I'd like to have xchat notify me when xdcc downloads are completed or fail, and after some looking around it seems to me that constructing a simple script for it is probably the way to go.

The debian host which runs xchat has bash scripts for the notifications in place that can send text messages to cell phones so performing a system call with a few arguments should do the trick.

Can any of you point me in the right direction with regards to hooking the file transfer events? I am a bit confused and don't really know where to start. Or perhaps you even know of a similar script which could serve as a basis for implementing such functionality?
Chemizt
 
Posts: 2
Joined: 17 Oct 2009 19:40

Postby LifeIsPain » 18 Oct 2009 10:31

Not very complete as I don't know what your notify script is looking for, but the following perl script would call some external command and pass on the file and sender, although depending on what you want, you may also want to hook 'DCC RECV Abort', 'DCC RECV Failed', andd 'DCC RECV File Open Error'

Code: Select all
use strict;
use warnings;
use Xchat qw(:all);

register('Notify on Download', '001', 'Run an external command on DCC Complete');

hook_print('DCC RECV Complete', \&notify_complete);
sub notify_complete {
   my ($file, $savedas, $from, $cps) = @{$_[0]};

   # This is the line you would want to change to specify what command to run
   exec '/path/to/your/script '.quotemeta($file).' '.quotemeta($from);

   return EAT_NONE;
}
User avatar
LifeIsPain
 
Posts: 522
Joined: 25 Aug 2005 06:36

Postby Chemizt » 18 Oct 2009 18:35

Thanks for your help!

Based on your amazingly spot-on example I made a handy little script that calls an external bash script which takes 3 parameters (status, filename and sender) and uses them to construct a simple message to be sent across the cellular network, for example: "file MyFile.zip has reached "COMPLETE" status (from servbot22)"

For reference, I'm posting the result of my work here as well. Should be a pretty clean job, but tips are welcome. Thanks again!

Code: Select all
use strict;
use warnings;
use Xchat qw(:all);

register('Notify on Download', '0.1', 'Run an external command on DCC Event');

my $script_location = '/usr/scripts/xchat/sendnotifysms';

hook_print('DCC RECV Complete', \&notify_complete);
hook_print('DCC RECV Connect', \&notify_connect);
hook_print('DCC RECV Failed', \&notify_failed);
hook_print('DCC RECV Abort', \&notify_abort);

sub notify_complete {
   # Parameters for this callback are nick, destination filepath, file, cps
   my ($file, $savedas, $from, $cps) = @{$_[0]};
   system $script_location.' COMPLETE '.quotemeta($file).' '.quotemeta($from);
   return EAT_NONE;
}

sub notify_connect {
   # Parameters for this callback are nick, host, file
   my ($from, $host, $file) = @{$_[0]};
   system $script_location.' CONNECT '.quotemeta($file).' '.quotemeta($from);
   return EAT_NONE;
}

sub notify_failed {
   # Parameters for this callback are file, destfile, nick, errorstring
   my ($file, $savedas, $from, $errorstring) = @{$_[0]};
   system $script_location.' FAILED '.quotemeta($file).' '.quotemeta($from);
   return EAT_NONE;
}

sub notify_abort {
   # Parameters for this callback are nick, file
   my ($from, $file) = @{$_[0]};
   system $script_location.' ABORTED '.quotemeta($file).' '.quotemeta($from);
   return EAT_NONE;
}
Chemizt
 
Posts: 2
Joined: 17 Oct 2009 19:40


Return to Scripts and Plugins

Who is online

Users browsing this forum: Bing [Bot] and 2 guests