首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通道上的irssi dcc统计信息

通道上的irssi dcc统计信息
EN

Stack Overflow用户
提问于 2016-02-16 02:45:35
回答 1查看 242关注 0票数 0

我制作了我的第一个irssi perl脚本,但它不能工作。我不明白有何不可。

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

代码语言:javascript
复制
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');
EN

回答 1

Stack Overflow用户

发布于 2016-03-15 21:39:19

一个问题可能是dccs()命令本身,它在我的IRSSIv0.8.15中不被识别,所以我使用Irssi::Irc::dccs()。它返回dcc连接的数组列表,所以(请原谅我的讽刺)它不会“神奇地”转换成当前dcc状态的字符串,如"/dcc “(您使用的"/dcc ”术语,我认为这不是一个错误,就是我不知道的脚本命令)。您需要遍历dccs数组,并拾取所需的所有数据。下面给出了一个粗略的(但可以工作的)代码,因此您可以将其用作模板。享受Irssi脚本的乐趣。

代码语言:javascript
复制
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“信号,如下所示:

代码语言:javascript
复制
# ..

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

    # .. the rest of code

}

Irssi::signal_add("message public", event_message_public);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35416810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档