1 #**************************************************************************
2 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
20 package NDIRC::Commands::SMS;
27 use MooseX::MethodAttributes;
31 : Help(.sendsms <username or number> message | number has to be an international number, like +44234234562 for a uk number or +1234528234 for a north american number)
35 my ($self,$c,$msg) = @_;
36 my ($number,$message) = $msg =~ /^(\S+) (.+)$/ or die 'ARGS';
39 if (length $message > 140){
40 $c->reply("Message is too long");
43 if ($number =~ /^\+([1-9]\d+)$/){
46 my ($sms) = $dbh->selectrow_array(q{
47 SELECT sms FROM users WHERE username ilike $1
48 AND uid IN (SELECT uid FROM groupmembers WHERE gid = 'M')
50 $sms //= 'No number, or invalid user';
51 if ($sms =~ /^\+([1-9]\d+)$/){
54 $c->reply("User $number has number '$sms' which is not a valid international number");
58 my $sms = $dbh->prepare(q{
59 INSERT INTO sms (uid,number,message)
63 $sms->execute($c->uid,$number,$message);
64 my ($id) = $sms->fetchrow_array;
65 $c->reply("Message added to queue, you can see the status with: .smsstatus $id");
69 : Help(.smsstatus smsid | Gives information about a given sms)
73 my ($self,$c,$msg) = @_;
74 my ($id) = $msg =~ /(\d+)/ or die 'ARGS';
77 my $sms = $dbh->selectrow_hashref(q{
78 SELECT s.id, u.username, s.number, s.status, s.cost
79 ,s.time AT TIME ZONE 'GMT' AS time
81 JOIN users u USING (uid)
86 $c->reply("SMS <b>$sms->{id}</b> was sent by <b>$sms->{username}</b> to <b>$sms->{number}</b> cost: <b>$sms->{cost}</b>. Last status at <b>$sms->{time}</b>: $sms->{status}");
88 $c->reply("Could not find any sms with id: $id");