Perl Irssi脚本:重命名无效的DCC文件

时间:2014-04-04 23:15:48

标签: perl scripting irssi

我在Windows上,使用Irssi客户端irssi-win32-0.8.12.exe。

我在收到名称无效的文件时遇到问题:

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

如何使用脚本从文件名中删除此无效部分“\ u2605”?

This page无效

我认为part of the Irssi source与此有关。从第195行开始

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

1 个答案:

答案 0 :(得分:0)

我确信希望Windows上的Irssi接受用Perl编写的脚本。如果是这种情况,这就是解决方案:

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');

脚本拦截“DCC SEND”ctcp消息,文件名中的所有反斜杠替换为“BSL”字符串,然后将更改的消息参数转发给任何其他脚本和Irssi。 如果您想要删除所有“\ uXXXX”,请使用s/\\u\w{4}//g代替s/\\/BSL/g

我希望它有所帮助!