Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions chat_exporter/construct/assets/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async def build_menu_options(self, options):
option_emoji = self._stringify_emoji(self._get_attr(option, "emoji", None))
is_default = bool(self._get_attr(option, "default", False))
default_class = "dropdownContentSelected" if is_default else ""
check_mark = "" if is_default else ""
check_mark = "✓" if is_default else ""

label_escaped = html.escape(str(label)) if label else ""
description_escaped = html.escape(str(description)) if description else ""
Expand Down Expand Up @@ -551,7 +551,7 @@ def _build_media_properties(self, media, description, spoiler, css_class_prefix=
if not spoiler and description:
description_overlay = (
f'<div class="chatlog__component-{css_class_prefix}-description">'
f'{{html.escape(str(description))}}</div>'
f'{html.escape(str(description))}</div>'
)

return {
Expand Down
5 changes: 4 additions & 1 deletion chat_exporter/construct/attachment_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def process_asset(self, attachment: discord.Attachment) -> discord.Attachm
:param attachment: discord.Attachment
:return: str
"""
file_name = urllib.parse.quote_plus(f"{datetime.datetime.utcnow().timestamp()}_{attachment.filename}")
file_name = urllib.parse.quote_plus(f"{datetime.datetime.now(datetime.timezone.utc).timestamp()}_{attachment.filename}")
asset_path = self.base_path / file_name
await attachment.save(asset_path)
file_url = f"{self.url_base}/{file_name}"
Expand Down Expand Up @@ -85,6 +85,7 @@ async def process_asset(self, attachment: discord.Attachment) -> discord.Attachm
"""Implement this to process the asset and return a url to the stored attachment.
:param attachment: discord.Attachment
:return: str"""
message = None
try:
if attachment.size > self.size_limit:
file = discord.File(self.placeholder_path, filename="too_large.png")
Expand All @@ -105,4 +106,6 @@ async def process_asset(self, attachment: discord.Attachment) -> discord.Attachm
# discords http errors, including missing permissions
raise e
else:
if message is None:
raise aiohttp.ClientConnectionError("Webhook connection failed after 3 retries.")
return message.attachments[0]
9 changes: 6 additions & 3 deletions chat_exporter/construct/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def get_interaction_status(interaction_message):
message_edited_at = _set_edit_at(message_edited_at)

avatar_url = message.author.display_avatar if message.author.display_avatar else DiscordUtils.default_avatar
reference_content = message.content.replace("\r\n", "\n").replace("\r", "\n")
reference_content = reference_content.replace("\n", " ").replace("<br>", " ")
self.message.reference = await fill_out(
self.guild,
message_reference,
Expand All @@ -279,7 +281,7 @@ def get_interaction_status(interaction_message):
("NAME_TAG", await discriminator(message.author.name, message.author.discriminator), PARSE_MODE_NONE),
("NAME", str(html.escape(message.author.display_name))),
("USER_COLOUR", user_colour, PARSE_MODE_NONE),
("CONTENT", message.content.replace("\n", "").replace("<br>", ""), PARSE_MODE_REFERENCE),
("CONTENT", reference_content, PARSE_MODE_REFERENCE),
("EDIT", message_edited_at, PARSE_MODE_NONE),
("ICON", icon, PARSE_MODE_NONE),
("USER_ID", str(message.author.id), PARSE_MODE_NONE),
Expand Down Expand Up @@ -351,14 +353,15 @@ async def build_sticker(self):
f"https://cdn.jsdelivr.net/gh/mahtoid/DiscordUtils@master/stickers/{sticker.pack_id}/{sticker.id}.gif"
)

self.rendered_content = await fill_out(
sticker_html = await fill_out(
self.guild,
img_attachment,
[
("ATTACH_URL", str(sticker_image_url), PARSE_MODE_NONE),
("ATTACH_URL_THUMB", str(sticker_image_url), PARSE_MODE_NONE),
],
)
self.rendered_content += sticker_html

@staticmethod
def calculate_grid_splits(n):
Expand Down Expand Up @@ -687,7 +690,7 @@ def set_time(self, message: Optional[discord.Message] = None):
return created_at_str, edited_at_str

def to_local_time_str(self, time):
if not self.message.created_at.tzinfo:
if not time.tzinfo:
time = timezone("UTC").localize(time)

local_time = time.astimezone(timezone(self.pytz_timezone))
Expand Down
2 changes: 1 addition & 1 deletion chat_exporter/construct/transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def build_transcript(self):
async def export_transcript(self, message_html: str, meta_data: str):
guild_icon = (
self.channel.guild.icon
if (self.channel.guild.icon and len(self.channel.guild.icon) > 2)
if self.channel.guild.icon
else DiscordUtils.default_avatar
)

Expand Down
2 changes: 1 addition & 1 deletion chat_exporter/ext/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def wrapper(*args, **kwargs):
return _wrap_new_coroutine(value)

wrapper.cache = _internal_cache
wrapper.clear_cache = _internal_cache.clear()
wrapper.clear_cache = _internal_cache.clear
return wrapper

return decorator
9 changes: 3 additions & 6 deletions chat_exporter/parse/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List

import pytz
import html


class Node:
Expand Down Expand Up @@ -184,11 +185,7 @@ def render(self, guild=None, bot=None):

if member:
member_name = member.display_name
escaped_name = (
member_name.replace("<", self.ESCAPE_LT)
.replace(">", self.ESCAPE_GT)
.replace("&", self.ESCAPE_AMP)
)
escaped_name = html.escape(member_name)
return f'<span class="mention" title="{self.user_id}">@{escaped_name}</span>'
else:
return f'<span class="mention" title="{self.user_id}">&lt;@{self.user_id}&gt;</span>'
Expand Down Expand Up @@ -236,7 +233,7 @@ def __init__(self, timestamp: int, format_str: str, original: str):
self.original = original

def render(self, guild=None, bot=None):
timestamp = self.timestamp - 1
timestamp = self.timestamp
try:
time_stamp = time.gmtime(timestamp)
datetime_stamp = datetime.datetime(2010, *time_stamp[1:6], tzinfo=pytz.utc)
Expand Down