diff --git a/TwitchLib.Client.Models/ConnectionCredentials.cs b/TwitchLib.Client.Models/ConnectionCredentials.cs index 9056400..e509b5f 100644 --- a/TwitchLib.Client.Models/ConnectionCredentials.cs +++ b/TwitchLib.Client.Models/ConnectionCredentials.cs @@ -23,21 +23,25 @@ public partial class ConnectionCredentials /// Constructor for ConnectionCredentials object. public ConnectionCredentials( - string twitchUsername, - string twitchOAuth, + string? twitchUsername = null, + string? twitchOAuth = null, bool disableUsernameCheck = false, Capabilities? capabilities = null) { - if (!disableUsernameCheck && !GetUsernameCheckRegex().Match(twitchUsername).Success) + if (twitchUsername != null && + !disableUsernameCheck && + !GetUsernameCheckRegex().Match(twitchUsername).Success) + { throw new Exception($"Twitch username does not appear to be valid. {twitchUsername}"); + } - TwitchUsername = twitchUsername.ToLower(); - TwitchOAuth = twitchOAuth; + TwitchUsername = twitchUsername?.ToLower() ?? $"justinfan${1000 + new Random().Next(79999)}"; + TwitchOAuth = twitchOAuth ?? string.Empty; // Make sure proper formatting is applied to oauth - if (!twitchOAuth.Contains(":")) + if (!TwitchOAuth.Contains(":")) { - TwitchOAuth = $"oauth:{twitchOAuth.Replace("oauth", "")}"; + TwitchOAuth = $"oauth:{TwitchOAuth.Replace("oauth", "")}"; } Capabilities = capabilities ?? new Capabilities();