Add DM support, friend identification, and target pruning
React in 1:1 DMs alongside servers/groups, surface the resolved friend username at startup and in the stats panel, verify reactions actually stick after adding them (with jump links for manual spot-checking), and prune stale targets from stats on each run so only the currently mutual set is shown.
This commit is contained in:
@@ -26,6 +26,7 @@ async def react_to_message(
|
||||
emoji: str,
|
||||
source: str,
|
||||
display: Optional[StatsDisplay] = None,
|
||||
verify: bool = True,
|
||||
) -> bool:
|
||||
if message.author.id != friend_id:
|
||||
return False
|
||||
@@ -46,6 +47,20 @@ async def react_to_message(
|
||||
log.exception("Failed to react to message %s in channel %s", message.id, message.channel.id)
|
||||
return False
|
||||
|
||||
if verify:
|
||||
try:
|
||||
refetched = await message.channel.fetch_message(message.id)
|
||||
confirmed = any(r.me and str(r.emoji) == emoji for r in refetched.reactions)
|
||||
except discord.HTTPException:
|
||||
confirmed = None # couldn't verify either way; don't block on it
|
||||
|
||||
if confirmed is False:
|
||||
log.warning(
|
||||
"Reaction API call succeeded but is NOT visible on refetch! "
|
||||
"message=%s channel=%s target=%s (%s) url=%s",
|
||||
message.id, message.channel.id, target.name, target.target_type, message.jump_url,
|
||||
)
|
||||
|
||||
inserted = await asyncio.to_thread(
|
||||
storage.record_reaction,
|
||||
message.id,
|
||||
@@ -57,7 +72,10 @@ async def react_to_message(
|
||||
message.created_at,
|
||||
)
|
||||
if inserted:
|
||||
log.info("Reacted to message %s in %s [%s] (%s)", message.id, target.name, target.target_type, source)
|
||||
log.info(
|
||||
"Reacted to message in %s [%s] (%s): %s",
|
||||
target.name, target.target_type, source, message.jump_url,
|
||||
)
|
||||
if display is not None:
|
||||
await display.refresh()
|
||||
return inserted
|
||||
|
||||
Reference in New Issue
Block a user