我試圖建立一個IRC Bot,它告訴我在私人通道中的每個提交消息都是我想知道的。但我有麻煩了每使用Perl構建SVN後提交鉤子: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);
所以,我的殭屍程序連接,並且可以跟我說話......
如果我手動啓動shell腳本,只發送一個單詞($ user內的字符串,甚至下面的冒號)。
如果腳本是通過SVN調用低谷提交,是好像$用戶和$提交字符串是空的,$用戶和$回購傳輸...
我想,什麼是錯的我whoami和svnlook的使用...但我無法弄清楚。也許有人可以給我一個提示?
好的,非常感謝,這有幫助。我的主要錯誤是「PRIVMSG mynick」 – marvin2k 2010-02-09 15:14:56