Skip to content

Commit 078982d

Browse files
Merge pull request #1046 from hamarb123/main
Add handling of threads to starboard
2 parents b517765 + 649d9e2 commit 078982d

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/Modix.Bot/Responders/StarboardReactionResponder.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Threading;
22
using System.Threading.Tasks;
33
using Discord;
4+
using Discord.WebSocket;
45
using MediatR;
56
using Modix.Bot.Notifications;
67
using Modix.Bot.Responders.MessageQuotes;
@@ -20,6 +21,37 @@ public Task Handle(ReactionAddedNotificationV3 notification, CancellationToken c
2021
public Task Handle(ReactionRemovedNotificationV3 notification, CancellationToken cancellationToken)
2122
=> HandleReactionAsync(notification.Message, notification.Reaction);
2223

24+
private async ValueTask<bool> IsChannelIgnoredFromStarboard(IGuildChannel channel)
25+
{
26+
if (channel.ChannelType is 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+
2355
private async Task HandleReactionAsync(Cacheable<IUserMessage, ulong> cachedMessage, IReaction reaction)
2456
{
2557
var emote = reaction.Emote;
@@ -34,13 +66,15 @@ private async Task HandleReactionAsync(Cacheable<IUserMessage, ulong> cachedMess
3466
return;
3567
}
3668

37-
var isIgnoredFromStarboard = await designatedChannelService
38-
.ChannelHasDesignation(channel.Guild.Id, channel.Id, DesignatedChannelType.IgnoredFromStarboard, default);
69+
if (await IsChannelIgnoredFromStarboard(channel))
70+
{
71+
return;
72+
}
3973

4074
var starboardExists = await designatedChannelService
4175
.HasDesignatedChannelForType(channel.GuildId, DesignatedChannelType.Starboard);
4276

43-
if (isIgnoredFromStarboard || !starboardExists)
77+
if (!starboardExists)
4478
{
4579
return;
4680
}

0 commit comments

Comments
 (0)