Apply TTS skips from message deletion & bans when merging with other chats. Fixed group permissions.

This commit is contained in:
Tom 2024-08-06 22:50:45 +00:00
parent 8a0e55bb95
commit ed68cc47e6
3 changed files with 49 additions and 19 deletions

View File

@ -69,7 +69,7 @@ namespace TwitchChatTTS.Chat.Commands
// Check if command can be executed by this chatter.
var command = selectorResult.Command;
long chatterId = long.Parse(message.ChatterUserId);
//if (chatterId != _user.OwnerId)
if (chatterId != _user.OwnerId)
{
bool executable = command.AcceptCustomPermission ? CanExecute(chatterId, groups, $"tts.commands.{com}", selectorResult.Permissions) : false;
if (!executable)

View File

@ -214,8 +214,27 @@ namespace TwitchChatTTS.Chat.Commands
return;
}
await _client.CreateEventSubscription("channel.chat.message", "1", _twitch.SessionId, _user.TwitchUserId.ToString(), fragment.Mention!.UserId);
_logger.Information($"Joined chat room [channel: {fragment.Mention.UserLogin}][channel id: {fragment.Mention.UserId}][invoker: {message.ChatterUserLogin}][id: {message.ChatterUserId}]");
string targetUserId = fragment.Mention!.UserId!;
if (targetUserId == _user.TwitchUserId.ToString())
{
_logger.Warning("Cannot join yourself.");
return;
}
string[] subscriptions = ["channel.chat.message", "channel.chat.message_delete", "channel.chat.clear_user_messages"];
foreach (var subscription in subscriptions)
{
_logger.Debug($"Attempting to subscribe to Twitch events [subscription: {subscription}]");
var data = await _client.CreateEventSubscription(subscription, "1", _twitch.SessionId, _user.TwitchUserId.ToString(), targetUserId);
var info = data?.Data?.FirstOrDefault();
if (info == null)
{
_logger.Warning("Could not find the subscription id.");
continue;
}
_twitch.AddSubscription(targetUserId, subscription, info.Id);
}
_logger.Information($"Joined chat room [channel: {fragment.Mention.UserLogin}][channel id: {targetUserId}][invoker: {message.ChatterUserLogin}][id: {message.ChatterUserId}]");
}
}
@ -251,22 +270,33 @@ namespace TwitchChatTTS.Chat.Commands
return;
}
var subscriptionId = _twitch.GetSubscriptionId(_user.TwitchUserId.ToString(), "channel.chat.message");
if (subscriptionId == null)
string targetUserId = fragment.Mention!.UserId!;
if (targetUserId == _user.TwitchUserId.ToString())
{
_logger.Warning("Cannot find the subscription for that channel.");
_logger.Warning("Cannot join yourself.");
return;
}
try
string[] subscriptions = ["channel.chat.message", "channel.chat.message_delete", "channel.chat.clear_user_messages"];
foreach (var subscription in subscriptions)
{
await _client.DeleteEventSubscription(subscriptionId);
_twitch.RemoveSubscription(fragment.Mention.UserId, "channel.chat.message");
_logger.Information($"Joined chat room [channel: {fragment.Mention.UserLogin}][channel id: {fragment.Mention.UserId}][invoker: {message.ChatterUserLogin}][id: {message.ChatterUserId}]");
}
catch (Exception ex)
{
_logger.Error(ex, "Failed to delete the subscription from Twitch.");
var subscriptionId = _twitch.GetSubscriptionId(targetUserId, subscription);
if (subscriptionId == null)
{
_logger.Warning($"Cannot find the subscription for that channel [subscription: {subscription}]");
continue;
}
try
{
await _client.DeleteEventSubscription(subscriptionId);
_twitch.RemoveSubscription(targetUserId, subscription);
_logger.Information($"Left chat room [channel: {fragment.Mention.UserLogin}][channel id: {targetUserId}][invoker: {message.ChatterUserLogin}][id: {message.ChatterUserId}]");
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to delete the subscription from Twitch [subscription: {subscription}][subscription id: {subscriptionId}]");
}
}
}
}

View File

@ -36,16 +36,16 @@ namespace TwitchChatTTS.Chat.Groups.Permissions
public bool? CheckIfAllowed(IEnumerable<string> groups, string path)
{
bool overall = true;
bool overall = false;
foreach (var group in groups)
{
var result = CheckIfAllowed($"{group}.{path}");
if (result == true)
return true;
if (result == false)
overall = false;
return false;
if (result == true)
overall = true;
}
return overall ? null : false;
return overall ? true : null;
}
public bool? CheckIfDirectAllowed(IEnumerable<string> groups, string path)