Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
working version for youtube link thumbnail display + images displaying properly; testing gif display
Browse files
app.py
CHANGED
@@ -52,6 +52,14 @@ def extract_youtube_video_id(url):
|
|
52 |
return match.group(1) if match else None
|
53 |
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
@bot.event
|
57 |
async def on_message(message):
|
@@ -72,19 +80,27 @@ async def on_message(message):
|
|
72 |
embed.add_field(name="Message Created On", value=convert_to_timezone(message.created_at, zurich_tz), inline=True)
|
73 |
embed.add_field(name="Message ID", value=message.id, inline=True)
|
74 |
embed.add_field(name="Message Jump URL", value=f"[Jump to message!](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})", inline=True)
|
75 |
-
|
|
|
76 |
for attachment in message.attachments:
|
77 |
if attachment.content_type and attachment.content_type.startswith("image/"):
|
78 |
embed.set_image(url=attachment.url)
|
79 |
break
|
80 |
|
81 |
-
#
|
82 |
video_id = extract_youtube_video_id(message.content)
|
83 |
if video_id:
|
84 |
video_url = f"https://youtu.be/{video_id}"
|
85 |
thumbnail_url = f"https://img.youtube.com/vi/{video_id}/hqdefault.jpg"
|
86 |
embed.add_field(name="YouTube Link", value=video_url, inline=False)
|
87 |
-
embed.set_image(url=thumbnail_url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
#await bot.log_channel.send(embed=embed)
|
90 |
dm_message = await lunarflu.send(embed=embed)
|
|
|
52 |
return match.group(1) if match else None
|
53 |
|
54 |
|
55 |
+
def extract_tenor_gif_url(content):
|
56 |
+
match = re.search(r"tenor\.com/view/[^-]+-(\d+)", content)
|
57 |
+
if match:
|
58 |
+
gif_id = match.group(1)
|
59 |
+
return f"https://media.tenor.com/{gif_id}/tenor.gif"
|
60 |
+
return None
|
61 |
+
|
62 |
+
|
63 |
|
64 |
@bot.event
|
65 |
async def on_message(message):
|
|
|
80 |
embed.add_field(name="Message Created On", value=convert_to_timezone(message.created_at, zurich_tz), inline=True)
|
81 |
embed.add_field(name="Message ID", value=message.id, inline=True)
|
82 |
embed.add_field(name="Message Jump URL", value=f"[Jump to message!](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})", inline=True)
|
83 |
+
|
84 |
+
# working image thumbnail display
|
85 |
for attachment in message.attachments:
|
86 |
if attachment.content_type and attachment.content_type.startswith("image/"):
|
87 |
embed.set_image(url=attachment.url)
|
88 |
break
|
89 |
|
90 |
+
# working video thumbnail display
|
91 |
video_id = extract_youtube_video_id(message.content)
|
92 |
if video_id:
|
93 |
video_url = f"https://youtu.be/{video_id}"
|
94 |
thumbnail_url = f"https://img.youtube.com/vi/{video_id}/hqdefault.jpg"
|
95 |
embed.add_field(name="YouTube Link", value=video_url, inline=False)
|
96 |
+
embed.set_image(url=thumbnail_url)
|
97 |
+
|
98 |
+
# gifs testing
|
99 |
+
gif_url = extract_tenor_gif_url(message.content)
|
100 |
+
if gif_url:
|
101 |
+
embed.set_image(url=gif_url)
|
102 |
+
embed.add_field(name="GIF Link", value=gif_url, inline=False)
|
103 |
+
|
104 |
|
105 |
#await bot.log_channel.send(embed=embed)
|
106 |
dm_message = await lunarflu.send(embed=embed)
|