From ed0948f3c7411521c08d840ec897ea4dfdf0c65d Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 19 Nov 2023 00:55:49 -0600 Subject: [PATCH] Updated ConnectionCredentials so a username is optional. If no username is provided to the ConnectionCredentials, a default username of `justinfan` right-padded with 4-5 random digits will be generated. --- .../ConnectionCredentials.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/TwitchLib.Client.Models/ConnectionCredentials.cs b/TwitchLib.Client.Models/ConnectionCredentials.cs index 90564003..e509b5ff 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();