Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple emoteboard bug fixes #861

Merged
merged 3 commits into from
Nov 15, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ public async Task<QueryResult<List<LeaderboardSlot>>> Handle(Query request, Canc
}
}

var posts = await _context.EmoteBoardPosts
var reactions = await _context.EmoteBoardPosts
.Where(p => board != null ? p.EmoteBoardId == board.Id : p.EmoteBoard.GuildId == request.GuildId)
.Include(p => p.Reactions)
.GroupBy(p => p.UserId)
.Select(group => new LeaderboardSlot
{
UserId = group.Key,
ReactionCount = group.Select(p => p.Reactions).Count()
ReactionCount = group.Select(p => p.Reactions.Count).Sum()
})
.OrderByDescending(slot => slot.ReactionCount)
.Take(request.Limit)
.ToListAsync();

return QueryResult<List<LeaderboardSlot>>.Success(posts);
return QueryResult<List<LeaderboardSlot>>.Success(reactions);
}
}
}
4 changes: 4 additions & 0 deletions ClemBot.Bot/bot/clem_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,14 @@ async def on_raw_message_edit(self, payload: discord.RawMessageUpdateEvent) -> N
await self.publish_with_error(Events.on_raw_message_edit, payload)

async def on_message_delete(self, message: discord.Message) -> None:
if not message.guild:
return
if message.author.id != self.user.id:
await self.publish_with_error(Events.on_message_delete, message)

async def on_raw_message_delete(self, payload: discord.RawMessageDeleteEvent) -> None:
if not payload.guild_id:
return
await self.publish_with_error(Events.on_raw_message_delete, payload)

async def on_after_command_invoke(self, ctx: ext.ClemBotContext["ClemBot"]) -> None:
Expand Down
11 changes: 7 additions & 4 deletions ClemBot.Bot/bot/services/emote_board_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def on_message_edit(self, event: RawMessageUpdateEvent) -> None:

posts = await self.bot.emote_board_route.get_posts(event.guild_id, event.message_id)

post_boards = {}
post_boards: list[tuple[EmoteBoardPost, EmoteBoard]] = []

for post in posts:
board = await self.bot.emote_board_route.get_emote_board(
Expand All @@ -131,9 +131,9 @@ async def on_message_edit(self, event: RawMessageUpdateEvent) -> None:
board=post.name,
)
continue
post_boards[post] = board
post_boards.append((post, board))

for post, board in post_boards.items():
for post, emote_board in post_boards:
for channel_id, message_id in post.channel_message_ids.items():
try:
if not (channel := guild.get_channel_or_thread(channel_id)):
Expand All @@ -142,7 +142,10 @@ async def on_message_edit(self, event: RawMessageUpdateEvent) -> None:
assert isinstance(channel, discord.abc.Messageable)
embed_msg = await channel.fetch_message(message_id)
embed = await self._as_embed(
message, board.reaction_threshold, len(post.reactions), board.emote
message,
emote_board.reaction_threshold,
len(post.reactions),
emote_board.emote,
)
await embed_msg.edit(embed=embed)
except NotFound: # Skips over the item if fetch_message() raises `NotFound`
Expand Down
4 changes: 4 additions & 0 deletions ClemBot.Bot/bot/services/message_handling_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ async def on_message_edit(self, before: discord.Message, after: discord.Message)
# noinspection PyArgumentList
@BaseService.listener(Events.on_raw_message_edit)
async def on_raw_message_edit(self, payload: discord.RawMessageUpdateEvent) -> None:
# ignore any cached messages - this will be handled by on_message_edit instead
if payload.cached_message:
return

message = await self.bot.message_route.get_message(payload.message_id)
channel = self.bot.get_channel(payload.channel_id)

Expand Down
Loading