Version update check is optional. Removed reliance on web API. Fixed client reconnection due to redemptions.
This commit is contained in:
parent
b74b1d70f3
commit
5fc1b5f942
@ -31,15 +31,4 @@ public class HermesApiClient
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
@ -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<string, string>(message.TTSVoicesAvailable);
|
||||
|
56
TTS.cs
56
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.");
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user