我制作了我的第一个irssi perl脚本,但它不起作用。我不明白为什么不。
当我在频道上输入!dccstat
时,我的家用电脑只响应所有DCC连接,就像我在irssi上输入/dcc stat
一样。
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');
答案 0 :(得分:0)
一个问题可能是dccs()
命令本身,在我的Irssi v0.8.15中无法识别,因此我使用了Irssi::Irc::dccs()
。它返回 dcc连接的数组,所以它不会(原谅我的讽刺)“神奇地”变成当前dccs状态的字符串,如“/ dcc list”(你使用“/ dcc stat”)我相信的一个术语是一个错误或一个我不知道的脚本命令。您需要遍历dcc数组并获取所需的所有数据。下面给出了一个粗略(但工作)的代码,因此您可以将其用作模板。享受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”也会触发(惊奇!)私人消息,而不仅仅是频道消息,但它也适用于那些(响应将作为私人消息发送给用户)。如果不需要,我建议使用“message public”信号,如下所示:
# ..
sub event_message_public {
my ($server, $msg, $nick, $mask, $target) = @_;
# .. the rest of code
}
Irssi::signal_add("message public", event_message_public);