2
0
mirror of https://github.com/narkoz/hacker-scripts synced 2025-08-22 18:37:10 +00:00
hacker-scripts/perl/smack-my-bitch-up.pl
robaganrab 3bcd684b06 Add perl/smack-my-bitch-up.pl
Dependencies:
- DateTime
- SMS::Send::Twilio
- YAML
2015-11-27 15:43:13 +01:00

73 lines
1.5 KiB
Perl
Executable File

#!/usr/bin/perl
use strict;
use warnings;
use DateTime;
use SMS::Send;
use YAML;
# Config
my $conf = Load( <<'...' );
---
phone_numbers:
my_number: +15005550006
her_number: +xxx
reasons:
- Working hard
- Gotta ship this feature
- Someone fucked the system again
...
my $date = DateTime->now;
# Skip on weekends
if ( $date->day_of_week >= 6 ) {
exit;
}
# Exit early if no sessions with my username are found
open( my $cmd_who, '-|', 'who' ) || die "Cannot pipe who command ". $!;
my @sessions = grep {
m/$ENV{'USER'}/
} <$cmd_who>;
close $cmd_who;
exit if ( scalar( @sessions ) == 0 );
# Load Twilio API config
open( my $env, '<', '../.env' ) || die "Cannot find .env file in project root.";
LINE: while ( my $line = <$env> ) {
next LINE unless ( $line =~ m/^(TWILIO[^=]+)=(.*)(?:[\n\r]*)/ );
$conf->{'env'}->{ $1 } = $2;
}
close $env;
# Randomize excuse
my $reason_number = int( rand( scalar( @{ $conf->{'reasons'} } ) ) );
my $sms_text = "Late at work. ". $conf->{'reasons'}[ $reason_number ];
# Create an object. There are three required values:
my $sender = SMS::Send->new('Twilio',
_accountsid => $conf->{'env'}->{'TWILIO_ACCOUNT_SID'},
_authtoken => $conf->{'env'}->{'TWILIO_AUTH_TOKEN'},
_from => $conf->{'phone_numbers'}->{'my_number'},
);
# Send a message to me
my $sent = $sender->send_sms(
text => $sms_text,
to => $conf->{'phone_numbers'}->{'her_number'},
);
# Did it send?
if ( $sent ) {
print "Sent message.\n";
} else {
print "Message failed.\n";
}