Skip to content

Commit

Permalink
support from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
sharl committed Mar 28, 2012
1 parent 6ab89c8 commit 145ef95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README
Expand Up @@ -10,3 +10,4 @@ nick = foobar
* usage

$ ircrelay "#hacktheirc" "this is test message"
$ cat README | ircrelay "#hacktheirc" -
15 changes: 13 additions & 2 deletions ircrelay
Expand Up @@ -19,10 +19,14 @@ my $PASS = $ini->{_}->{pass};
my $NICK = $ini->{_}->{nick};

if ($#ARGV != 1) {
print STDERR "usage: " . basename($0) . " <channel> <message>\n";
print STDERR "usage: " . basename($0) . " <channel> <message | ->\n";
exit 1;
}
my ($channel, $message) = @ARGV;
my @messages;
if ($message eq '-') {
@messages = <STDIN>;
}

my $irc = new Net::IRC;
my $conn = $irc->newconn(
Expand All @@ -35,7 +39,14 @@ sub on_connect {
my $self = shift;

$self->join($channel);
$self->notice($channel, $message);
if ($#messages >= 0) {
for (@messages) {
$self->notice($channel, $_);
sleep(1); # avoid flood
}
} else {
$self->notice($channel, $message);
}
exit;
}
$conn->add_handler('endofmotd', \&on_connect);
Expand Down

0 comments on commit 145ef95

Please sign in to comment.