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
21 changes: 11 additions & 10 deletions src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using TwitchLib.Api.Helix.Models.Moderation.GetModerators;
using TwitchLib.Api.Helix.Models.Streams.GetStreams;
using TwitchLib.Api.Helix.Models.Users.GetUsers;
using TwitchLib.Api.Interfaces;

using Stream = TwitchLib.Api.Helix.Models.Streams.GetStreams.Stream;

Expand Down Expand Up @@ -73,7 +74,7 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires)

/// <inheritdoc />
public async Task<TwitchAccessToken?> CreateAccessToken(string code, CancellationToken token = new()) {
TwitchAPI api = GetApi();
ITwitchAPI api = GetApi();
AuthCodeResponse? response = await api.Auth.GetAccessTokenFromCodeAsync(code, ClientSecret, ClientRedirect);
if (null == response) {
return null;
Expand All @@ -90,7 +91,7 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires)
/// <inheritdoc />
public async Task<TwitchAccessToken?> RefreshAccessToken(CancellationToken token = new()) {
try {
TwitchAPI api = GetApi();
ITwitchAPI api = GetApi();
RefreshResponse? response = await api.Auth.RefreshAuthTokenAsync(OAuth?.RefreshToken, ClientSecret, ClientId);
if (null == response) {
return null;
Expand All @@ -116,7 +117,7 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires)
/// <inheritdoc />
public async Task<(string? id, string? username)> GetUser(CancellationToken token = new()) {
return await Retry.Execute(async () => {
TwitchAPI api = GetApi();
ITwitchAPI api = GetApi();
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync();
if (null == response) {
return (null, null);
Expand All @@ -130,7 +131,7 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires)
/// <inheritdoc />
public async Task<string?> GetUserEmail(CancellationToken token = new()) {
return await Retry.Execute(async () => {
TwitchAPI api = GetApi();
ITwitchAPI api = GetApi();
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync();
if (null == response) {
return null;
Expand Down Expand Up @@ -175,7 +176,7 @@ public async Task<IEnumerable<TwitchModeratedChannel>> GetUserModChannels(string
public async Task<IEnumerable<BannedUser>> BanChannelUsers(string channelId, string botId,
IEnumerable<(string Id, string Username)> users, string reason, CancellationToken token = new()) {
return await Retry.Execute(async () => {
TwitchAPI api = GetApi();
ITwitchAPI api = GetApi();

var bannedUsers = new List<BannedUser>();
foreach ((string Id, string Username) user in users) {
Expand Down Expand Up @@ -209,7 +210,7 @@ public async Task<IEnumerable<BannedUser>> BanChannelUsers(string channelId, str
public async Task<IEnumerable<Chatter>> GetChannelUsers(string channelId, string botId,
CancellationToken token = new()) {
return await Retry.Execute(async () => {
TwitchAPI api = GetApi();
ITwitchAPI api = GetApi();
var chatters = new List<Chatter>();
string? cursor = null;
int total = 0;
Expand All @@ -231,7 +232,7 @@ public async Task<IEnumerable<Chatter>> GetChannelUsers(string channelId, string

/// <inheritdoc />
public async Task<IEnumerable<string>> GetChannelsLive(IEnumerable<string> userIds) {
TwitchAPI api = GetApi();
ITwitchAPI api = GetApi();

// We can only query 100 at a time, so throttle the search.
var liveUsers = new List<Stream>();
Expand All @@ -256,7 +257,7 @@ public async Task<IEnumerable<string>> GetChannelsLive(IEnumerable<string> userI
/// <inheritdoc />
public async Task<IEnumerable<Moderator>> GetChannelMods(string channelId, CancellationToken token = new()) {
return await Retry.Execute(async () => {
TwitchAPI api = GetApi();
ITwitchAPI api = GetApi();

var results = new List<Moderator>();
GetModeratorsResponse? response = null;
Expand All @@ -283,7 +284,7 @@ public async Task<IEnumerable<string>> GetChannelsLive(IEnumerable<string> userI
/// <inheritdoc />
public async Task<bool> AddChannelMod(string channelId, string userId, CancellationToken token = new()) {
return await Retry.Execute(async () => {
TwitchAPI api = GetApi();
ITwitchAPI api = GetApi();
await api.Helix.Moderation.AddChannelModeratorAsync(channelId, userId);
return true;
}, Retries, token);
Expand All @@ -293,7 +294,7 @@ public async Task<IEnumerable<string>> GetChannelsLive(IEnumerable<string> userI
/// Gets a new instance of the <see cref="TwitchAPI" />.
/// </summary>
/// <returns>A new instance of the <see cref="TwitchAPI" />.</returns>
private TwitchAPI GetApi() {
protected ITwitchAPI GetApi() {
var api = new TwitchAPI {
Settings = {
ClientId = ClientId,
Expand Down
86 changes: 0 additions & 86 deletions src/Nullinside.Api/Controllers/TwitchBotController.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Nullinside.Api/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task<IActionResult> Login([FromForm] GoogleOpenIdToken creds, Cance
[HttpGet]
[Route("twitch-login")]
public async Task<IActionResult> TwitchLogin([FromQuery] string code, [FromServices] ITwitchApiProxy api,
CancellationToken token) {
CancellationToken token = new()) {
string? siteUrl = _configuration.GetValue<string>("Api:SiteUrl");
if (null == await api.CreateAccessToken(code, token)) {
return Redirect($"{siteUrl}/user/login?error=3");
Expand Down
Loading