Compare commits

...

2 Commits

5 changed files with 28 additions and 13 deletions

View File

@ -27,8 +27,10 @@ namespace TwitchChatTTS.Chat.Groups
public void Add(long chatterId, string groupId) public void Add(long chatterId, string groupId)
{ {
if (_chatters.TryGetValue(chatterId, out var list)) if (_chatters.TryGetValue(chatterId, out var list))
{
if (!list.Contains(groupId)) if (!list.Contains(groupId))
list.Add(groupId); list.Add(groupId);
}
else else
_chatters.Add(chatterId, new List<string>() { groupId }); _chatters.Add(chatterId, new List<string>() { groupId });
} }
@ -37,8 +39,9 @@ namespace TwitchChatTTS.Chat.Groups
{ {
if (_chatters.TryGetValue(chatter, out var list)) if (_chatters.TryGetValue(chatter, out var list))
{ {
foreach (var group in groupIds) foreach (var groupId in groupIds)
list.Add(group); if (!list.Contains(groupId))
list.Add(groupId);
} }
else else
_chatters.Add(chatter, groupIds); _chatters.Add(chatter, groupIds);
@ -85,7 +88,7 @@ namespace TwitchChatTTS.Chat.Groups
public void Modify(Group group) public void Modify(Group group)
{ {
_groups[group.Name] = group; _groups[group.Id] = group;
} }
public bool Remove(string groupId) public bool Remove(string groupId)
@ -104,10 +107,10 @@ namespace TwitchChatTTS.Chat.Groups
if (_chatters.TryGetValue(chatterId, out var groups)) if (_chatters.TryGetValue(chatterId, out var groups))
{ {
groups.Remove(groupId); groups.Remove(groupId);
_logger.Debug($"Removed chatter from group [chatter id: {chatterId}][group name: {_groups[groupId]}][group id: {groupId}]"); _logger.Debug($"Removed chatter from group [chatter id: {chatterId}][group name: {_groups[groupId].Name}][group id: {groupId}]");
return true; return true;
} }
_logger.Debug($"Failed to remove chatter from group [chatter id: {chatterId}][group name: {_groups[groupId]}][group id: {groupId}]"); _logger.Debug($"Failed to remove chatter from group [chatter id: {chatterId}][group name: {_groups[groupId].Name}][group id: {groupId}]");
return false; return false;
} }
} }

View File

@ -84,6 +84,7 @@ namespace TwitchChatTTS.Chat.Messaging
var msg = FilterMessage(fragments, reply); var msg = FilterMessage(fragments, reply);
string voiceSelected = chatterId == null ? _user.DefaultTTSVoice : GetSelectedVoiceFor(chatterId.Value); string voiceSelected = chatterId == null ? _user.DefaultTTSVoice : GetSelectedVoiceFor(chatterId.Value);
var messages = GetPartialTTSMessages(msg, voiceSelected).ToList(); var messages = GetPartialTTSMessages(msg, voiceSelected).ToList();
_logger.Debug("TTS messages separated as: " + string.Join(" || ", messages.Select(m => m.Message ?? "<" + m.File + ">")));
var groupedMessage = new TTSGroupedMessage(broadcasterId, chatterId, messageId, messages, DateTime.UtcNow, priority); var groupedMessage = new TTSGroupedMessage(broadcasterId, chatterId, messageId, messages, DateTime.UtcNow, priority);
_player.Add(groupedMessage, groupedMessage.Priority); _player.Add(groupedMessage, groupedMessage.Priority);
@ -223,7 +224,7 @@ namespace TwitchChatTTS.Chat.Messaging
}]; }];
} }
return matches.Cast<Match>().SelectMany(match => var messages = matches.Cast<Match>().SelectMany(match =>
{ {
var m = match.Groups["message"].Value; var m = match.Groups["message"].Value;
if (string.IsNullOrWhiteSpace(m)) if (string.IsNullOrWhiteSpace(m))
@ -233,6 +234,13 @@ namespace TwitchChatTTS.Chat.Messaging
voiceSelected = voiceSelected[0].ToString().ToUpper() + voiceSelected.Substring(1).ToLower(); voiceSelected = voiceSelected[0].ToString().ToUpper() + voiceSelected.Substring(1).ToLower();
return HandlePartialMessage(voiceSelected, m); return HandlePartialMessage(voiceSelected, m);
}); });
string beforeMatch = message.Substring(0, matches.First().Index);
if (!string.IsNullOrEmpty(beforeMatch))
messages = HandlePartialMessage(defaultVoice, beforeMatch).Union(messages);
_logger.Debug("TTS message matches: " + string.Join(" || ", matches.Select(m => "(" + m.Length + " / " + m.Index + "): " + m.Value + " ")));
return messages;
} }
private string GetSelectedVoiceFor(long chatterId) private string GetSelectedVoiceFor(long chatterId)

View File

@ -33,16 +33,16 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
return; return;
} }
var exists = _groups.Get(groupId); var group = _groups.Get(groupId);
if (exists == null) if (group == null)
{ {
_logger.Warning($"Group id does not exist [group id: {exists}]"); _logger.Warning($"Group id does not exist [group id: {group}]");
return; return;
} }
_logger.Debug($"Removing group [group id: {exists.Id}][group name: {exists.Name}][group priority: {exists.Priority}]"); _logger.Debug($"Removing group [group id: {group.Id}][group name: {group.Name}][group priority: {group.Priority}]");
_groups.Remove(exists.Id); _groups.Remove(group.Id);
_logger.Information($"Group has been updated [group id: {exists.Id}]"); _logger.Information($"Group has been updated [group id: {group.Id}]");
} }
} }
} }

View File

@ -46,7 +46,10 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
var groupsById = groupInfo.Groups.ToDictionary(g => g.Id, g => g); var groupsById = groupInfo.Groups.ToDictionary(g => g.Id, g => g);
foreach (var group in groupInfo.Groups) foreach (var group in groupInfo.Groups)
{
_logger.Debug($"Adding group [group id: {group.Id}][name: {group.Name}][priority: {group.Priority}]");
_groups.Add(group); _groups.Add(group);
}
foreach (var permission in groupInfo.GroupPermissions) foreach (var permission in groupInfo.GroupPermissions)
{ {

View File

@ -70,6 +70,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
} }
string permission = GetPermissionPath(message.ChannelPointsCustomRewardId, bits); string permission = GetPermissionPath(message.ChannelPointsCustomRewardId, bits);
_logger.Information(chatterId + " / " + permission + " / groups: " + string.Join(" | ", groups));
if (!HasPermission(chatterId, groups, permission)) if (!HasPermission(chatterId, groups, permission))
{ {
_logger.Debug($"Blocked message [chatter: {chatterLogin}][message: {message}]"); _logger.Debug($"Blocked message [chatter: {chatterLogin}][message: {message}]");
@ -136,7 +137,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
private bool HasPermission(long chatterId, IEnumerable<string> groups, string permissionPath) private bool HasPermission(long chatterId, IEnumerable<string> groups, string permissionPath)
{ {
return chatterId == _user.OwnerId ? true : _permissionManager.CheckIfAllowed(groups, permissionPath) == true; return chatterId == _user.OwnerId || _permissionManager.CheckIfAllowed(groups, permissionPath) == true;
} }
} }
} }