Perl Irssi scripting: How to send msg to a specific channel?

时间秒杀一切 提交于 2020-01-01 07:18:06

问题


I need to establish this single task with Irssi Perl script. I have my own channel and I want to sent msg directly to that channel in certain scenarios.

My experience with Perl is quite limited so I haven't got this one. I am confused how to manage different chatnets and channels in Irssi Perl scripting. So how I can send message for example channel #testchan@Quakenet for example?

Test one:

server->command("^MSG $info{'#testchan'} $info{'Test message.'}");

Test two (tuto about scripting):

sub away_describe_pub_channels { 
    my($net, $channel) = @_;
    my ($text) = @_;
    my $c = Irssi::server_find_chatnet("QuakeNet")->channel_find("testchan");
    $c->command("DESCRIBE $channel $text") 
}

回答1:


here is an example is used for a bot :)

#==========================BEGINNING OF PARMS======================================
#name of the channels where this feature will be used
my @channels  = ("foo","bar");

#the public commands
#help
my $cmd_help = '!help';

#new ticket
my $cmd_newticket = "!stack";
my %url_newticket = ( 'foo'=>{url=>"http://stackoverflow.com/questions/ask"},
                  'bar'=>{url=>"http://https://github.com/repo/project/issues/new"}


sub bootstrap {
    my ($server, $msg, $nick, $address, $target) = @_;
    #lowercase of the channel name in case this one will be registered in camelCase ;)
    $target = lc $target;

    foreach my $channel (@channels) {
        if ( $target eq "#".$channel) {
            #split the line first peace the command second the rest
            my ($cmd,$line) = split / /,$msg,2;
            if ($cmd =~ $cmd_help) {
                $server->command("MSG ". $nick ." Here are the available commands : !stack");
            } elsif ($cmd eq $cmd_newticket) {
                my $h = $url_newticket{$channel};
                $server->command("MSG $target submit an issue/a ticket $h->{'url'}");
            }
         }
     }
}

#let's add the sub as a signal and let's play
Irssi::signal_add_last('message public', 'bootstrap');

Hope this could help



来源:https://stackoverflow.com/questions/7863746/perl-irssi-scripting-how-to-send-msg-to-a-specific-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!