Version update check is optional. Removed reliance on web API. Fixed client reconnection due to redemptions.

This commit is contained in:
Tom 2025-01-14 03:48:02 +00:00
parent b74b1d70f3
commit 5fc1b5f942
4 changed files with 34 additions and 50 deletions

View File

@ -31,15 +31,4 @@ public class HermesApiClient
{ {
return await _web.GetJson<TTSVersion>($"https://{BASE_URL}/api/info/version"); return await _web.GetJson<TTSVersion>($"https://{BASE_URL}/api/info/version");
} }
public async Task<Account> FetchHermesAccountDetails()
{
var account = await _web.GetJson<Account>($"https://{BASE_URL}/api/account", new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
});
if (account == null || account.Id == null || account.Username == null)
throw new NullReferenceException("Invalid value found while fetching for hermes account data.");
return account;
}
} }

View File

@ -41,6 +41,9 @@ namespace TwitchChatTTS.Hermes.Socket.Handlers
} }
_user.HermesUserId = message.UserId; _user.HermesUserId = message.UserId;
_user.HermesUsername = message.UserName;
_user.TwitchUsername = message.UserName;
_user.TwitchUserId = long.Parse(message.ProviderAccountId);
_user.OwnerId = message.OwnerId; _user.OwnerId = message.OwnerId;
_user.DefaultTTSVoice = message.DefaultTTSVoice; _user.DefaultTTSVoice = message.DefaultTTSVoice;
_user.VoicesAvailable = new ConcurrentDictionary<string, string>(message.TTSVoicesAvailable); _user.VoicesAvailable = new ConcurrentDictionary<string, string>(message.TTSVoicesAvailable);

36
TTS.cs
View File

@ -86,6 +86,8 @@ namespace TwitchChatTTS
return; return;
} }
try
{
var hermesVersion = await _hermesApiClient.GetLatestTTSVersion(); var hermesVersion = await _hermesApiClient.GetLatestTTSVersion();
if (hermesVersion == null) if (hermesVersion == null)
{ {
@ -100,34 +102,13 @@ namespace TwitchChatTTS
_logger.Information("Changelog:\n - " + string.Join("\n - ", changes) + "\n\n"); _logger.Information("Changelog:\n - " + string.Join("\n - ", changes) + "\n\n");
await Task.Delay(15 * 1000); await Task.Delay(15 * 1000);
} }
}
catch
{
_logger.Warning("Failed to check for version updates.");
}
await InitializeHermesWebsocket(); await InitializeHermesWebsocket();
try
{
var hermesAccount = await _hermesApiClient.FetchHermesAccountDetails();
_user.HermesUserId = hermesAccount.Id;
_user.HermesUsername = hermesAccount.Username;
_user.TwitchUsername = hermesAccount.Username;
_user.TwitchUserId = long.Parse(hermesAccount.BroadcasterId);
}
catch (ArgumentNullException)
{
_logger.Error("Ensure you have your Twitch account linked to TTS.");
await Task.Delay(TimeSpan.FromSeconds(30));
return;
}
catch (FormatException)
{
_logger.Error("Ensure you have your Twitch account linked to TTS.");
await Task.Delay(TimeSpan.FromSeconds(30));
return;
}
catch (Exception ex)
{
_logger.Error(ex, "Failed to initialize properly. Restart app please.");
await Task.Delay(TimeSpan.FromSeconds(30));
return;
}
_playback.AddOnMixerInputEnded((object? s, SampleProviderEventArgs e) => _playback.AddOnMixerInputEnded((object? s, SampleProviderEventArgs e) =>
{ {
@ -142,7 +123,8 @@ namespace TwitchChatTTS
_veado.Initialize(); _veado.Initialize();
await _veado.Connect(); await _veado.Connect();
} }
catch (Exception e) { catch (Exception e)
{
_logger.Warning(e, "Failed to connect to Veado websocket server."); _logger.Warning(e, "Failed to connect to Veado websocket server.");
} }

View File

@ -87,12 +87,22 @@ namespace TwitchChatTTS.Twitch.Redemptions
_logger.Debug($"Added redeemable action to redemption manager [action name: {action.Name}]"); _logger.Debug($"Added redeemable action to redemption manager [action name: {action.Name}]");
} }
else else
_logger.Debug($"Redemption manager already has this action stored [action name: {action.Name}]"); {
_actions[action.Name] = action;
_logger.Debug($"Updated redeemable action to redemption manager [action name: {action.Name}]");
}
} }
public void Add(Redemption redemption) public void Add(Redemption redemption)
{
if (!_redemptions.ContainsKey(redemption.Id))
{ {
_redemptions.Add(redemption.Id, redemption); _redemptions.Add(redemption.Id, redemption);
_logger.Debug($"Added redemption to redemption manager [redemption id: {redemption.Id}]");
} else {
_redemptions[redemption.Id] = redemption;
_logger.Debug($"Updated redemption to redemption manager [redemption id: {redemption.Id}]");
}
Add(redemption.RedemptionId, redemption); Add(redemption.RedemptionId, redemption);
} }