Skip to content

Commit

Permalink
Updated ConnectionCredentials so a username is optional.
Browse files Browse the repository at this point in the history
If no username is provided to the ConnectionCredentials, a default username of `justinfan` right-padded with 4-5 random digits will be generated.
  • Loading branch information
ChrisBlueStone committed Nov 19, 2023
1 parent bb8afa2 commit ed0948f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions TwitchLib.Client.Models/ConnectionCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@ public partial class ConnectionCredentials

/// <summary>Constructor for ConnectionCredentials object.</summary>
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();
Expand Down

0 comments on commit ed0948f

Please sign in to comment.