Skip to content

Commit

Permalink
Fixed issue between embed images and embed thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtoid committed Nov 26, 2020
1 parent 35d6d54 commit ee7dbaa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
39 changes: 23 additions & 16 deletions chat_exporter/chat_exporter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io
import re
import os
import requests
import discord
import sys
import traceback
Expand Down Expand Up @@ -132,10 +131,25 @@ async def produce_transcript(channel):
footer_icon = e.footer.icon_url \
if e.footer.icon_url != discord.Embed.Empty \
else None
url = e.url \
if e.url != discord.Embed.Empty \

thumbnail = e.thumbnail.url \
if e.thumbnail.url != discord.Embed.Empty \
else ""

image = e.image.url \
if e.image.url != discord.Embed.Empty \
else ""
embed_image = ""

if image != "":
image = await fill_out(channel, embed_image, [
("EMBED_IMAGE", str(image)),
])

if thumbnail != "":
thumbnail = await fill_out(channel, embed_thumbnail, [
("EMBED_THUMBNAIL", str(thumbnail)),
])

footer_fields = ""
if footer != "":
if footer_icon:
Expand All @@ -148,27 +162,18 @@ async def produce_transcript(channel):
("EMBED_FOOTER", footer),
])
footer_fields += cur_footer
if "tenor.com" in str(url):
try:
pattern = r"https:\/\/tenor.com\/view\/.*-gif-(.*)"
url_id = re.search(pattern, str(url)).group(1)
requested_website = requests.get(f'{m.content}')
pattern = rf"https:\/\/media1.tenor.com\/images\/(.*?)?\/tenor.gif\?itemid={url_id}"
url = re.search(pattern, requested_website.text).group(1)
embed_image = "https://media1.tenor.com/images/" + url + f"/tenor.gif?itemid={url_id}"
except AttributeError:
pass

cur_embed = await fill_out(channel, msg_embed, [
("EMBED_R", str(r)),
("EMBED_G", str(g)),
("EMBED_B", str(b)),
("EMBED_AUTHOR", author, PARSE_MODE_EMBED_EMOJI),
("EMBED_TITLE", title, PARSE_MODE_EMBED_EMOJI),
("EMBED_IMAGE", embed_image),
("EMBED_IMAGE", image),
("EMBED_THUMBNAIL", thumbnail),
("EMBED_DESC", desc, PARSE_MODE_EMBED),
("EMBED_FIELDS", fields, PARSE_MODE_EMBED_VALUE),
("EMBED_FOOTER", footer_fields, PARSE_MODE_EMBED_EMOJI)

])
embeds += cur_embed

Expand Down Expand Up @@ -374,3 +379,5 @@ def read_file(filename):
end_message = read_file(dir_path + "/chat_exporter_html/end_message.html")
embed_footer = read_file(dir_path + "/chat_exporter_html/embed_footer.html")
embed_footer_image = read_file(dir_path + "/chat_exporter_html/embed_footer_image.html")
embed_image = read_file(dir_path + "/chat_exporter_html/embed_image.html")
embed_thumbnail = read_file(dir_path + "/chat_exporter_html/embed_thumbnail.html")
5 changes: 5 additions & 0 deletions chat_exporter/chat_exporter_html/embed_image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="chatlog__embed-image-container">
<a class="chatlog__embed-image-link" href="{{EMBED_IMAGE}}">
<img class="chatlog__embed-image" src="{{EMBED_IMAGE}}">
</a>
</div>
5 changes: 5 additions & 0 deletions chat_exporter/chat_exporter_html/embed_thumbnail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="chatlog__embed-thumbnail-container">
<a class="chatlog__embed-thumbnail-link" href="{{EMBED_THUMBNAIL}}">
<img class="chatlog__embed-thumbnail" src="{{EMBED_THUMBNAIL}}">
</a>
</div>
12 changes: 7 additions & 5 deletions chat_exporter/chat_exporter_html/message-embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
{{EMBED_FIELDS}}
</div>

{{EMBED_IMAGE}}

</div>
<div class="chatlog__embed-thumbnail-container">
<a class="chatlog__embed-thumbnail-link" href="{{EMBED_IMAGE}}">
<img class="chatlog__embed-thumbnail" src="{{EMBED_IMAGE}}">
</a>
</div>



{{EMBED_THUMBNAIL}}

</div>

{{EMBED_FOOTER}}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="chat_exporter",
version="1.1.6",
version="1.1.6.5",
author="mahtoid",
description="A simple Discord chat exporter for Python Discord bots.",
long_description=long_description,
Expand Down

0 comments on commit ee7dbaa

Please sign in to comment.