【问题标题】:Perl Irssi scripting: How to send msg to a specific channel?Perl Irssi 脚本:如何将 msg 发送到特定频道?
【发布时间】:2011-12-13 09:45:12
【问题描述】:

我需要使用Irssi Perl 脚本来建立这个单一的任务。我有自己的频道,我想在某些情况下直接向该频道发送消息。

我对 Perl 的经验非常有限,所以我没有这个。我很困惑如何在 Irssi Perl 脚本中管理不同的聊天网和频道。那么我如何发送消息,例如频道#testchan@Quakenet

测试一:

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

测试二(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") 
}

【问题讨论】:

  • @user1009108:编辑您的问题以添加您的代码并准确地描述什么不起作用。使用代码块进行格式化(选择所有代码并在编辑器中点击{} 按钮)

标签: perl irc channel irssi


【解决方案1】:

这是一个用于机器人的示例:)

#==========================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');

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-16
    • 2022-07-16
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    • 2021-12-31
    相关资源
    最近更新 更多