Well to post to Lemmy from Mastodon, the Mastodon user has to tag the community. That tag displays as a link on the Lemmy side. The Mastodon user has no control over the format of said link, as it’s a Mastodon user tag. So your bot shouldn’t be trying to correct it at all in this case.