我制作了我的第一个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');发布于 2016-03-15 21:39:19
一个问题可能是dccs()命令本身,它在我的IRSSIv0.8.15中不被识别,所以我使用Irssi::Irc::dccs()。它返回dcc连接的数组列表,所以(请原谅我的讽刺)它不会“神奇地”转换成当前dcc状态的字符串,如"/dcc “(您使用的"/dcc ”术语,我认为这不是一个错误,就是我不知道的脚本命令)。您需要遍历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“,它也会触发for (令人惊讶!)私有消息,不仅是通道消息,而且对那些也有效(响应将作为私有消息发送给用户)。如果不需要,建议使用"message public“信号,如下所示:
# ..
sub event_message_public {
my ($server, $msg, $nick, $mask, $target) = @_;
# .. the rest of code
}
Irssi::signal_add("message public", event_message_public);https://stackoverflow.com/questions/35416810
复制相似问题