File: dccmove.pl

package info (click to toggle)
irssi-scripts 20100512
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,420 kB
  • ctags: 2,479
  • sloc: perl: 58,204; sh: 171; makefile: 33
file content (45 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/perl
#
#    $Id: dccmove.pl,v 1.4 2007/04/17 21:32:30 peder Exp $
#
# Copyright (C) 2003 by Peder Stray <peder@ninja.no>
#

use Irssi;
use vars qw{$VERSION %IRSSI};
($VERSION) = '$Revision: 1.4 $' =~ / (\d+\.\d+) /;
%IRSSI = (
          name        => 'dccmove',
          authors     => 'Peder Stray',
          contact     => 'peder@ninja.no',
          url         => 'http://ninja.no/irssi/dccmove.pl',
          license     => 'GPL',
          description => 'Move completed dcc gets to the subfolder done',
         );

sub sig_dcc_closed {
    my($dcc) = @_;
    my($dir,$file);

    return unless $dcc->{type} eq 'GET';
    return unless -f $dcc->{file};

    ($dir,$file) = $dcc->{file} =~ m,(.*)/(.*),;
    $dir .= "/done";

    if ($dcc->{transfd} < $dcc->{size}) {
	printf('%%gDCC aborted %%_%s%%_, %%R%d%%%%%%g remaining%%n', 
	       $file,
	       $dcc->{size} ? 100 - $dcc->{transfd}/$dcc->{size}*100 : 0,
	      );
	return;
    }

    mkdir $dir, 0755 unless -d $dir;
    rename $dcc->{file}, "$dir/$file";

    printf('%%gDCC moved %%_%s%%_ to %%_%s%%_%%n', $file, $dir);
     
}

Irssi::signal_add_last('dcc closed', 'sig_dcc_closed');