Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Nullinside.Api.Common/Twitch/ITwitchApiProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using TwitchLib.Api.Helix.Models.Chat.GetChatters;
using TwitchLib.Api.Helix.Models.Moderation.BanUser;
using TwitchLib.Api.Helix.Models.Moderation.GetModerators;
using TwitchLib.Api.Helix.Models.Users.GetUsers;

namespace Nullinside.Api.Common.Twitch;

Expand Down Expand Up @@ -49,7 +50,7 @@ public interface ITwitchApiProxy {
/// </summary>
/// <param name="token">The cancellation token.</param>
/// <returns>The twitch user information if successful, null otherwise.</returns>
Task<(string? id, string? username)> GetUser(CancellationToken token = new());
Task<User?> GetUser(CancellationToken token = new());

/// <summary>
/// Gets the twitch id and username of the username provided.
Expand Down
9 changes: 4 additions & 5 deletions src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,23 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires,
/// <inheritdoc />
public async Task<bool> GetAccessTokenIsValid(CancellationToken token = new()) {
try {
return !string.IsNullOrWhiteSpace((await GetUser(token)).id);
return !string.IsNullOrWhiteSpace((await GetUser(token))?.Id);
}
catch {
return false;
}
}

/// <inheritdoc />
public virtual async Task<(string? id, string? username)> GetUser(CancellationToken token = new()) {
public virtual async Task<User?> GetUser(CancellationToken token = new()) {
return await Retry.Execute(async () => {
ITwitchAPI api = GetApi();
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync();
if (null == response) {
return (null, null);
return null;
}

User? user = response.Users.FirstOrDefault();
return (user?.Id, user?.Login);
return response.Users.FirstOrDefault();
}, Retries, token);
}

Expand Down