Skip to content

Commit

Permalink
Fix CSS/JS Issues + QOL Improvements (#108)
Browse files Browse the repository at this point in the history
* Versioning

* Fix discord import for wrapper namespaces != discord (#104)

* Versioning

* Fix quick_export() Missing Argument

* Remove Use of 'proxy_url' due to Discord's CDN Changes

* Fix Embed Colour & Reduce Unnecessary Gaps

* Fix Emoji Mis-Alignment

* Fix Button Label Padding

* Equalise Footer Width

* Fix User Pop-Out

* Add Hover on User Avatars

* Fix Scrolling to Messages

* Open Buttons & Images in New Tabs + Fix Audio Container

* Change BOT Tag to New APP Tag

* Update README

* Add .vscode to Git-Ignore

* Update README.md for my Fork

* Update README.md

* Revert README Installation Changes

* Revert Asset URL Change back to Proxy URL

* Fixed Message Aside Timestamp

* Update chat_exporter/construct/assets/component.py

Co-authored-by: Lukas Dobler <[email protected]>

* Update chat_exporter/construct/assets/component.py

Co-authored-by: Lukas Dobler <[email protected]>

* Update chat_exporter/construct/assets/component.py

Co-authored-by: Lukas Dobler <[email protected]>

* Update chat_exporter/construct/assets/component.py

Co-authored-by: Lukas Dobler <[email protected]>

* Update chat_exporter/construct/assets/component.py

Co-authored-by: Lukas Dobler <[email protected]>

* Update chat_exporter/html/component/component_button.html

Co-authored-by: Lukas Dobler <[email protected]>

* Update chat_exporter/html/base.html

Co-authored-by: Lukas Dobler <[email protected]>

* Update chat_exporter/construct/assets/component.py

Co-authored-by: Lukas Dobler <[email protected]>

* Update chat_exporter/construct/message.py

Co-authored-by: Lukas Dobler <[email protected]>

* Refactoring

* Fixed Military Times

---------

Co-authored-by: mahtoid <[email protected]>
Co-authored-by: Lukas Dobler <[email protected]>
  • Loading branch information
3 people authored May 20, 2024
1 parent 84b4af3 commit acff601
Show file tree
Hide file tree
Showing 25 changed files with 168 additions and 191 deletions.
109 changes: 35 additions & 74 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
Expand Down Expand Up @@ -50,6 +49,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
Expand All @@ -72,6 +72,7 @@ instance/
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
Expand All @@ -82,7 +83,9 @@ profile_default/
ipython_config.py

# pyenv
.python-version
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand All @@ -91,7 +94,22 @@ ipython_config.py
# install all needed dependencies.
#Pipfile.lock

# pyflow
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
Expand All @@ -102,7 +120,6 @@ celerybeat.pid
*.sage.py

# Environments
.idea
.env
.venv
env/
Expand All @@ -129,77 +146,21 @@ dmypy.json
# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# VSCode
.vscode/

# Project specific ignores
bot.py
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ from discord import Attachment


class MyAttachmentHandler(AttachmentHandler):
def __init__(self, *args, **kwargs):
# Your initialization code here
# in your case we just create the cloud client
self.cloud_client = CloudClient()

async def process_asset(self, attachment: Attachment):
# Your upload logic here, in our example we just upload the asset to the cloud

Expand All @@ -258,14 +263,14 @@ class MyAttachmentHandler(AttachmentHandler):
# now we can generate the asset url from the identifier
asset_url = await self.cloud_client.get_share_url(asset_id, shared_with="everyone")

# and set the url attribute of the attachment to the generated url
attachment.url = asset_url
# and set the proxy url attribute of the attachment to the generated url
attachment.proxy_url = asset_url
return attachment

```

Note
1. The `process_asset` method should return the attachment object with the url attribute set to the generated url.
1. The `process_asset` method should return the attachment object with the proxy_url attribute set to the generated url.
2. The `process_asset` method should be an async method, as it is likely that you have to do some async operations
like fetching the content of the attachment or uploading it to the cloud.
3. You are free to add other methods in your class, and call them from `process_asset` if you need to do some
Expand Down
1 change: 1 addition & 0 deletions chat_exporter/chat_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def quick_export(
after=None,
support_dev=True,
bot=bot,
attachment_handler=None
).export()
).html

Expand Down
6 changes: 3 additions & 3 deletions chat_exporter/construct/assets/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def audio(self):

self.attachments = await fill_out(self.guild, audio_attachment, [
("ATTACH_ICON", file_icon, PARSE_MODE_NONE),
("ATTACH_URL", self.attachments.url, PARSE_MODE_NONE),
("ATTACH_URL", self.attachments.proxy_url, PARSE_MODE_NONE),
("ATTACH_BYTES", str(file_size), PARSE_MODE_NONE),
("ATTACH_AUDIO", self.attachments.proxy_url, PARSE_MODE_NONE),
("ATTACH_FILE", str(self.attachments.filename), PARSE_MODE_NONE)
Expand All @@ -60,7 +60,7 @@ async def file(self):

self.attachments = await fill_out(self.guild, msg_attachment, [
("ATTACH_ICON", file_icon, PARSE_MODE_NONE),
("ATTACH_URL", self.attachments.url, PARSE_MODE_NONE),
("ATTACH_URL", self.attachments.proxy_url, PARSE_MODE_NONE),
("ATTACH_BYTES", str(file_size), PARSE_MODE_NONE),
("ATTACH_FILE", str(self.attachments.filename), PARSE_MODE_NONE)
])
Expand Down Expand Up @@ -88,7 +88,7 @@ async def get_file_icon(self) -> str:
"arj", "pkg", "z"
)

extension = self.attachments.url.rsplit('.', 1)[1]
extension = self.attachments.proxy_url.rsplit('.', 1)[1]
if extension in acrobat_types:
return DiscordUtils.file_attachment_acrobat
elif extension in webcode_types:
Expand Down
22 changes: 15 additions & 7 deletions chat_exporter/construct/assets/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,26 @@ async def build_component(self, c):
Component.menu_div_id += 1

async def build_button(self, c):
url = c.url if c.url else ""
label = c.label if c.label else ""
if c.url:
url = str(c.url)
target = " target='_blank'"
icon = str(DiscordUtils.button_external_link)
else:
url = "javascript:;"
target = ""
icon = ""

label = str(c.label) if c.label else ""
style = self.styles[str(c.style).split(".")[1]]
icon = DiscordUtils.button_external_link if url else ""
emoji = str(c.emoji) if c.emoji else ""

self.buttons += await fill_out(self.guild, component_button, [
("DISABLED", "chatlog__component-disabled" if c.disabled else "", PARSE_MODE_NONE),
("URL", str(url), PARSE_MODE_NONE),
("LABEL", str(label), PARSE_MODE_MARKDOWN),
("EMOJI", str(emoji), PARSE_MODE_EMOJI),
("ICON", str(icon), PARSE_MODE_NONE),
("URL", url, PARSE_MODE_NONE),
("LABEL", label, PARSE_MODE_MARKDOWN),
("EMOJI", emoji, PARSE_MODE_EMOJI),
("ICON", icon, PARSE_MODE_NONE),
("TARGET", target, PARSE_MODE_NONE),
("STYLE", style, PARSE_MODE_NONE)
])

Expand Down
10 changes: 5 additions & 5 deletions chat_exporter/construct/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ async def build_message_template(self):
("COMPONENTS", self.components, PARSE_MODE_NONE),
("EMOJI", self.reactions, PARSE_MODE_NONE),
("TIMESTAMP", self.message_created_at, PARSE_MODE_NONE),
("TIME", self.message_created_at.split()[-1], PARSE_MODE_NONE),
("TIME", self.message_created_at.split(maxsplit=4)[4], PARSE_MODE_NONE),
])

return self.message_html
Expand Down Expand Up @@ -312,7 +312,10 @@ async def generate_message_divider(self, channel_audit=False):
if not self.message.created_at.tzinfo:
time = timezone("UTC").localize(time)

default_timestamp = time.astimezone(timezone(self.pytz_timezone)).strftime("%d-%m-%Y %H:%M")
if self.military_time:
default_timestamp = time.astimezone(timezone(self.pytz_timezone)).strftime("%d-%m-%Y %H:%M")
else:
default_timestamp = time.astimezone(timezone(self.pytz_timezone)).strftime("%d-%m-%Y %I:%M %p")

self.message_html += await fill_out(self.guild, start_message, [
("REFERENCE_SYMBOL", followup_symbol, PARSE_MODE_NONE),
Expand Down Expand Up @@ -432,9 +435,6 @@ def to_local_time_str(self, time):

local_time = time.astimezone(timezone(self.pytz_timezone))

if self.military_time:
return local_time.strftime(self.time_format)

return local_time.strftime(self.time_format)


Expand Down
16 changes: 14 additions & 2 deletions chat_exporter/construct/transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ async def export_transcript(self, message_html: str, meta_data: str):
guild_name = html.escape(self.channel.guild.name)

timezone = pytz.timezone(self.pytz_timezone)
time_now = datetime.datetime.now(timezone).strftime("%e %B %Y at %T (%Z)")
if self.military_time:
time_now = datetime.datetime.now(timezone).strftime("%e %B %Y at %H:%M:%S (%Z)")
else:
time_now = datetime.datetime.now(timezone).strftime("%e %B %Y at %I:%M:%S %p (%Z)")

meta_data_html: str = ""
for data in meta_data:
Expand Down Expand Up @@ -105,7 +108,10 @@ async def export_transcript(self, message_html: str, meta_data: str):
("MESSAGE_COUNT", str(meta_data[int(data)][4]))
])

channel_creation_time = self.channel.created_at.astimezone(timezone).strftime("%b %d, %Y (%T)")
if self.military_time:
channel_creation_time = self.channel.created_at.astimezone(timezone).strftime("%b %d, %Y (%H:%M:%S)")
else:
channel_creation_time = self.channel.created_at.astimezone(timezone).strftime("%b %d, %Y (%I:%M:%S %p)")

raw_channel_topic = (
self.channel.topic if isinstance(self.channel, discord.TextChannel) and self.channel.topic else ""
Expand Down Expand Up @@ -136,7 +142,13 @@ async def export_transcript(self, message_html: str, meta_data: str):
_fancy_time = ""

if self.fancy_times:
if self.military_time:
time_format = "HH:mm"
else:
time_format = "hh:mm A"

_fancy_time = await fill_out(self.channel.guild, fancy_time, [
("TIME_FORMAT", time_format, PARSE_MODE_NONE),
("TIMEZONE", str(self.pytz_timezone), PARSE_MODE_NONE)
])

Expand Down
2 changes: 1 addition & 1 deletion chat_exporter/ext/html_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def fill_out(guild, base, replacements):
elif mode == PARSE_MODE_EMOJI:
v = await ParseMarkdown(v).special_emoji_flow()

base = base.replace("{{" + k + "}}", v)
base = base.replace("{{" + k + "}}", v.strip())

return base

Expand Down
2 changes: 1 addition & 1 deletion chat_exporter/html/attachment/audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="chatlog__attachment-filesize">
{{ATTACH_BYTES}}
</div>
<audio class="chatlog__attachment-thumbnail" style="padding-top: 5px" controls>
<audio controls>
<source src="{{ATTACH_URL}}" alt="Audio Attachment" title="{{ATTACH_FILE}}">
</audio>
</div>
Expand Down
4 changes: 3 additions & 1 deletion chat_exporter/html/attachment/image.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div class=chatlog__attachment>
<a href={{ATTACH_URL}}><img class=chatlog__attachment-thumbnail src={{ATTACH_URL_THUMB}}></a>
<a href={{ATTACH_URL}} target="_blank">
<img class=chatlog__attachment-thumbnail src={{ATTACH_URL_THUMB}}>
</a>
</div>
Loading

0 comments on commit acff601

Please sign in to comment.