0

我制作了我的第一个 irssi perl 脚本,但它不起作用。我不明白为什么不。

当我!dccstat在频道上打字时,我的家用电脑只会响应所有 DCC 连接,就像我/dcc stat在 irssi 上打字时一样。

use Irssi;

use vars qw($VERSION %IRSSI);

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

sub event_privmsg {
my ($server, $data, $nick, $mask) =@_;
my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
        return if ( $text !~ /^!dccstat$/i );
if ($text =~ /^!dccstat$/ ) {
        my $dcc = dccs();
        $server->command ( "msg $target $dcc" )
    }
}

Irssi::signal_add('event privmsg', 'event_privmsg');
4

1 回答 1

0

一个问题可能是dccs()命令本身,在我的 Irssi v0.8.15 中无法识别,所以我使用了Irssi::Irc::dccs(). 它返回dcc 连接的数组,因此它不会(请原谅我的讽刺)“神奇地”变成当前 dcc 状态的字符串,如“/dcc list”(您使用了“/dcc stat”术语,我相信这是一个错误或我不知道的脚本命令)。您需要遍历 dccs 数组并获取所需的所有数据。下面给出了一个粗略的(但有效的)代码,因此您可以将其用作模板。玩 Irssi 脚本。

use Irssi;

use vars qw($VERSION %IRSSI);

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

sub event_privmsg {
    my ($server, $data, $nick, $mask) =@_;
    my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
    return if ( $text !~ /^!dccstat$/i ); # this line could be removed as the next one checks for the same
    if ($text =~ /^!dccstat$/ ) {
        # get array of dccs and store it in @dccs
        my @dccs = Irssi::Irc::dccs();
        # iterate through array
        foreach my $dcc (@dccs) {
            # get type of dcc (SEND, GET or CHAT)
            my $type = $dcc->{type};
            # process only SEND and GET types
            if ($type eq "SEND" || $type eq "GET") {
                my $filename = $dcc->{arg};   # name of file            
                my $nickname = $dcc->{nick};  # nickname of sender/receiver
                my $filesize = $dcc->{size};  # size of file in bytes
                my $transfered = $dcc->{transfd}; # bytes transfered so far

                # you probably want to format file size and bytes transfered nicely, i'll leave it to you
                $server->command("msg $target nick: $nickname type: $type file: $filename size: $filesize transfered: $transfered");
            }
        }
    }
}

Irssi::signal_add('event privmsg', 'event_privmsg');

此外,您使用“event privmsg”,它也触发(惊喜!)私人消息,不仅是频道消息,而且它也适用于那些(响应将作为私人消息发送给用户)。如果不需要,我建议使用“消息公开”信号,如下所示:

# ..

sub event_message_public {
    my ($server, $msg, $nick, $mask, $target) = @_;

    # .. the rest of code

}

Irssi::signal_add("message public", event_message_public);
于 2016-03-15T13:39:18.820 回答