fix(wormhole): resolve reply button to local copy, not original server

The forward map only stores relay targets — the source channel (where
the original message was typed) was never included. When someone in
Server B replied to a relayed message, the button for Server A fell
back to the fallback URL pointing at Server B instead of Server A.

Fix: after building the relay-target URLs, identify the source channel
by finding network channels not present in the forward map, and map
them to the original message ID.
This commit is contained in:
Viktor 2026-05-14 15:23:27 +00:00
parent 2a14a08801
commit 2acee87123

View file

@ -4238,10 +4238,22 @@ class Wormhole(commands.Cog):
if orig_ref_id
else self.msg_map.forward.get(net_name, {}).get(ref.id, {})
)
# Map each relay-target channel to its local copy
for cid, mid in ref_relayed.items():
target_ch = self.bot.get_channel(cid)
if target_ch and target_ch.guild:
reply_jump_urls[cid] = f"https://discord.com/channels/{target_ch.guild.id}/{cid}/{mid}"
# Map the source channel (where the original was typed).
# The forward map only stores relay targets — the source
# channel is whichever network channel is NOT in the map.
if orig_ref_id:
# ref was a relayed copy — find the original's channel
relayed_ch_ids = set(ref_relayed.keys())
for net_ch_id in nd.get("channels", []):
if net_ch_id not in relayed_ch_ids and net_ch_id not in reply_jump_urls:
net_ch = self.bot.get_channel(net_ch_id)
if net_ch and net_ch.guild:
reply_jump_urls[net_ch_id] = f"https://discord.com/channels/{net_ch.guild.id}/{net_ch_id}/{orig_ref_id}"
# Include the channel where the ref message lives
reply_jump_urls.setdefault(ref.channel.id, reply_fallback_url)
except: content = f"> ↩ *[reply]*\n{content}"