summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <jonas@atreju.jones.dk>2012-10-11 16:08:38 +0200
committerJonas Smedegaard <jonas@atreju.jones.dk>2012-10-11 16:08:38 +0200
commit6eef9c02d29390a769671ccf83cbddfe4d44567e (patch)
tree926d5b7bc909f5583a908a5c03b7be113a9823f0
parent54b07b7363256c3d61263ee0abbbfba75793805f (diff)
Use NetSDS::Kannel and Getopt::Long::Descriptive.
-rwxr-xr-xsmsbot45
1 files changed, 44 insertions, 1 deletions
diff --git a/smsbot b/smsbot
index 60fb8f6..6cf5995 100755
--- a/smsbot
+++ b/smsbot
@@ -1,6 +1,7 @@
#!/usr/bin/perl
use strict;
use utf8;
+
use AnyEvent;
use AnyEvent::XMPP::Client;
use AnyEvent::XMPP::Ext::Disco;
@@ -8,6 +9,38 @@ use AnyEvent::XMPP::Ext::Version;
use AnyEvent::XMPP::Ext::MUC;
use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
use AnyEvent::XMPP::Util qw/node_jid res_jid/;
+use NetSDS::Kannel;
+#use Coro;
+
+use Getopt::Long::Descriptive;
+
+my ($opt, $usage) = describe_options(
+ '%c %o <jid> <password> <talkfile> [<room>]',
+ ['kannelserver=s', "the Kannel server to connect to",
+ {default => 'localhost'}],
+ ['kannelport=i', "the Kannel port to connect to",
+ {default => 13013}],
+ ['kanneluser=s', "the Kannel users to authenticate as",
+ {default => 'tester'}],
+ ['kannelpasswd=s', "the Kannel password to authenticate with",
+ {default => 'foobar'}],
+ ['kannelsmsc=s', "the Kannel SMSC to correspond with"],
+ [],
+# [ 'verbose|v', "print extra stuff"],
+ [ 'debug', "print debug stuff"],
+ [ 'help', "print usage message and exit"],
+);
+
+print($usage->text), exit if $opt->help;
+
+# TODO: support overriding full URL
+# TODO: use URI module to construct URL
+my $kannel = NetSDS::Kannel->new(
+ sendsms_url => 'http://' . $opt->kannelserver . ':' . $opt->kannelport . '/cgi-bin/sendsms',
+ sendsms_user => $opt->kanneluser,
+ sendsms_passwd => $opt->kannelpasswd,
+ default_smsc => $opt->kannelsmsc,
+);
my @msgs;
@@ -37,7 +70,7 @@ unless (@ARGV >= 3) {
read_messages ($inputfile);
my $j = AnyEvent->condvar;
-my $cl = AnyEvent::XMPP::Client->new (debug => 1);
+my $cl = AnyEvent::XMPP::Client->new (debug => $opt->debug);
my $disco = AnyEvent::XMPP::Ext::Disco->new;
my $version = AnyEvent::XMPP::Ext::Version->new;
my $muc = AnyEvent::XMPP::Ext::MUC->new (disco => $disco);
@@ -101,3 +134,13 @@ $cl->reg_cb (
$cl->start;
$j->wait;
+
+__END__
+
+=head1 COPYRIGHT
+
+2012 © Jonas Smedegaard <dr@jones.dk>
+
+=head1 BUGS
+
+Send Bug Reports to Jonas Smedegaard <dr@jones.dk>