Advertisement
CrayonCrayoff

Streamer.bot Temp Conversion

Jan 5th, 2025 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2.  
  3. public class CPHInline
  4. {
  5.     public bool Execute()
  6.     {
  7.         // your main code goes here
  8.         CPH.TryGetArg("input0", out string numberString);
  9.         CPH.TryGetArg("input1", out string fromUnit);
  10.         CPH.TryGetArg("input3", out string toUnit);
  11.         CPH.TryGetArg("msgId", out string replyId);
  12.        
  13.        
  14.         if ((numberString == "") || (fromUnit == null) || (toUnit == null))
  15.         {
  16.             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);
  17.             return false;
  18.         }
  19.        
  20.         int convertedNumber;
  21.        
  22.         if (int.TryParse(numberString, out convertedNumber))
  23.         {}
  24.         else
  25.         {
  26.             CPH.TwitchReplyToMessage("Please use a whole number. Negative numbers are also accepted. Here's a correct usage example: !temp 100 F to C", replyId);
  27.             return false;
  28.         }
  29.  
  30.        
  31.         string fromUnitLower = fromUnit.ToLower();
  32.         string toUnitLower = toUnit.ToLower();
  33.  
  34.         switch ((fromUnitLower, toUnitLower))
  35.         {
  36.             case ("c", "f"):
  37.                 CPH.TwitchReplyToMessage($"{numberString}°C is about {Convert.ToInt32((convertedNumber * 1.8) + 32)}°F", replyId);
  38.                 break;
  39.             case ("c", "k"):
  40.                 CPH.TwitchReplyToMessage($"{numberString}°C is about {Convert.ToInt32(convertedNumber + 273.15)}°K", replyId);
  41.                 break;
  42.             case ("f", "c"):
  43.                 CPH.TwitchReplyToMessage($"{numberString}°F is about {Convert.ToInt32((convertedNumber - 32) / 1.8)}°C", replyId);
  44.                 break;
  45.             case ("f", "k"):
  46.                 CPH.TwitchReplyToMessage($"{numberString}°F is about {Convert.ToInt32(((convertedNumber - 32) / 1.8) + 273.15)}°K", replyId);
  47.                 break;
  48.             case ("k", "c"):
  49.                 CPH.TwitchReplyToMessage($"{numberString}°K is about {Convert.ToInt32(convertedNumber - 273.15)}°C", replyId);
  50.                 break;
  51.             case ("k", "f"):
  52.                 CPH.TwitchReplyToMessage($"{numberString}°K is about {Convert.ToInt32(((convertedNumber - 273.15) * 1.8) + 32)}°F", replyId);
  53.                 break;
  54.             case ("c", "c"):
  55.             case ("f", "f"):
  56.             case ("k", "k"):
  57.                 CPH.TwitchReplyToMessage("I'm sure you can figure this one out yourself", replyId);
  58.                 break;
  59.             default:
  60.                 CPH.TwitchReplyToMessage("I only know Celsius (C), Fahrenheit (F), and Kelvin (K). Here's a correct usage example: !temp 100 F to C", replyId);
  61.                 break;
  62.         }
  63.         return true;
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement