Build custom embeds for Twitter
This commit is contained in:
parent
f48af6fc80
commit
933bff6711
2 changed files with 25 additions and 2 deletions
|
@ -5,8 +5,10 @@ from logging import Logger
|
||||||
|
|
||||||
import tweepy
|
import tweepy
|
||||||
from dis_snek import Snake
|
from dis_snek import Snake
|
||||||
|
from dis_snek.models.discord.embed import EmbedAttachment
|
||||||
from jarvis_core.db import q
|
from jarvis_core.db import q
|
||||||
from jarvis_core.db.models import TwitterAccount, TwitterFollow
|
from jarvis_core.db.models import TwitterAccount, TwitterFollow
|
||||||
|
from jarvis_core.util import build_embed
|
||||||
|
|
||||||
from jarvis_tasks.config import TaskConfig
|
from jarvis_tasks.config import TaskConfig
|
||||||
|
|
||||||
|
@ -65,8 +67,29 @@ async def twitter(bot: Snake, logger: Logger) -> None:
|
||||||
timestamp = int(tweet.created_at.timestamp())
|
timestamp = int(tweet.created_at.timestamp())
|
||||||
url = f"https://twitter.com/{account.handle}/status/{tweet.id}"
|
url = f"https://twitter.com/{account.handle}/status/{tweet.id}"
|
||||||
mod = "re" if retweet else ""
|
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(
|
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
|
# Delete invalid follows
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "jarvis-tasks"
|
name = "jarvis-tasks"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
description = ""
|
description = ""
|
||||||
authors = ["Your Name <you@example.com>"]
|
authors = ["Your Name <you@example.com>"]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue