2024-07-16 01:18:34 +01:00
using TwitchLib.Client.Models ;
namespace TTSMe ;
public abstract class TtsMeCommand {
private const string UsageMessage = "Usage: !ttsme <help|get|set [voice]|randomize|optout>." ;
public const bool VERBOSE = Bot . VERBOSE | | false ;
private static Voices voices = > Voices . Instance ( ) ;
private abstract class Messages {
public static string VoiceSet ( string username ) = > $"ttsme voice for '{username}' is '{Voices.Instance().GetVoice(username) ?? " none "}'" ;
public static string InvalidVoice ( string voice ) = > $"Invalid voice '{voice}'. Valid voices are: {string.Join(" , ", Voices.Instance().ValidVoices)}." ;
}
public static string? ProcessVoiceChange ( ChatMessage chatMessage ) {
string username = chatMessage . Username ;
string [ ] args = chatMessage . Message . Split ( ' ' ) ;
if ( args [ 0 ] ! = "!ttsme" ) return null ;
if ( args . Length is 1 or > 3 ) return UsageMessage ;
string action = args [ 1 ] ;
string voice = args [ ^ 1 ] ;
switch ( action ) {
case "help" : return UsageMessage ;
case "get" when args . Length = = 2 : return Messages . VoiceSet ( username ) ;
case "get" when args . Length = = 3 & & username = = chatMessage . Channel : return Messages . VoiceSet ( voice ) ;
case "randomise" or "randomize" : voices . SetRandomVoice ( username ) ; return $"ttsme voice for '{username}' has been {action}d and is now '{voices.GetVoice(username)}'." ;
case "set" when args . Length ! = 3 : return Messages . InvalidVoice ( "NULL" ) ;
case "set" when ! voices . IsValidVoice ( voice ) : return Messages . InvalidVoice ( voice ) ;
case "set" when voices . IsVoice ( username , voice ) : return $"ttsme voice for '{username}' is already set to '{voice}'." ;
case "set" : voices . SetVoice ( username , voice ) ; return $"Changing ttsme for {username} to '{voice}'" ;
2024-07-16 02:29:14 +01:00
// TODO: Get OptOut working so that it doesn't opt you back in when next chatting
2024-07-16 01:18:34 +01:00
case "optout" : voices . RemoveVoice ( username ) ; return $"Opting {username} out of ttsme, their voice will no longer be heard by the masses (and me!)" ;
default : return UsageMessage ;
}
}
}