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 #**************************************************************************/
25 use NDIRC::Dispatcher;
28 help => q(.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),
29 acl => q(irc_sendsms),
31 }, class extends NDIRC::Command {
32 method execute($c,$msg) {
33 my ($number,$message) = $msg =~ /^(\S+) (.+)$/ or die 'ARGS';
36 if (length $message > 140){
37 $c->reply("Message is too long");
40 if ($number =~ /^\+([1-9]\d+)$/){
43 my ($sms) = $dbh->selectrow_array(q{
44 SELECT sms FROM users WHERE username ilike $1
45 AND uid IN (SELECT uid FROM groupmembers WHERE gid = 'M')
47 $sms //= 'No number, or invalid user';
48 if ($sms =~ /^\+([1-9]\d+)$/){
51 $c->reply("User $number has number '$sms' which is not a valid international number");
55 my $sms = $dbh->prepare(q{
56 INSERT INTO sms (uid,number,message)
60 $sms->execute($c->uid,$number,$message);
61 my ($id) = $sms->fetchrow_array;
62 $c->reply("Message added to queue, you can see the status with: .smsstatus $id");
66 command smsstatus => {
67 help => q(.smsstatus smsid | Gives information about a given sms),
68 acl => q(irc_smsstatus),
70 }, class extends NDIRC::Command {
71 method execute($c,$msg) {
72 my ($id) = $msg =~ /(\d+)/ or die 'ARGS';
75 my $sms = $dbh->selectrow_hashref(q{
76 SELECT s.id, u.username, s.number, s.status, s.cost
77 ,s.time AT TIME ZONE 'GMT' AS time
79 JOIN users u USING (uid)
84 $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}");
86 $c->reply("Could not find any sms with id: $id");
92 help => q(.sendmail <username or email addy> message),
93 acl => q(irc_sendmail),
95 }, class extends NDIRC::Command {
98 method execute($c,$msg) {
99 my ($user,$message) = $msg =~ /^(\S+) (.+)$/ or die 'ARGS';
106 $mail = $dbh->selectrow_array(q{
107 SELECT email FROM users WHERE username ilike $1
108 AND uid IN (SELECT uid FROM groupmembers WHERE gid = 'M')
110 $mail //= 'No mail, or invalid user';
111 if ($mail =~ /^\S+@\S+$/){
113 $c->reply("User $user has email addy '$mail' which looks odd");
118 smtp => 'ruin.nu:587',
120 From => 'NewDawn Command <nd@ruin.nu>',
121 'Content-type' => 'text/plain; charset="UTF-8"',
122 Subject => "ND: " . (substr $message, 0, 60),
123 Message => encode("UTF-8",$message),
126 if (sendmail %mail) {
127 $c->reply("Mail sent to $user");
129 $c->reply("Could not send mail to $user: " . $Mail::Sendmail::error);