From 7b5429d05a85c76194c40881245bc2a2797d1fdc Mon Sep 17 00:00:00 2001 From: Raphael Moreira Date: Mon, 23 Oct 2023 12:37:08 -0300 Subject: [PATCH] Technological updates for the `Hangover` program The proposed improvements are: - Update of the framework to .net6; - Update Twilio to the latest version; - Improve readability with clean code; --- CSharp/Hangover.cs | 64 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/CSharp/Hangover.cs b/CSharp/Hangover.cs index fe7a588..7e954d6 100644 --- a/CSharp/Hangover.cs +++ b/CSharp/Hangover.cs @@ -1,34 +1,36 @@ -namespace Hacker_Scripts +using Twilio; +using Twilio.Rest.Api.V2010.Account; + +//Exit early if any session with my username is found +if (args[0] is null) { - using System; - using Twilio; - using System.Linq; - - class Hangover - { - 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 BOSS_NUMBER = "3213213233"; - - static void Main(string[] args) - { - var twilio = new TwilioRestClient(TWILIO_ACCOUNT_SID, AUTH_TOKEN); - - string[] randomMessages = { - "Locked out", - "Pipes broke", - "Food poisoning", - "Not feeling well" - }; - - int randomIndex = new Random().Next(randomMessages.Count()); - String messageToSend = (randomMessages[randomIndex]); - - var message = twilio.SendMessage(YOUR_NUMBER, BOSS_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 numberOfBoss = "+xxx"; + +TwilioClient.Init(twilioAccountSid, authToken); + +string[] excuses = { + "Locked out", + "Pipes broke", + "Food poisoning", + "Not feeling well" +}; + +var rand = new Random().Next(excuses.Length); +var message = $"Gonna work from home. {excuses[rand]}"; + +//Send a text message +var response = MessageResource.Create( + body: message, + from: new Twilio.Types.PhoneNumber(myNumber), + to: new Twilio.Types.PhoneNumber(numberOfBoss) +); + +Console.WriteLine(response.Sid);