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)
{
if (_chatters.TryGetValue(chatterId, out var list))
{
if (!list.Contains(groupId))
list.Add(groupId);
}
else
_chatters.Add(chatterId, new List<string>() { groupId });
}
@ -37,8 +39,9 @@ namespace TwitchChatTTS.Chat.Groups
{
if (_chatters.TryGetValue(chatter, out var list))
{
foreach (var group in groupIds)
list.Add(group);
foreach (var groupId in groupIds)
if (!list.Contains(groupId))
list.Add(groupId);
}
else
_chatters.Add(chatter, groupIds);
@ -85,7 +88,7 @@ namespace TwitchChatTTS.Chat.Groups
public void Modify(Group group)
{
_groups[group.Name] = group;
_groups[group.Id] = group;
}
public bool Remove(string groupId)
@ -104,10 +107,10 @@ namespace TwitchChatTTS.Chat.Groups
if (_chatters.TryGetValue(chatterId, out var groups))
{
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;
}
_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;
}
}

View File

@ -84,6 +84,7 @@ namespace TwitchChatTTS.Chat.Messaging
var msg = FilterMessage(fragments, reply);
string voiceSelected = chatterId == null ? _user.DefaultTTSVoice : GetSelectedVoiceFor(chatterId.Value);
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);
_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;
if (string.IsNullOrWhiteSpace(m))
@ -233,6 +234,13 @@ namespace TwitchChatTTS.Chat.Messaging
voiceSelected = voiceSelected[0].ToString().ToUpper() + voiceSelected.Substring(1).ToLower();
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)

View File

@ -33,16 +33,16 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
return;
}
var exists = _groups.Get(groupId);
if (exists == null)
var group = _groups.Get(groupId);
if (group == null)
{
_logger.Warning($"Group id does not exist [group id: {exists}]");
_logger.Warning($"Group id does not exist [group id: {group}]");
return;
}
_logger.Debug($"Removing group [group id: {exists.Id}][group name: {exists.Name}][group priority: {exists.Priority}]");
_groups.Remove(exists.Id);
_logger.Information($"Group has been updated [group id: {exists.Id}]");
_logger.Debug($"Removing group [group id: {group.Id}][group name: {group.Name}][group priority: {group.Priority}]");
_groups.Remove(group.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);
foreach (var group in groupInfo.Groups)
{
_logger.Debug($"Adding group [group id: {group.Id}][name: {group.Name}][priority: {group.Priority}]");
_groups.Add(group);
}
foreach (var permission in groupInfo.GroupPermissions)
{

View File

@ -70,6 +70,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
}
string permission = GetPermissionPath(message.ChannelPointsCustomRewardId, bits);
_logger.Information(chatterId + " / " + permission + " / groups: " + string.Join(" | ", groups));
if (!HasPermission(chatterId, groups, permission))
{
_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)
{
return chatterId == _user.OwnerId ? true : _permissionManager.CheckIfAllowed(groups, permissionPath) == true;
return chatterId == _user.OwnerId || _permissionManager.CheckIfAllowed(groups, permissionPath) == true;
}
}
}