From 6eef9c02d29390a769671ccf83cbddfe4d44567e Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Thu, 11 Oct 2012 16:08:38 +0200 Subject: Use NetSDS::Kannel and Getopt::Long::Descriptive. --- smsbot | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) 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 []', + ['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 + +=head1 BUGS + +Send Bug Reports to Jonas Smedegaard -- cgit v1.2.3