summaryrefslogtreecommitdiff
path: root/localmarkdown2sms
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2009-08-09 00:21:00 +0200
committerJonas Smedegaard <dr@jones.dk>2009-08-09 00:21:00 +0200
commitda610563f2230fc3f2d69fd7d88a4b8f33a13acf (patch)
tree35d03f7ad632117a91530c52764064cc9c32d71c /localmarkdown2sms
parent4aaf7f0ffe97b1a4a4317c9970fee0bb9923632c (diff)
Add fallback message.
Diffstat (limited to 'localmarkdown2sms')
-rwxr-xr-xlocalmarkdown2sms31
1 files changed, 23 insertions, 8 deletions
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 {