Skip to content

Commit 9dd8f04

Browse files
mahtoiddevargonmahtoiddoluk1337Syntax
authored
2.8.0 (#117)
* Fix type hinting compatibility with Python < 3.9 (#105) * Merging master in to 2.8.0 (#110) * Versioning * Fix discord import for wrapper namespaces != discord (#104) * Versioning --------- Co-authored-by: mahtoid <git@mahto.id> Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Fix CSS/JS Issues + QOL Improvements (#108) * 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 <69309597+doluk@users.noreply.github.com> * Update chat_exporter/construct/assets/component.py Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Update chat_exporter/construct/assets/component.py Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Update chat_exporter/construct/assets/component.py Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Update chat_exporter/construct/assets/component.py Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Update chat_exporter/html/component/component_button.html Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Update chat_exporter/html/base.html Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Update chat_exporter/construct/assets/component.py Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Update chat_exporter/construct/message.py Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Refactoring * Fixed Military Times --------- Co-authored-by: mahtoid <git@mahto.id> Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> * Update discord link * Fix a bug within LocalAttachmentHandler and regex search returning None causing AttributeError & add html meta tags to transcript (#111) * Ensure unique filenames Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> * Add html meta tags Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> * Fix Local File handler Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> * Fix regex search returning no match causing AttributeError Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> * Exchange uuid4 with EPOCH timestamp with ms Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> --------- Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> * Interaction Message (metadata) * Backport Interaction * interaction name --------- Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> Co-authored-by: Argon <laiyeqi@gmail.com> Co-authored-by: mahtoid <git@mahto.id> Co-authored-by: Lukas Dobler <69309597+doluk@users.noreply.github.com> Co-authored-by: syntax <me@syntax.fo>
1 parent 7372cb2 commit 9dd8f04

28 files changed

+238
-220
lines changed

.gitignore

Lines changed: 35 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ parts/
2020
sdist/
2121
var/
2222
wheels/
23-
pip-wheel-metadata/
2423
share/python-wheels/
2524
*.egg-info/
2625
.installed.cfg
@@ -50,6 +49,7 @@ coverage.xml
5049
*.py,cover
5150
.hypothesis/
5251
.pytest_cache/
52+
cover/
5353

5454
# Translations
5555
*.mo
@@ -72,6 +72,7 @@ instance/
7272
docs/_build/
7373

7474
# PyBuilder
75+
.pybuilder/
7576
target/
7677

7778
# Jupyter Notebook
@@ -82,7 +83,9 @@ profile_default/
8283
ipython_config.py
8384

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

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

94-
# pyflow
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
95113
__pypackages__/
96114

97115
# Celery stuff
@@ -102,7 +120,6 @@ celerybeat.pid
102120
*.sage.py
103121

104122
# Environments
105-
.idea
106123
.env
107124
.venv
108125
env/
@@ -129,77 +146,21 @@ dmypy.json
129146
# Pyre type checker
130147
.pyre/
131148

149+
# pytype static type analyzer
150+
.pytype/
132151

133-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
134-
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
135-
136-
# User-specific stuff
137-
.idea/**/workspace.xml
138-
.idea/**/tasks.xml
139-
.idea/**/usage.statistics.xml
140-
.idea/**/dictionaries
141-
.idea/**/shelf
142-
143-
# Generated files
144-
.idea/**/contentModel.xml
145-
146-
# Sensitive or high-churn files
147-
.idea/**/dataSources/
148-
.idea/**/dataSources.ids
149-
.idea/**/dataSources.local.xml
150-
.idea/**/sqlDataSources.xml
151-
.idea/**/dynamic.xml
152-
.idea/**/uiDesigner.xml
153-
.idea/**/dbnavigator.xml
154-
155-
# Gradle
156-
.idea/**/gradle.xml
157-
.idea/**/libraries
158-
159-
# Gradle and Maven with auto-import
160-
# When using Gradle or Maven with auto-import, you should exclude module files,
161-
# since they will be recreated, and may cause churn. Uncomment if using
162-
# auto-import.
163-
# .idea/artifacts
164-
# .idea/compiler.xml
165-
# .idea/modules.xml
166-
# .idea/*.iml
167-
# .idea/modules
168-
# *.iml
169-
# *.ipr
170-
171-
# CMake
172-
cmake-build-*/
173-
174-
# Mongo Explorer plugin
175-
.idea/**/mongoSettings.xml
176-
177-
# File-based project format
178-
*.iws
179-
180-
# IntelliJ
181-
out/
182-
183-
# mpeltonen/sbt-idea plugin
184-
.idea_modules/
185-
186-
# JIRA plugin
187-
atlassian-ide-plugin.xml
188-
189-
# Cursive Clojure plugin
190-
.idea/replstate.xml
191-
192-
# Crashlytics plugin (for Android Studio and IntelliJ)
193-
com_crashlytics_export_strings.xml
194-
crashlytics.properties
195-
crashlytics-build.properties
196-
fabric.properties
197-
198-
# Editor-based Rest Client
199-
.idea/httpRequests
200-
201-
# Android studio 3.1+ serialized cache file
202-
.idea/caches/build_file_checksums.ser
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/
161+
162+
# VSCode
163+
.vscode/
203164

204165
# Project specific ignores
205166
bot.py

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ from discord import Attachment
238238

239239

240240
class MyAttachmentHandler(AttachmentHandler):
241+
def __init__(self, *args, **kwargs):
242+
# Your initialization code here
243+
# in your case we just create the cloud client
244+
self.cloud_client = CloudClient()
245+
241246
async def process_asset(self, attachment: Attachment):
242247
# Your upload logic here, in our example we just upload the asset to the cloud
243248

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

261-
# and set the url attribute of the attachment to the generated url
262-
attachment.url = asset_url
266+
# and set the proxy url attribute of the attachment to the generated url
267+
attachment.proxy_url = asset_url
263268
return attachment
264269

265270
```
266271

267272
Note
268-
1. The `process_asset` method should return the attachment object with the url attribute set to the generated url.
273+
1. The `process_asset` method should return the attachment object with the proxy_url attribute set to the generated url.
269274
2. The `process_asset` method should be an async method, as it is likely that you have to do some async operations
270275
like fetching the content of the attachment or uploading it to the cloud.
271276
3. You are free to add other methods in your class, and call them from `process_asset` if you need to do some

chat_exporter/chat_exporter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async def quick_export(
3636
after=None,
3737
support_dev=True,
3838
bot=bot,
39+
attachment_handler=None
3940
).export()
4041
).html
4142

chat_exporter/construct/assets/attachment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async def audio(self):
4747

4848
self.attachments = await fill_out(self.guild, audio_attachment, [
4949
("ATTACH_ICON", file_icon, PARSE_MODE_NONE),
50-
("ATTACH_URL", self.attachments.url, PARSE_MODE_NONE),
50+
("ATTACH_URL", self.attachments.proxy_url, PARSE_MODE_NONE),
5151
("ATTACH_BYTES", str(file_size), PARSE_MODE_NONE),
5252
("ATTACH_AUDIO", self.attachments.proxy_url, PARSE_MODE_NONE),
5353
("ATTACH_FILE", str(self.attachments.filename), PARSE_MODE_NONE)
@@ -60,7 +60,7 @@ async def file(self):
6060

6161
self.attachments = await fill_out(self.guild, msg_attachment, [
6262
("ATTACH_ICON", file_icon, PARSE_MODE_NONE),
63-
("ATTACH_URL", self.attachments.url, PARSE_MODE_NONE),
63+
("ATTACH_URL", self.attachments.proxy_url, PARSE_MODE_NONE),
6464
("ATTACH_BYTES", str(file_size), PARSE_MODE_NONE),
6565
("ATTACH_FILE", str(self.attachments.filename), PARSE_MODE_NONE)
6666
])
@@ -88,7 +88,7 @@ async def get_file_icon(self) -> str:
8888
"arj", "pkg", "z"
8989
)
9090

91-
extension = self.attachments.url.rsplit('.', 1)[1]
91+
extension = self.attachments.proxy_url.rsplit('.', 1)[1]
9292
if extension in acrobat_types:
9393
return DiscordUtils.file_attachment_acrobat
9494
elif extension in webcode_types:

chat_exporter/construct/assets/component.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,26 @@ async def build_component(self, c):
4444
Component.menu_div_id += 1
4545

4646
async def build_button(self, c):
47-
url = c.url if c.url else ""
48-
label = c.label if c.label else ""
47+
if c.url:
48+
url = str(c.url)
49+
target = " target='_blank'"
50+
icon = str(DiscordUtils.button_external_link)
51+
else:
52+
url = "javascript:;"
53+
target = ""
54+
icon = ""
55+
56+
label = str(c.label) if c.label else ""
4957
style = self.styles[str(c.style).split(".")[1]]
50-
icon = DiscordUtils.button_external_link if url else ""
5158
emoji = str(c.emoji) if c.emoji else ""
5259

5360
self.buttons += await fill_out(self.guild, component_button, [
5461
("DISABLED", "chatlog__component-disabled" if c.disabled else "", PARSE_MODE_NONE),
55-
("URL", str(url), PARSE_MODE_NONE),
56-
("LABEL", str(label), PARSE_MODE_MARKDOWN),
57-
("EMOJI", str(emoji), PARSE_MODE_EMOJI),
58-
("ICON", str(icon), PARSE_MODE_NONE),
62+
("URL", url, PARSE_MODE_NONE),
63+
("LABEL", label, PARSE_MODE_MARKDOWN),
64+
("EMOJI", emoji, PARSE_MODE_EMOJI),
65+
("ICON", icon, PARSE_MODE_NONE),
66+
("TARGET", target, PARSE_MODE_NONE),
5967
("STYLE", style, PARSE_MODE_NONE)
6068
])
6169

chat_exporter/construct/attachment_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import io
33
import pathlib
44
from typing import Union
5+
import urllib.parse
6+
57

68
import aiohttp
79
from chat_exporter.ext.discord_import import discord
@@ -33,7 +35,7 @@ async def process_asset(self, attachment: discord.Attachment) -> discord.Attachm
3335
:param attachment: discord.Attachment
3436
:return: str
3537
"""
36-
file_name = f"{int(datetime.datetime.utcnow().timestamp())}_{attachment.filename}".replace(' ', '%20')
38+
file_name = urllib.parse.quote_plus(f"{datetime.datetime.utcnow().timestamp()}_{attachment.filename}")
3739
asset_path = self.base_path / file_name
3840
await attachment.save(asset_path)
3941
file_url = f"{self.url_base}/{file_name}"

0 commit comments

Comments
 (0)