diff --git a/Hermes/HermesApiClient.cs b/Hermes/HermesApiClient.cs index b780e72..153f493 100644 --- a/Hermes/HermesApiClient.cs +++ b/Hermes/HermesApiClient.cs @@ -31,15 +31,4 @@ public class HermesApiClient { return await _web.GetJson($"https://{BASE_URL}/api/info/version"); } - - public async Task FetchHermesAccountDetails() - { - var account = await _web.GetJson($"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; - } } \ No newline at end of file diff --git a/Hermes/Socket/Handlers/LoginAckHandler.cs b/Hermes/Socket/Handlers/LoginAckHandler.cs index 1add60c..da3e7ed 100644 --- a/Hermes/Socket/Handlers/LoginAckHandler.cs +++ b/Hermes/Socket/Handlers/LoginAckHandler.cs @@ -41,6 +41,9 @@ namespace TwitchChatTTS.Hermes.Socket.Handlers } _user.HermesUserId = message.UserId; + _user.HermesUsername = message.UserName; + _user.TwitchUsername = message.UserName; + _user.TwitchUserId = long.Parse(message.ProviderAccountId); _user.OwnerId = message.OwnerId; _user.DefaultTTSVoice = message.DefaultTTSVoice; _user.VoicesAvailable = new ConcurrentDictionary(message.TTSVoicesAvailable); diff --git a/TTS.cs b/TTS.cs index 273d160..f694bba 100644 --- a/TTS.cs +++ b/TTS.cs @@ -86,48 +86,29 @@ namespace TwitchChatTTS return; } - var hermesVersion = await _hermesApiClient.GetLatestTTSVersion(); - if (hermesVersion == null) + try { - _logger.Error("Failed to fetch latest TTS version. Something went wrong."); - return; + var hermesVersion = await _hermesApiClient.GetLatestTTSVersion(); + if (hermesVersion == null) + { + _logger.Error("Failed to fetch latest TTS version. Something went wrong."); + return; + } + if (hermesVersion.MajorVersion > TTS.MAJOR_VERSION || hermesVersion.MajorVersion == TTS.MAJOR_VERSION && hermesVersion.MinorVersion > TTS.MINOR_VERSION) + { + _logger.Information($"A new update for TTS is avaiable! Version {hermesVersion.MajorVersion}.{hermesVersion.MinorVersion} is available at {hermesVersion.Download}"); + var changes = hermesVersion.Changelog.Split("\n"); + if (changes != null && changes.Any()) + _logger.Information("Changelog:\n - " + string.Join("\n - ", changes) + "\n\n"); + await Task.Delay(15 * 1000); + } } - if (hermesVersion.MajorVersion > TTS.MAJOR_VERSION || hermesVersion.MajorVersion == TTS.MAJOR_VERSION && hermesVersion.MinorVersion > TTS.MINOR_VERSION) + catch { - _logger.Information($"A new update for TTS is avaiable! Version {hermesVersion.MajorVersion}.{hermesVersion.MinorVersion} is available at {hermesVersion.Download}"); - var changes = hermesVersion.Changelog.Split("\n"); - if (changes != null && changes.Any()) - _logger.Information("Changelog:\n - " + string.Join("\n - ", changes) + "\n\n"); - await Task.Delay(15 * 1000); + _logger.Warning("Failed to check for version updates."); } 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) => { @@ -142,7 +123,8 @@ namespace TwitchChatTTS _veado.Initialize(); await _veado.Connect(); } - catch (Exception e) { + catch (Exception e) + { _logger.Warning(e, "Failed to connect to Veado websocket server."); } diff --git a/Twitch/Redemptions/RedemptionManager.cs b/Twitch/Redemptions/RedemptionManager.cs index 63ac0d4..c5a4a67 100644 --- a/Twitch/Redemptions/RedemptionManager.cs +++ b/Twitch/Redemptions/RedemptionManager.cs @@ -87,12 +87,22 @@ namespace TwitchChatTTS.Twitch.Redemptions _logger.Debug($"Added redeemable action to redemption manager [action name: {action.Name}]"); } 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) { - _redemptions.Add(redemption.Id, redemption); + if (!_redemptions.ContainsKey(redemption.Id)) + { + _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); }