2016-02-15 115 views
0

我做了我的第一个irssi perl脚本,但它不起作用。我不明白为什么不。通道上的irssi dcc统计信息

当我在通道上键入!dccstat时,我的家用PC只是响应所有的DCC连接,就像我在irssi上键入/dcc stat一样。

use Irssi; 

use vars qw($VERSION %IRSSI); 

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

sub event_privmsg { 
my ($server, $data, $nick, $mask) [email protected]_; 
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'); 

回答

0

的一个问题可能是dccs()命令本身,它不是在我的irssi v0.8.15的认可,所以我用Irssi::Irc::dccs()。它返回dcc连接数组,所以它不会(原谅我的讽刺)“神奇地”变成当前dccs状态的字符串,因为“/ 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) [email protected]_; 
    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'); 

而且,你用“事件PRIVMSG”,这也引发了(惊喜!)私人信息,不仅渠道的,但它适用于那些太(响应会被送到一个私人消息给用户)。如果不需要,我建议使用“message public”信号,如下所示:

# .. 

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

    # .. the rest of code 

} 

Irssi::signal_add("message public", event_message_public);