我正在尝试构建一个 IRC Bot,它在私人频道中告诉我我想知道的每条提交消息。但我很难得到每个
#!/bin/bash
REPOS="$1"
REV="$2"
# call bot with arguments reposname, revison and commit message in one string
/usr/bin/perl /home/user/repo/svn_irc_bot.pl "$REPOS" "$REV"
# all checks passed, so allow the commit
exit 0
然后,调用的 Perl-Skript:
#!/usr/bin/perl -w
# see http://www.javalinux.it/wordpress/2009/10/15/writing-an-irc-bot-for-svn-commit-notification/
# see http://oreilly.com/pub/h/1964
use strict;
# We will use a raw socket to connect to the IRC server.
use IO::Socket;
my $repos = $ARGV[0];
my $rev = $ARGV[1];
my $commit = `/usr/bin/svnlook log $repos`;
my $user = `whoami`;
# The server to connect to and our details.
my $server = "irc.server.com";
my $nick = "bot2";
my $login = "bot2";
# The channel which the bot will join.
# my $channel = "#channel";
# Connect to the IRC server.
my $sock = new IO::Socket::INET(PeerAddr => $server,
PeerPort => 6667,
Proto => 'tcp') or
die "Can't connect\n";
# Log on to the server.
print $sock "NICK $nick\r\n";
print $sock "USER $login 8 * :Perl IRC Hacks Robot\r\n";
# Read lines from the server until it tells us we have connected.
while (my $input = <$sock>) {
# Check the numerical responses from the server.
if ($input =~ /004/) {
# We are now logged in.
print $sock "PRIVMSG mynick : $user: $repos r$rev -- $commit\n";
last;
}
elsif ($input =~ /433/) {
die "Nickname is already in use.";
}
}
sleep(5);
print $sock "QUIT bye... \n";
sleep(5);
close($sock);
所以,我的 Bot 确实可以连接,并且可以与我交谈……
如果我手动启动 shell 脚本,则只发送一个单词($user 中的字符串,甚至不发送下面的冒号)。
如果脚本由 SVN 通过提交调用,似乎 $user 和 $commit 字符串为空,$user 和 $repos 被传输......
我想我对 whoami 和 svnlook 的使用有问题……但我想不通。也许有人可以给我一个提示?