diff --git a/Hermes/Socket/Requests/CreateRedemptionAck.cs b/Hermes/Socket/Requests/CreateRedemptionAck.cs index 874cbc9..929dc49 100644 --- a/Hermes/Socket/Requests/CreateRedemptionAck.cs +++ b/Hermes/Socket/Requests/CreateRedemptionAck.cs @@ -29,7 +29,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests } _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}]"); } } } \ No newline at end of file diff --git a/Hermes/Socket/Requests/UpdateRedeemptionAck.cs b/Hermes/Socket/Requests/UpdateRedeemptionAck.cs index 96864c6..f5cdea7 100644 --- a/Hermes/Socket/Requests/UpdateRedeemptionAck.cs +++ b/Hermes/Socket/Requests/UpdateRedeemptionAck.cs @@ -29,9 +29,9 @@ namespace TwitchChatTTS.Hermes.Socket.Requests } 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 - _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}]"); } } } \ No newline at end of file diff --git a/Twitch/Redemptions/RedemptionManager.cs b/Twitch/Redemptions/RedemptionManager.cs index 78361b7..63ac0d4 100644 --- a/Twitch/Redemptions/RedemptionManager.cs +++ b/Twitch/Redemptions/RedemptionManager.cs @@ -93,7 +93,7 @@ namespace TwitchChatTTS.Twitch.Redemptions public void Add(Redemption redemption) { _redemptions.Add(redemption.Id, redemption); - Add(redemption.TwitchRedemptionId, redemption); + Add(redemption.RedemptionId, redemption); } private void Add(string twitchRedemptionId, string redemptionId) @@ -171,15 +171,33 @@ namespace TwitchChatTTS.Twitch.Redemptions switch (action.Type) { 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)); - _logger.Debug($"Overwritten text to file [file: {action.Data["file_path"]}][chatter: {senderDisplayName}][chatter id: {senderId}]"); - break; + { + string path = action.Data["file_path"]; + if (string.IsNullOrWhiteSpace(path)) + 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": - Directory.CreateDirectory(Path.GetDirectoryName(action.Data["file_path"])!); - await File.AppendAllTextAsync(action.Data["file_path"], ReplaceContentText(action.Data["file_content"], senderDisplayName)); - _logger.Debug($"Appended text to file [file: {action.Data["file_path"]}][chatter: {senderDisplayName}][chatter id: {senderId}]"); - break; + { + string path = action.Data["file_path"]; + if (string.IsNullOrWhiteSpace(path)) + 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": var type = typeof(OBSTransformationData); 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)) { _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 _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); - if (_redeems.TryGetValue(redemption.TwitchRedemptionId, out var redeem)) + if (_redeems.TryGetValue(redemption.RedemptionId, out var redeem)) { redeem.Remove(redemptionId); if (!redeem.Any()) - _redeems.Remove(redemption.TwitchRedemptionId); + _redeems.Remove(redemption.RedemptionId); return true; } } @@ -446,7 +464,7 @@ namespace TwitchChatTTS.Twitch.Redemptions { 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(); int index = redeems.IndexOf(redemption.Id), i; @@ -476,7 +494,7 @@ namespace TwitchChatTTS.Twitch.Redemptions { r.ActionName = redemption.ActionName; r.State = redemption.State; - r.TwitchRedemptionId = redemption.TwitchRedemptionId; + r.RedemptionId = redemption.RedemptionId; r.Order = redemption.Order; } _logger.Debug($"Updated redemption in redemption manager [redemption id: {redemption.Id}][redemption action: {redemption.ActionName}]");