Skip to content
Open
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
20 changes: 19 additions & 1 deletion Cogs/Profile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio, discord, time, shutil, os, tempfile, json
import re
from operator import itemgetter
from discord.ext import commands
from Cogs import Utils, Settings, ReadableTime, DisplayName, Message, Nullify, PickList, DL
Expand Down Expand Up @@ -112,11 +113,28 @@ async def _get_profile_reply(self,ctx,name=None,raw=False):
if item is None:
# Just got a member - list their profiles
return await self._list_profiles(ctx,member.id)
def _format_codeblock(contents=""):
return "```markdown\n{}\n```".format(contents.replace("```", "`\uFEFF`\uFEFF`"))
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}|-#|-\s*|>(>>)?) ")
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
msg = '*{}\'s {}{} Profile:*\n\n{}'.format(
DisplayName.name(member),
"Raw " if raw else "",
Nullify.escape_all(item['Name']),
discord.utils.escape_markdown(item['URL']) if raw else item['URL']
_format_raw(item['URL']) if raw else item['URL']
)
return await ctx.send(Utils.suppressed(ctx,msg))

Expand Down