Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class CPHInline
- {
- public bool Execute()
- {
- // your main code goes here
- CPH.TryGetArg("input0", out string numberString);
- CPH.TryGetArg("input1", out string fromUnit);
- CPH.TryGetArg("input3", out string toUnit);
- CPH.TryGetArg("msgId", out string replyId);
- if ((numberString == "") || (fromUnit == null) || (toUnit == null))
- {
- CPH.TwitchReplyToMessage("Please provide a whole number and two units. I know Celsius (C), Fahrenheit (F), and Kelvin (K). Example usage: !temp 100 F to C", replyId);
- return false;
- }
- int convertedNumber;
- if (int.TryParse(numberString, out convertedNumber))
- {}
- else
- {
- CPH.TwitchReplyToMessage("Please use a whole number. Negative numbers are also accepted. Here's a correct usage example: !temp 100 F to C", replyId);
- return false;
- }
- string fromUnitLower = fromUnit.ToLower();
- string toUnitLower = toUnit.ToLower();
- switch ((fromUnitLower, toUnitLower))
- {
- case ("c", "f"):
- CPH.TwitchReplyToMessage($"{numberString}°C is about {Convert.ToInt32((convertedNumber * 1.8) + 32)}°F", replyId);
- break;
- case ("c", "k"):
- CPH.TwitchReplyToMessage($"{numberString}°C is about {Convert.ToInt32(convertedNumber + 273.15)}°K", replyId);
- break;
- case ("f", "c"):
- CPH.TwitchReplyToMessage($"{numberString}°F is about {Convert.ToInt32((convertedNumber - 32) / 1.8)}°C", replyId);
- break;
- case ("f", "k"):
- CPH.TwitchReplyToMessage($"{numberString}°F is about {Convert.ToInt32(((convertedNumber - 32) / 1.8) + 273.15)}°K", replyId);
- break;
- case ("k", "c"):
- CPH.TwitchReplyToMessage($"{numberString}°K is about {Convert.ToInt32(convertedNumber - 273.15)}°C", replyId);
- break;
- case ("k", "f"):
- CPH.TwitchReplyToMessage($"{numberString}°K is about {Convert.ToInt32(((convertedNumber - 273.15) * 1.8) + 32)}°F", replyId);
- break;
- case ("c", "c"):
- case ("f", "f"):
- case ("k", "k"):
- CPH.TwitchReplyToMessage("I'm sure you can figure this one out yourself", replyId);
- break;
- default:
- CPH.TwitchReplyToMessage("I only know Celsius (C), Fahrenheit (F), and Kelvin (K). Here's a correct usage example: !temp 100 F to C", replyId);
- break;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement