Skip to content

Commit ee417f9

Browse files
committed
Apply feedback
1 parent 78455ea commit ee417f9

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/Modix.Bot/Responders/StarboardReactionResponder.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,37 @@ public Task Handle(ReactionAddedNotificationV3 notification, CancellationToken c
2121
public Task Handle(ReactionRemovedNotificationV3 notification, CancellationToken cancellationToken)
2222
=> HandleReactionAsync(notification.Message, notification.Reaction);
2323

24+
private async ValueTask<bool> IsChannelIgnoredFromStarboard(IGuildChannel channel)
25+
{
26+
if (channel.ChannelType == ChannelType.PrivateThread)
27+
{
28+
return true;
29+
}
30+
31+
var hasDirectDesignation = await designatedChannelService
32+
.ChannelHasDesignation(channel.Guild.Id, channel.Id, DesignatedChannelType.IgnoredFromStarboard, default);
33+
34+
if (hasDirectDesignation)
35+
{
36+
return true;
37+
}
38+
39+
if (channel is SocketThreadChannel { ParentChannel: not null } threadChannel)
40+
{
41+
var parentChannelId = threadChannel.ParentChannel.Id;
42+
43+
var parentHasDesignation = await designatedChannelService
44+
.ChannelHasDesignation(channel.Guild.Id, parentChannelId, DesignatedChannelType.IgnoredFromStarboard, default);
45+
46+
if (parentHasDesignation)
47+
{
48+
return true;
49+
}
50+
}
51+
52+
return false;
53+
}
54+
2455
private async Task HandleReactionAsync(Cacheable<IUserMessage, ulong> cachedMessage, IReaction reaction)
2556
{
2657
var emote = reaction.Emote;
@@ -35,21 +66,15 @@ private async Task HandleReactionAsync(Cacheable<IUserMessage, ulong> cachedMess
3566
return;
3667
}
3768

38-
if (channel.ChannelType == ChannelType.PrivateThread)
69+
if (await IsChannelIgnoredFromStarboard(channel))
3970
{
4071
return;
4172
}
4273

43-
var isIgnoredFromStarboard = await designatedChannelService
44-
.ChannelHasDesignation(channel.Guild.Id, channel.Id, DesignatedChannelType.IgnoredFromStarboard, default);
45-
46-
var isParentIgnoredFromStarboard = channel is SocketThreadChannel { ParentChannel: not null } threadChannel && await designatedChannelService
47-
.ChannelHasDesignation(channel.Guild.Id, threadChannel.ParentChannel.Id, DesignatedChannelType.IgnoredFromStarboard, default);
48-
4974
var starboardExists = await designatedChannelService
5075
.HasDesignatedChannelForType(channel.GuildId, DesignatedChannelType.Starboard);
5176

52-
if (isIgnoredFromStarboard || isParentIgnoredFromStarboard || !starboardExists)
77+
if (!starboardExists)
5378
{
5479
return;
5580
}

0 commit comments

Comments
 (0)