Compare commits

..

3 Commits

5 changed files with 38 additions and 28 deletions

View File

@@ -34,7 +34,6 @@ namespace TwitchChatTTS.Hermes.Socket
public bool LoggedIn { get; set; } public bool LoggedIn { get; set; }
public bool Ready { get; set; } public bool Ready { get; set; }
private bool _attempting;
public HermesSocketClient( public HermesSocketClient(
@@ -85,29 +84,23 @@ namespace TwitchChatTTS.Hermes.Socket
{ {
lock (_lock) lock (_lock)
{ {
if (Connected || _attempting) if (Connected)
return; return;
_attempting = true;
} }
_logger.Debug($"Attempting to connect to {URL}"); _logger.Debug($"Attempting to connect to {URL}");
await ConnectAsync(URL); await ConnectAsync(URL);
_attempting = false;
} }
private async Task Disconnect() private async Task Disconnect()
{ {
lock (_lock) lock (_lock)
{ {
if (!Connected || _attempting) if (!Connected)
return; return;
_attempting = true;
} }
await DisconnectAsync(new SocketDisconnectionEventArgs("Normal disconnection", "Disconnection was executed")); await DisconnectAsync(new SocketDisconnectionEventArgs("Normal disconnection", "Disconnection was executed"));
_attempting = false;
} }
public async Task CreateTTSVoice(string voiceName) public async Task CreateTTSVoice(string voiceName)

View File

@@ -29,7 +29,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
} }
_redemptions.Add(redemption); _redemptions.Add(redemption);
_logger.Information($"A new redemption has been created [redemption id: {redemption.Id}][twitch redemption id: {redemption.TwitchRedemptionId}]"); _logger.Information($"A new redemption has been created [redemption id: {redemption.Id}][twitch redemption id: {redemption.RedemptionId}]");
} }
} }
} }

View File

@@ -31,8 +31,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
var policies = JsonSerializer.Deserialize<IEnumerable<Policy>>(json, _options); var policies = JsonSerializer.Deserialize<IEnumerable<Policy>>(json, _options);
if (policies == null || !policies.Any()) if (policies == null || !policies.Any())
{ {
_logger.Information($"No policies have been found. Policies have been set to default."); _logger.Error($"No policies have been found.");
_policies.Set("everyone", "tts", 25, TimeSpan.FromSeconds(15));
return; return;
} }

View File

@@ -29,9 +29,9 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
} }
if (_redemptions.Update(redemption)) if (_redemptions.Update(redemption))
_logger.Information($"A redemption has been updated [redemption id: {redemption.Id}][twitch redemption id: {redemption.TwitchRedemptionId}]"); _logger.Information($"A redemption has been updated [redemption id: {redemption.Id}][twitch redemption id: {redemption.RedemptionId}]");
else else
_logger.Warning($"Failed to update an existing redemption [redemption id: {redemption.Id}][twitch redemption id: {redemption.TwitchRedemptionId}]"); _logger.Warning($"Failed to update an existing redemption [redemption id: {redemption.Id}][twitch redemption id: {redemption.RedemptionId}]");
} }
} }
} }

View File

