One problem may be the dccs()
command itself, it's not recognized in my Irssi v0.8.15, so I used Irssi::Irc::dccs()
. It returns the array of dcc connections, so it won't (pardon my sarcasm) "magically" turn into string of current dccs status, as "/dcc list" (you used "/dcc stat" term which i beleive is either a mistake or a command of a script which is unknown to me). You need to loop through the array of dccs and pick up the all the data you want. A sketchy (but working) code is given below, so you could use it as a template. Have fun with Irssi scripts.
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');
Also, you use "event privmsg" which triggers also for (surprise!) private messages, not only channel ones, yet it works for those too (the response would be sent as a private message to the user). If it's not desired, i suggest use of "message public" signal, as below:
# ..
sub event_message_public {
my ($server, $msg, $nick, $mask, $target) = @_;
# .. the rest of code
}
Irssi::signal_add("message public", event_message_public);