Perl Irssi scripting: rename invalid DCC file

186 Views Asked by At

I'm on Windows, using Irssi client irssi-win32-0.8.12.exe.

I'm having problems receiving a file with invalid name:

..nameo_\u2605_name.. (err: DCC can't create file)

How can I strip this invalid part "\u2605" from filename, using script?

This page doesn't help

I think this part of the Irssi source has something to do with it. Starting at line 195

/* if some plugin wants to change the file name/path here.. */
signal_emit("dcc get receive", 1, dcc);    
1

There are 1 best solutions below

0
On

I sure hope Irssi on Windows accepts scripts written in Perl. If this is the case, here's the solution:

use strict;
use warnings;

our $VERSION = "1.0";
our %IRSSI = ();

# interception made by registering signal as first + Irssi::signal_continue()
sub event_ctcp_dccsend {
    my ($server, $args, $nick, $addr, $target) = @_;

    # split incomming send request args into filename (either before first space or
    #  quoted), and the rest (IP, port, +optionally filesize)
    my ($filename, $rest) = $args =~ /((?:".*")|\S*)\s+(.*)/;

    # remember file name for informing sake
    my $oldname = $filename;
    # replace backslashes with "BSL" (change to anything you wish)
    if ($filename =~ s/\\/BSL/g) {
        # some info for user
        Irssi::print('DCC SEND request from '.$nick.': renamed bad filename '.$oldname.' to '.$filename);
        $args = $filename." ".$rest;
        # propagate signal; Irssi will proceed the request with altered arguments ($args) 
        Irssi::signal_continue($server, $args, $nick, $addr, $target);  
    }
}

# register signal of incoming ctcp 'DCC SEND', before anything else
Irssi::signal_add_first('ctcp msg dcc send', 'event_ctcp_dccsend');

The script intercepts "DCC SEND" ctcp messages and replaces all backslashes in the filename into "BSL" string, then forwards altered arguments of message to any other scripts and Irssi. If you want to remove all "\uXXXX" instead, use s/\\u\w{4}//g in place of s/\\/BSL/g

I hope it helps!