Skip to content

Proposal for technological and best practices update for the C# script #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Next Next commit
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;
  • Loading branch information
raphaelmoreira authored Oct 23, 2023
commit 7b5429d05a85c76194c40881245bc2a2797d1fdc
64 changes: 33 additions & 31 deletions CSharp/Hangover.cs
Original file line number Diff line number Diff line change
@@ -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);