Compare commits
3 Commits
b724cd00eb
...
86590f1c7f
| Author | SHA1 | Date | |
|---|---|---|---|
| 86590f1c7f | |||
| 4099322ce2 | |||
| 75fa154546 |
@@ -34,7 +34,6 @@ namespace TwitchChatTTS.Hermes.Socket
|
||||
public bool LoggedIn { get; set; }
|
||||
public bool Ready { get; set; }
|
||||
|
||||
private bool _attempting;
|
||||
|
||||
|
||||
public HermesSocketClient(
|
||||
@@ -85,29 +84,23 @@ namespace TwitchChatTTS.Hermes.Socket
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (Connected || _attempting)
|
||||
if (Connected)
|
||||
return;
|
||||
|
||||
_attempting = true;
|
||||
}
|
||||
|
||||
_logger.Debug($"Attempting to connect to {URL}");
|
||||
await ConnectAsync(URL);
|
||||
_attempting = false;
|
||||
}
|
||||
|
||||
private async Task Disconnect()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!Connected || _attempting)
|
||||
if (!Connected)
|
||||
return;
|
||||
|
||||
_attempting = true;
|
||||
}
|
||||
|
||||
await DisconnectAsync(new SocketDisconnectionEventArgs("Normal disconnection", "Disconnection was executed"));
|
||||
_attempting = false;
|
||||
}
|
||||
|
||||
public async Task CreateTTSVoice(string voiceName)
|
||||
|
||||
@@ -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}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
var policies = JsonSerializer.Deserialize<IEnumerable<Policy>>(json, _options);
|
||||
if (policies == null || !policies.Any())
|
||||
{
|
||||
_logger.Information($"No policies have been found. Policies have been set to default.");
|
||||
_policies.Set("everyone", "tts", 25, TimeSpan.FromSeconds(15));
|
||||
_logger.Error($"No policies have been found.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -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}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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}]");
|
||||
|
||||
Reference in New Issue
Block a user