Permalink
Browse files

support from stdin

  • Loading branch information...
1 parent 6ab89c8 commit 145ef95cd7f2354515a54097d64c0ee140ea497c @sharl committed Mar 28, 2012
Showing with 14 additions and 2 deletions.
  1. +1 −0 README
  2. +13 −2 ircrelay
View
1 README
@@ -10,3 +10,4 @@ nick = foobar
* usage
$ ircrelay "#hacktheirc" "this is test message"
+$ cat README | ircrelay "#hacktheirc" -
View
@@ -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(
@@ -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);

0 comments on commit 145ef95

Please sign in to comment.