From 933bff6711819701fe90c217998ee87ee88bd236 Mon Sep 17 00:00:00 2001 From: zevaryx Date: Wed, 2 Mar 2022 14:37:45 -0700 Subject: [PATCH] Build custom embeds for Twitter --- jarvis_tasks/tasks/twitter.py | 25 ++++++++++++++++++++++++- pyproject.toml | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/jarvis_tasks/tasks/twitter.py b/jarvis_tasks/tasks/twitter.py index 5e5e834..f4f0286 100644 --- a/jarvis_tasks/tasks/twitter.py +++ b/jarvis_tasks/tasks/twitter.py @@ -5,8 +5,10 @@ from logging import Logger import tweepy from dis_snek import Snake +from dis_snek.models.discord.embed import EmbedAttachment from jarvis_core.db import q from jarvis_core.db.models import TwitterAccount, TwitterFollow +from jarvis_core.util import build_embed from jarvis_tasks.config import TaskConfig @@ -65,8 +67,29 @@ async def twitter(bot: Snake, logger: Logger) -> None: timestamp = int(tweet.created_at.timestamp()) url = f"https://twitter.com/{account.handle}/status/{tweet.id}" mod = "re" if retweet else "" + media = tweet.entities.get("media", None) + photo = None + if media and media[0]["type"] in ["photo", "animated_gif"]: + photo = EmbedAttachment(url=media[0]["media_url_https"]) + embed = build_embed( + title="", + description=(tweet.text + f"\n\n[View this tweet]({url})"), + fields=[], + color="#1DA1F2", + image=photo, + ) + embed.set_author( + name=account.handle, + url=url, + icon_url=tweet.author.profile_image_url_https, + ) + embed.set_footer( + text="Twitter", + icon_url="https://abs.twimg.com/icons/apple-touch-icon-192x192.png", + ) + await channel.send( - f"`@{account.handle}` {mod}tweeted this at : {url}" + f"`@{account.handle}` {mod}tweeted this at " ) # Delete invalid follows diff --git a/pyproject.toml b/pyproject.toml index b1c9b41..d4ce527 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "jarvis-tasks" -version = "0.1.0" +version = "0.1.1" description = "" authors = ["Your Name "]