Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluesky command #10

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![top.gg - Servers](https://top.gg/api/widget/servers/1128948590467895396.svg) ![top.gg - Upvotes](https://top.gg/api/widget/upvotes/1128948590467895396.svg?noavatar=true) ![top.gg - Owner](https://top.gg/api/widget/owner/1128948590467895396.svg?noavatar=true) ![Keto](https://img.shields.io/endpoint?url=https%3A%2F%2Fhealthchecks.io%2Fb%2F2%2Fda3c0488-6209-4d19-b4c5-4bf06ac4d505.shields)

A Discord bot for fixing social media embeds (TikTok, Instagram, Twitter, Reddit and YouTube) with other cool features.
A Discord bot for fixing social media embeds (TikTok, Instagram, Twitter, Bluesky, Reddit and YouTube) with other cool features.

Setup with Docker (Recommended):

Expand Down
10 changes: 8 additions & 2 deletions cogs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, bot):
"instagram": 0,
"reddit": 0,
"twitter": 0,
"bluesky": 0,
"songs": 0,
"imdb": 0,
"steam": 0,
Expand Down Expand Up @@ -55,6 +56,7 @@ async def create_tables(self):
instagram INTEGER DEFAULT 0,
reddit INTEGER DEFAULT 0,
twitter INTEGER DEFAULT 0,
bluesky INTEGER DEFAULT 0,
songs INTEGER DEFAULT 0,
imdb INTEGER DEFAULT 0,
steam INTEGER DEFAULT 0
Expand Down Expand Up @@ -89,6 +91,7 @@ async def sync_db_task(self):
"instagram",
"reddit",
"twitter",
"bluesky",
"songs",
"imdb",
"steam",
Expand All @@ -102,20 +105,21 @@ async def sync_db_task(self):
db_counts[platform] += self.link_fix_counts[platform]
self.link_fix_counts[platform] = 0
await self.db.execute(
"UPDATE link_fix_counts SET tiktok = ?, instagram = ?, reddit = ?, twitter = ?, songs = ?, imdb = ?, steam = ? WHERE id = 1",
"UPDATE link_fix_counts SET tiktok = ?, instagram = ?, reddit = ?, twitter = ?, bluesky = ?, songs = ?, imdb = ?, steam = ? WHERE id = 1",
(
db_counts["tiktok"],
db_counts["instagram"],
db_counts["reddit"],
db_counts["twitter"],
db_counts["bluesky"],
db_counts["songs"],
db_counts["imdb"],
db_counts["steam"],
),
)
else:
await self.db.execute(
"INSERT INTO link_fix_counts (id, tiktok, instagram, reddit, twitter, songs, imdb, steam) VALUES (1, ?, ?, ?, ?, ?, ?, ?)",
"INSERT INTO link_fix_counts (id, tiktok, instagram, reddit, twitter, bluesky, songs, imdb, steam) VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?)",
tuple(self.link_fix_counts.values()),
)
self.link_fix_counts = {k: 0 for k in self.link_fix_counts}
Expand All @@ -138,6 +142,7 @@ async def get_link_fix_counts(self):
"instagram",
"reddit",
"twitter",
"bluesky",
"songs",
"imdb",
"steam",
Expand All @@ -151,6 +156,7 @@ async def get_link_fix_counts(self):
"instagram": 0,
"reddit": 0,
"twitter": 0,
"bluesky": 0,
"songs": 0,
"imdb": 0,
"steam": 0,
Expand Down
42 changes: 42 additions & 0 deletions cogs/socials.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def __init__(self, bot):
self.youtube_shorts_pattern = re.compile(
r"https?://(?:www\.)?youtube\.com/shorts/[a-zA-Z0-9_-]+"
)
self.bluesky_pattern = re.compile(
r"https:\/\/bsky\.app\/profile\/[a-zA-Z0-9.-]+\/post\/[a-zA-Z0-9]+"
)

@commands.Cog.listener()
async def on_message(self, message: discord.Message):
Expand All @@ -66,6 +69,9 @@ async def on_message(self, message: discord.Message):
elif twitter_match := self.twitter_pattern.search(message_content):
link = twitter_match.group(0)
await self.fix_twitter(message, link, guild_id=message.guild.id)
elif bluesky_match := self.bluesky_pattern.search(message_content):
link = bluesky_match.group(0)
await self.fix_bluesky(message, link, guild_id=message.guild.id)
# elif youtube_shorts_match := self.youtube_shorts_pattern.search(
# message_content
# ):
Expand Down Expand Up @@ -393,6 +399,8 @@ async def fix(self, context: Context, link: str, spoiler: bool = False) -> None:
await self.fix_reddit(context.message, link, context, spoiler)
elif re.match(self.twitter_pattern, link):
await self.fix_twitter(context.message, link, context, spoiler)
elif re.match(self.bluesky_pattern, link):
await self.fix_bluesky(context.message, link, context, spoiler)
# elif re.match(self.youtube_shorts_pattern, link):
# await self.fix_youtube_shorts(context.message, link, context, spoiler)
else:
Expand Down Expand Up @@ -762,6 +770,40 @@ async def fix_youtube_shorts(
with suppress(discord.errors.Forbidden, discord.errors.NotFound):
await message.edit(suppress=True)

async def fix_bluesky(
self,
message: discord.Message,
link: str,
context: Context = None,
spoiler: bool = False,
guild_id: int = None,
):
if not await self.check_enabled("bluesky", self.config, guild_id):
return
if f"<{link}>" in message.content:
return
spoiler = spoiler or (
f"||{link}" in message.content and message.content.count("||") >= 2
)

link = link.replace("www.", "")
link = link.replace("bsky.app", self.config["bluesky"]["url"])

if context:
await context.send(
link if not spoiler else f"||{link}||", mention_author=False
)
await self.config_cog.increment_link_fix_count("bluesky")
else:
if message.channel.permissions_for(message.guild.me).send_messages:
await message.reply(
link if not spoiler else f"||{link}||", mention_author=False
)
await self.config_cog.increment_link_fix_count("bluesky")
await asyncio.sleep(0.75)
with suppress(discord.errors.Forbidden, discord.errors.NotFound):
await message.edit(suppress=True)


async def setup(bot):
await bot.add_cog(Socials(bot))
4 changes: 4 additions & 0 deletions config/socials.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"enabled": true,
"url": "twittpr.com"
},
"bluesky": {
"enabled": true,
"url": "bskyx.app"
},
"songs": {
"enabled": true
},
Expand Down