From d2d863d68e3baa590071f98c973128c07e3eac9b Mon Sep 17 00:00:00 2001 From: Raphael Moreira Date: Mon, 23 Oct 2023 12:46:10 -0300 Subject: [PATCH] Technological updates for the SmackMyBitch program The proposed improvements are: - Update of the framework to .net6; - Update Twilio to the latest version; - Improve readability with clean code; --- CSharp/SmackMyBitch.cs | 64 ++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/CSharp/SmackMyBitch.cs b/CSharp/SmackMyBitch.cs index d5c13fc..7073499 100644 --- a/CSharp/SmackMyBitch.cs +++ b/CSharp/SmackMyBitch.cs @@ -1,35 +1,37 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Twilio; +using Twilio.Rest.Api.V2010.Account; -namespace Hacker_Scripts +//Exit early if any session with my username is found +if (args[0] is null) { - class SmackMyBitch - { - public static string TWILIO_ACCOUNT_SID = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); - public static string AUTH_TOKEN = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); - - public static string YOUR_NUMBER = "9879789978"; - public static string HER_NUMBER = "3213213233"; - - static void Main(string[] args) - { - var twilio = new TwilioRestClient(TWILIO_ACCOUNT_SID, AUTH_TOKEN); - - string[] randomMessages = { - "Working hard", - "Gotta ship this feature", - "Someone fucked the system again" - }; - - int randomIndex = new Random().Next(randomMessages.Count()); - String messageToSend = (randomMessages[randomIndex]); - - var message = twilio.SendMessage(YOUR_NUMBER, HER_NUMBER, messageToSend); - Console.WriteLine(message.Sid); - } - } + return; } + +var twilioAccountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); +var authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); + +//Phone numbers +const string myNumber = "+xxx"; +const string herNumber = "+xxx"; + +TwilioClient.Init(twilioAccountSid, authToken); + +string[] reasons = { + "Working hard", + "Gotta ship this feature", + "Someone fucked the system again" +}; + +var randomNumber = new Random().Next(reasons.Length); +var reason = reasons[randomNumber]; +var message = $"Late at work. {reason}"; + +//Send a text message +MessageResource.Create( + body: message, + from: new Twilio.Types.PhoneNumber(myNumber), + to: new Twilio.Types.PhoneNumber(herNumber) +); + +//Log this +Console.WriteLine($@"Message sent at: #{DateTime.Now} | Reason: #{reason}");