From da610563f2230fc3f2d69fd7d88a4b8f33a13acf Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 9 Aug 2009 00:21:00 +0200 Subject: Add fallback message. --- localmarkdown2sms | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'localmarkdown2sms') diff --git a/localmarkdown2sms b/localmarkdown2sms index 51d3bf9..163e732 100755 --- a/localmarkdown2sms +++ b/localmarkdown2sms @@ -126,10 +126,31 @@ foreach my $file (read_dir( $path )) { } } +sub sendmsg { + my ($phone, $desc, $msg) = @_; + + unless ($DUMMY) { + system {'/usr/share/kannel/contrib/sendsms' } $phone, $msg; + print STDERR "Done $desc\n" if ($DEBUG); + } else { + print STDERR "\n --> $desc\n"; + print STDERR $msg . "\n"; + } +} + my ($phone) = shift @ARGV; -my ($key) = shift @ARGV; +my ($key) = lc (shift @ARGV); my $num_children = $#{ $reply{$key} } + 1; # How many children we'll create + +if (0 == $num_children) { + &sendmsg($phone, "fallback message", "Hmmm, strange, the word \"$key\" is unknown. Perhaps you typed it wrong?\n\nPlease try again."); + exit; +} + +if (0 == $num_children) { +} + $SIG{CHLD} = 'IGNORE'; # Don't worry about reaping zombies # Spawn off some children @@ -145,13 +166,7 @@ for my $num ( 0 .. $num_children - 1 ) { run_fork { child { sleep($delay{$key}[$num]) unless ($NOSLEEP); - unless ($DUMMY) { - system {'/usr/share/kannel/contrib/sendsms' } $phone, $reply{$key}[$num]; - print STDERR "Done reply #$num [" . $delay{$key}[$num] . "s]\n" if ($DEBUG); - } else { - print STDERR "\n[" . $delay{$key}[$num] . "s]\n"; - print STDERR $reply{$key}[$num] . "\n"; - } + &sendmsg($phone, "reply #$num [" . $delay{$key}[$num] . "s]", $reply{$key}[$num]); exit; } parent { -- cgit v1.2.3