Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions general-helpers/message-caching/messageCaching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ private static async Task<CachedMessageInfo> DownloadAndCacheAsync(
IMessageChannel channel,
ulong messageId)
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(15));

try
{
if (await channel.GetMessageAsync(messageId, options: new RequestOptions { CancelToken = cts.Token }) is not IUserMessage msg)
if (await channel.GetMessageAsync(messageId, options: new RequestOptions { CancelToken = cts.Token, RetryMode = RetryMode.RetryRatelimit}) is not IUserMessage msg)
return null;

if (msg.Flags.HasValue &&
Expand Down
31 changes: 14 additions & 17 deletions main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,23 +493,6 @@ private static Task HandleReactionAddedAsync(
return;
}

var botUser = textChannel.GetUser(Client.CurrentUser.Id);

if (botUser == null || !botUser.GetPermissions(textChannel).ReadMessageHistory)
{
return;
}

var userMessage = await CachedMessages.GetOrDownloadAsync(textChannel, cacheable.Id);
if (userMessage == null)
{
return;
}

string key = reaction.Emote is Emote emote ? emote.Id.ToString() : reaction.Emote.Name;

userMessage.IncreaseReactionCount(key);

using var scope = Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<BobEntities>();
var server = await dbContext.GetOrCreateServerAsync(textChannel.Guild.Id);
Expand All @@ -519,6 +502,7 @@ private static Task HandleReactionAddedAsync(
return;
}

string key = reaction.Emote is Emote emote ? emote.Id.ToString() : reaction.Emote.Name;
var storedEmojiId = ReactBoardMethods.GetEmojiIdFromString(server.ReactBoardEmoji);

bool isMatchingEmoji = (storedEmojiId != null && key == storedEmojiId)
Expand All @@ -529,6 +513,19 @@ private static Task HandleReactionAddedAsync(
return;
}

var botUser = textChannel.GetUser(Client.CurrentUser.Id);
if (botUser == null || !botUser.GetPermissions(textChannel).ReadMessageHistory)
{
return;
}

var userMessage = await CachedMessages.GetOrDownloadAsync(textChannel, cacheable.Id);
if (userMessage == null)
{
return;
}

userMessage.IncreaseReactionCount(key);
var reactionCount = userMessage.GetReactionCount(key);

if (reactionCount == 0 || reactionCount < server.ReactBoardMinimumReactions)
Expand Down
Loading