@@ -93,7 +93,7 @@ namespace TwitchChatTTS.Twitch.Redemptions
public void Add(Redemption redemption) public void Add(Redemption redemption)
{ {
_redemptions.Add(redemption.Id, redemption); _redemptions.Add(redemption.Id, redemption);
Add(redemption.TwitchRedemptionId, redemption); Add(redemption.RedemptionId, redemption);
} }
private void Add(string twitchRedemptionId, string redemptionId) private void Add(string twitchRedemptionId, string redemptionId)
@@ -171,15 +171,33 @@ namespace TwitchChatTTS.Twitch.Redemptions
switch (action.Type) switch (action.Type)
{ {
case "WRITE_TO_FILE": case "WRITE_TO_FILE":
Directory.CreateDirectory(Path.GetDirectoryName(action.Data["file_path"])!); {
await File.WriteAllTextAsync(action.Data["file_path"], ReplaceContentText(action.Data["file_content"], senderDisplayName)); string path = action.Data["file_path"];
_logger.Debug($"Overwritten text to file [file: {action.Data["file_path"]}][chatter: {senderDisplayName}][chatter id: {senderId}]"); if (string.IsNullOrWhiteSpace(path))
break; return;
string? directory = Path.GetDirectoryName(path);
if (!string.IsNullOrWhiteSpace(directory))
Directory.CreateDirectory(directory);
await File.WriteAllTextAsync(path, ReplaceContentText(action.Data["file_content"], senderDisplayName));
_logger.Debug($"Overwritten text to file [file: {action.Data["file_path"]}][chatter: {senderDisplayName}][chatter id: {senderId}]");
break;
}
case "APPEND_TO_FILE": case "APPEND_TO_FILE":
Directory.CreateDirectory(Path.GetDirectoryName(action.Data["file_path"])!); {
await File.AppendAllTextAsync(action.Data["file_path"], ReplaceContentText(action.Data["file_content"], senderDisplayName)); string path = action.Data["file_path"];
_logger.Debug($"Appended text to file [file: {action.Data["file_path"]}][chatter: {senderDisplayName}][chatter id: {senderId}]"); if (string.IsNullOrWhiteSpace(path))
break; return;
string? directory = Path.GetDirectoryName(path);
if (!string.IsNullOrWhiteSpace(directory))
Directory.CreateDirectory(directory);
await File.AppendAllTextAsync(path, ReplaceContentText(action.Data["file_content"], senderDisplayName));
_logger.Debug($"Appended text to file [file: {action.Data["file_path"]}][chatter: {senderDisplayName}][chatter id: {senderId}]");
break;
}
case "OBS_TRANSFORM": case "OBS_TRANSFORM":
var type = typeof(OBSTransformationData); var type = typeof(OBSTransformationData);
await _obs.UpdateTransformation(action.Data["scene_name"], action.Data["scene_item_name"], (d) => await _obs.UpdateTransformation(action.Data["scene_name"], action.Data["scene_item_name"], (d) =>
@@ -392,7 +410,7 @@ namespace TwitchChatTTS.Twitch.Redemptions
if (_actions.ContainsKey(redemption.ActionName)) if (_actions.ContainsKey(redemption.ActionName))
{ {
_logger.Debug($"Fetched a redeemable action [redemption id: {redemption.Id}][redemption action: {redemption.ActionName}][order: {redemption.Order}]"); _logger.Debug($"Fetched a redeemable action [redemption id: {redemption.Id}][redemption action: {redemption.ActionName}][order: {redemption.Order}]");
Add(redemption.TwitchRedemptionId, redemption.Id); Add(redemption.RedemptionId, redemption.Id);
} }
else else
_logger.Warning($"Could not find redeemable action [redemption id: {redemption.Id}][redemption action: {redemption.ActionName}][order: {redemption.Order}]"); _logger.Warning($"Could not find redeemable action [redemption id: {redemption.Id}][redemption action: {redemption.ActionName}][order: {redemption.Order}]");
@@ -422,11 +440,11 @@ namespace TwitchChatTTS.Twitch.Redemptions
} }
_redemptions.Remove(redemptionId); _redemptions.Remove(redemptionId);
if (_redeems.TryGetValue(redemption.TwitchRedemptionId, out var redeem)) if (_redeems.TryGetValue(redemption.RedemptionId, out var redeem))
{ {
redeem.Remove(redemptionId); redeem.Remove(redemptionId);
if (!redeem.Any()) if (!redeem.Any())
_redeems.Remove(redemption.TwitchRedemptionId); _redeems.Remove(redemption.RedemptionId);
return true; return true;
} }
} }
@@ -446,7 +464,7 @@ namespace TwitchChatTTS.Twitch.Redemptions
{ {
if (_redemptions.TryGetValue(redemption.Id, out var r)) if (_redemptions.TryGetValue(redemption.Id, out var r))
{ {
if (r.Order != redemption.Order && _redeems.TryGetValue(redemption.TwitchRedemptionId, out var redeems) && redeems.Count > 1) if (r.Order != redemption.Order && _redeems.TryGetValue(redemption.RedemptionId, out var redeems) && redeems.Count > 1)
{ {
var redemptions = redeems.Select(r => _redemptions.TryGetValue(r, out var rr) ? rr : null).ToArray(); var redemptions = redeems.Select(r => _redemptions.TryGetValue(r, out var rr) ? rr : null).ToArray();
int index = redeems.IndexOf(redemption.Id), i; int index = redeems.IndexOf(redemption.Id), i;
@@ -476,7 +494,7 @@ namespace TwitchChatTTS.Twitch.Redemptions
{ {
r.ActionName = redemption.ActionName; r.ActionName = redemption.ActionName;
r.State = redemption.State; r.State = redemption.State;
r.TwitchRedemptionId = redemption.TwitchRedemptionId; r.RedemptionId = redemption.RedemptionId;
r.Order = redemption.Order; r.Order = redemption.Order;
} }
_logger.Debug($"Updated redemption in redemption manager [redemption id: {redemption.Id}][redemption action: {redemption.ActionName}]"); _logger.Debug($"Updated redemption in redemption manager [redemption id: {redemption.Id}][redemption action: {redemption.ActionName}]");