Skip to content

Commit

Permalink
DiscordChatExporterPy 2.4 (#69)
Browse files Browse the repository at this point in the history
* Fix: Pins and Threads type name

* Switching entry build class to function & minor reference improvement

* Message containers, message highlighting, side-timestamp

* Reference symbol

* Fix class typo and HTML escaping

* README update

* Solved 'NoneType' object has no attribute 'html'

* CSS tidy up, pin and thread message template fix

* __version__ and Discord import order

* README update

* Solve Nextcord Embed.Empty change

* Template/CSS changes

* README and screenshots update

* Welcome channel font weight change

* Updated styling, added unix timestamp parse, added member since&id and more

Co-authored-by: mahtoid <[email protected]>
  • Loading branch information
mahtoid and mahtoid authored Oct 10, 2022
1 parent 04815c8 commit feead20
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 78 deletions.
2 changes: 1 addition & 1 deletion chat_exporter/construct/assets/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


def _gather_checker():
if hasattr(discord.Embed, "Empty") and discord.module != "nextcord":
if hasattr(discord.Embed, "Empty") and (discord.module != "nextcord" or discord.__version__ < 2.2):
return discord.Embed.Empty
return None

Expand Down
14 changes: 11 additions & 3 deletions chat_exporter/construct/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def __init__(
self.military_time = military_time
self.guild = guild

self.time_format = "%A, %d %B %Y at %I:%M %p"
self.time_format = "%A, %e %B %Y %I:%M %p"
if self.military_time:
self.time_format = "%A, %d %B %Y at %H:%M"
self.time_format = "%A, %e %B %Y %H:%M"

self.message_created_at, self.message_edited_at = self.set_time()
self.meta_data = meta_data
Expand Down Expand Up @@ -106,7 +106,15 @@ async def build_meta_data(self):
self.message.author.display_avatar if self.message.author.display_avatar
else DiscordUtils.default_avatar
)
self.meta_data[user_id] = [user_name_discriminator, user_created_at, user_bot, user_avatar, 1]
user_joined_at = self.message.author.joined_at
user_display_name = (
f'<div class="meta__display-name">{self.message.author.display_name}</div>'
if self.message.author.display_name != self.message.author.name
else ""
)
self.meta_data[user_id] = [
user_name_discriminator, user_created_at, user_bot, user_avatar, 1, user_joined_at, user_display_name
]

async def build_content(self):
if not self.message.content:
Expand Down
39 changes: 33 additions & 6 deletions chat_exporter/construct/transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
from chat_exporter.ext.cache import clear_cache
from chat_exporter.parse.mention import pass_bot
from chat_exporter.ext.discord_utils import DiscordUtils
from chat_exporter.ext.html_generator import fill_out, total, meta_data_temp, fancy_time, PARSE_MODE_NONE
from chat_exporter.ext.html_generator import (
fill_out, total, channel_topic, meta_data_temp, fancy_time, channel_subject, PARSE_MODE_NONE
)


class TranscriptDAO:
Expand All @@ -39,6 +41,9 @@ def __init__(
self.support_dev = support_dev
self.pytz_timezone = pytz_timezone

# This is to pass timezone in to mention.py without rewriting
setattr(discord.Guild, "timezone", self.pytz_timezone)

if bot:
pass_bot(bot)

Expand Down Expand Up @@ -66,21 +71,43 @@ async def export_transcript(self, message_html: str, meta_data: str):

meta_data_html: str = ""
for data in meta_data:
creation_time = meta_data[int(data)][1].astimezone(timezone).strftime("%d/%m/%y @ %T")
creation_time = meta_data[int(data)][1].astimezone(timezone).strftime("%b %d, %Y")
joined_time = meta_data[int(data)][5].astimezone(timezone).strftime("%b %d, %Y")

meta_data_html += await fill_out(self.channel.guild, meta_data_temp, [
("USER_ID", str(data), PARSE_MODE_NONE),
("USERNAME", str(meta_data[int(data)][0][:-5]), PARSE_MODE_NONE),
("DISCRIMINATOR", str(meta_data[int(data)][0][-5:])),
("BOT", str(meta_data[int(data)][2]), PARSE_MODE_NONE),
("CREATED_AT", str(creation_time), PARSE_MODE_NONE),
("JOINED_AT", str(joined_time), PARSE_MODE_NONE),
("GUILD_ICON", str(guild_icon), PARSE_MODE_NONE),
("DISCORD_ICON", str(DiscordUtils.logo), PARSE_MODE_NONE),
("MEMBER_ID", str(data), PARSE_MODE_NONE),
("USER_AVATAR", str(meta_data[int(data)][3]), PARSE_MODE_NONE),
("DISPLAY", str(meta_data[int(data)][6]), PARSE_MODE_NONE),
("MESSAGE_COUNT", str(meta_data[int(data)][4]))
])

channel_creation_time = self.channel.created_at.astimezone(timezone).strftime("%d/%m/%y @ %T")
channel_creation_time = self.channel.created_at.astimezone(timezone).strftime("%b %d, %Y (%T)")

raw_channel_topic = self.channel.topic if self.channel.topic else ""

channel_topic_html = ""
if raw_channel_topic:
channel_topic_html = await fill_out(self.channel.guild, channel_topic, [
("CHANNEL_TOPIC", raw_channel_topic)
])

limit = "start"
if self.limit:
limit = f"latest {self.limit} messages"

channel_topic = f'<span class="panel__channel-topic">{self.channel.topic}</span>' if self.channel.topic else ""
subject = await fill_out(self.channel.guild, channel_subject, [
("LIMIT", limit, PARSE_MODE_NONE),
("CHANNEL_NAME", self.channel.name),
("RAW_CHANNEL_TOPIC", str(raw_channel_topic))
])

sd = (
'<div class="meta__support">'
Expand All @@ -102,10 +129,10 @@ async def export_transcript(self, message_html: str, meta_data: str):
("MESSAGE_COUNT", str(len(self.messages))),
("MESSAGES", message_html, PARSE_MODE_NONE),
("META_DATA", meta_data_html, PARSE_MODE_NONE),
("TIMEZONE", str(self.pytz_timezone)),
("DATE_TIME", str(time_now)),
("SUBJECT", subject, PARSE_MODE_NONE),
("CHANNEL_CREATED_AT", str(channel_creation_time), PARSE_MODE_NONE),
("CHANNEL_TOPIC", str(channel_topic), PARSE_MODE_NONE),
("CHANNEL_TOPIC", str(channel_topic_html), PARSE_MODE_NONE),
("CHANNEL_ID", str(self.channel.id), PARSE_MODE_NONE),
("MESSAGE_PARTICIPANTS", str(len(meta_data)), PARSE_MODE_NONE),
("FANCY_TIME", _fancy_time, PARSE_MODE_NONE),
Expand Down
1 change: 1 addition & 0 deletions chat_exporter/ext/discord_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class DiscordUtils:
logo: str = 'https://cdn.jsdelivr.net/gh/mahtoid/DiscordUtils@master/discord-logo.svg'
default_avatar: str = 'https://cdn.jsdelivr.net/gh/mahtoid/DiscordUtils@master/discord-default.png'
pinned_message_icon: str = 'https://cdn.jsdelivr.net/gh/mahtoid/DiscordUtils@master/discord-pinned.svg'
thread_channel_icon: str = 'https://cdn.jsdelivr.net/gh/mahtoid/DiscordUtils@master/discord-thread.svg'
Expand Down
4 changes: 3 additions & 1 deletion chat_exporter/ext/html_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def fill_out(guild, base, replacements):
k, v, mode = r

if mode != PARSE_MODE_NONE:
v = ParseMention(v, guild).flow()
v = await ParseMention(v, guild).flow()
if mode == PARSE_MODE_MARKDOWN:
v = await ParseMarkdown(v).standard_message_flow()
elif mode == PARSE_MODE_EMBED:
Expand Down Expand Up @@ -92,3 +92,5 @@ def read_file(filename):

# SCRIPT
fancy_time = read_file(dir_path + "/html/script/fancy_time.html")
channel_topic = read_file(dir_path + "/html/script/channel_topic.html")
channel_subject = read_file(dir_path + "/html/script/channel_subject.html")
Loading

0 comments on commit feead20

Please sign in to comment.