【问题标题】:Perl Irssi scripting: rename invalid DCC filePerl Irssi 脚本:重命名无效的 DCC 文件
【发布时间】:2014-05-17 11:03:53
【问题描述】:

我在 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);    

【问题讨论】:

  • \u2605 是 Unicode U+2605,一个黑星 - ★。您不能只删除 Unicode 文件名中的字符,因为您可能会面临文件名冲突的风险。您需要在整个程序中支持 Unicode。
  • 我会以某种方式解决文件名冲突。真正的目的是能够更改文件名
  • 我会以某种方式解决文件名冲突。真正的目的是能够在获取时间更改文件名,而不是在下载之后。没关系 - 要么只有 ascii 文件名,要么将所有空格更改为下划线。

标签: perl scripting irssi


【解决方案1】:

我当然希望 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

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-04
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    相关资源
    最近更新 更多