Skip to content

Commit

Permalink
Updated ConnectionCredentials to use an anonymous user by default (#257)
Browse files Browse the repository at this point in the history
* 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.

* Updated call to Random to provide a min value

Co-authored-by: AoshiW <[email protected]>
  • Loading branch information
ChrisBlueStone and AoshiW authored Apr 6, 2024
1 parent f54d60b commit 8c5e0ae
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{new Random().Next(1000, 89999)}";
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 8c5e0ae

Please sign in to comment.