1#!/usr/local/bin/perl
2#
3#    $Id: dccmove.pl,v 1.4 2007/04/17 21:32:30 peder Exp $
4#
5# Copyright (C) 2003 by Peder Stray <peder@ninja.no>
6#
7
8use strict;
9use Irssi;
10use vars qw{$VERSION %IRSSI};
11($VERSION) = '$Revision: 1.4 $' =~ / (\d+\.\d+) /;
12%IRSSI = (
13          name        => 'dccmove',
14          authors     => 'Peder Stray',
15          contact     => 'peder@ninja.no',
16          url         => 'http://ninja.no/irssi/dccmove.pl',
17          license     => 'GPL',
18          description => 'Move completed dcc gets to the subfolder done',
19         );
20
21sub sig_dcc_closed {
22    my($dcc) = @_;
23    my($dir,$file);
24
25    return unless $dcc->{type} eq 'GET';
26    return unless -f $dcc->{file};
27
28    ($dir,$file) = $dcc->{file} =~ m,(.*)/(.*),;
29    $dir .= "/done";
30
31    if ($dcc->{transfd} < $dcc->{size}) {
32	printf('%%gDCC aborted %%_%s%%_, %%R%d%%%%%%g remaining%%n',
33	       $file,
34	       $dcc->{size} ? 100 - $dcc->{transfd}/$dcc->{size}*100 : 0,
35	      );
36	return;
37    }
38
39    mkdir $dir, 0755 unless -d $dir;
40    rename $dcc->{file}, "$dir/$file";
41
42    printf('%%gDCC moved %%_%s%%_ to %%_%s%%_%%n', $file, $dir);
43
44}
45
46Irssi::signal_add_last('dcc closed', 'sig_dcc_closed');
47