Skip to content

Comments

Improve the Profile.py $rawprofile Command#156

Open
Calebh101 wants to merge 3 commits intocorpnewt:rewritefrom
Calebh101:rewrite
Open

Improve the Profile.py $rawprofile Command#156
Calebh101 wants to merge 3 commits intocorpnewt:rewritefrom
Calebh101:rewrite

Conversation

@Calebh101
Copy link

@Calebh101 Calebh101 commented Jul 19, 2025

Instead of using discord.utils.escape_markdown(item['URL']) alone, which doesn't properly escape things like titles, subtitles, and many more - as seen in this example:

Screenshot from 2025-07-19 15-24-42

I've changed the message logic to use a new function that properly escapes certain effects and prefixes:

msg = '*{}\'s {}{} Profile:*\n\n{}'.format(
	DisplayName.name(member),
	"Raw " if raw else "",
	Nullify.escape_all(item['Name']),
	_format_raw(item['URL']) if raw else item['URL']
)
def _format_raw(contents=""): # Format the contents to properly display all characters without letting Discord format it.
	contents = discord.utils.escape_markdown(item['URL'])
	pattern = re.compile(r"#{1,3}|-#|[->] ")
	number_prefix_pattern = re.compile(r"\d+\. [^\n]+")
	lines = []
	for line in contents.splitlines():
		if number_prefix_pattern.search(line):
			i = line.find(".")
			if i != -1:
				line = line[:i] + "\\" + line[i:] # Escape number lists manually
		elif pattern.search(line):
			line = "\\" + line
		lines.append(line)
	contents = "\n".join(lines)
	return contents

This will format profiles like the following:

Screenshot from 2025-07-19 21-04-31 Screenshot from 2025-07-19 21-04-19 Screenshot from 2025-07-19 21-04-10

This makes it a lot easier to edit heavily-formatted profiles, or transfer profiles across servers, as previously, you would have to use Copy Text and edit out the top line (like Caleb's codeblock Profile:).

Note: _format_codeblock is included for the ability to format as a markdown code block, but it doesn't work with nested code blocks.
I have tested this with my own bot instance, but let me know if you find other issues while the PR is still pending and I can work on it!

@Calebh101 Calebh101 marked this pull request as draft July 19, 2025 21:43
@Calebh101 Calebh101 marked this pull request as draft July 19, 2025 21:43
@Calebh101 Calebh101 changed the title Show Raw Profiles as Markdown Code Block in the Profile.py $rawprofile Command Improve Showing Raw Profile Text ($rawprofile command in Profile.py) Jul 20, 2025
@Calebh101 Calebh101 marked this pull request as ready for review July 20, 2025 02:18
@Calebh101 Calebh101 changed the title Improve Showing Raw Profile Text ($rawprofile command in Profile.py) Improve the Profile.py $rawprofile Command Jul 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant