Build custom embeds for Twitter

This commit is contained in:
Zeva Rose 2022-03-02 14:37:45 -07:00
parent f48af6fc80
commit 933bff6711
2 changed files with 25 additions and 2 deletions

View file

@ -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 <t:{timestamp}:f>: {url}"
f"`@{account.handle}` {mod}tweeted this at <t:{timestamp}:f>"
)
# Delete invalid follows

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "jarvis-tasks"
version = "0.1.0"
version = "0.1.1"
description = ""
authors = ["Your Name <you@example.com>"]