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

Fix twitter not embedding in the first place (fxtwitter). Add support for tiktok (vxtiktok), reddit (fxreddit/rxddit), and threads (vxthreads) #12

Open
wants to merge 11 commits into
base: dpy2
Choose a base branch
from
4 changes: 2 additions & 2 deletions snsconverter/commandHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def _grpSns(self, ctx: Context):
async def _cmdToggle(self, ctx: Context):
"""Toggle SNSConverter replacements on the server

This will toggle the auto-reply of any Twitter or Instagram links with
embeds, and replace them with vxtwitter or ddinstagram, respectively.
This will toggle the auto-reply of any Twitter, Instagram, Threads, Tiktok, or Reddit links with
embeds, and replace them with vxtwitter, ddinstagram, vxthreads, vxtiktok, or fxreddit respectively.
"""
await self.cmdToggle(ctx)
14 changes: 13 additions & 1 deletion snsconverter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@

KEY_ENABLED = "enabled"
DEFAULT_GUILD = {KEY_ENABLED: False}
INSTA_REGEX_PATTERN = re.compile(r"https://(?:www\.)?(instagram.com)")
INSTA_REGEX_PATTERN = re.compile(r"http(?:s)?://(?:www\.)?(instagram\.com)")
TIKTOK_REGEX_PATTERN = re.compile(r"http(?:s)?://(www\.|vm\.)?(tiktok\.com)")
TWITTER_REGEX_PATTERN = re.compile(
r"http(?:s)?://(?:www\.)?twitter\.com(/[^/]+/status/\d+)"
)
X_REGEX_PATTERN = re.compile(r"http(?:s)?://(?:www\.)?x\.com(/[^/]+/status/\d+)")
# Match any reddit subdomain, too many to list (old, np, de, us, etc)
REDDIT_REGEX_PATTERN = re.compile(r"http(?:s)?://(?:[\w-]+?\.)?reddit\.com")
THREADS_REGEX_PATTERN = re.compile(r"http(?:s)?://(?:www\.)?(threads\.net)")


class SocialMedia(enum.Enum):
INSTAGRAM = "Instagram"
# I'm not calling it f****ng "x" lol
TWITTER = "Twitter"
TIKTOK = "TikTok"
REDDIT = "Reddit"
THREADS = "Threads"
16 changes: 12 additions & 4 deletions snsconverter/eventHandlers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from discord import Message

from discord import Message, RawMessageUpdateEvent
from redbot.core import commands

from .eventsCore import EventsCore
Expand All @@ -10,8 +9,17 @@ class EventHandlers(EventsCore):
async def twit_replacer(self, message: Message):
await self._on_message_twit_replacer(message)
await self._on_message_insta_replacer(message)
await self._on_message_tik_replacer(message)
await self._on_message_reddit_replacer(message)
await self._on_message_threads_replacer(message)

@commands.Cog.listener("on_message_edit")
async def twit_edit_replacer(self, message_before: Message, message_after):
async def twit_edit_replacer(self, message_before: Message, message_after: Message):
await self._on_edit_twit_replacer(message_before, message_after)
await self._on_edit_insta_replacer(message_before, message_after)

@commands.Cog.listener("on_raw_message_edit")
async def twit_raw_edit_replacer(self, payload: RawMessageUpdateEvent):
await self._on_edit_insta_replacer(payload)
await self._on_edit_tik_replacer(payload)
await self._on_edit_reddit_replacer(payload)
await self._on_edit_threads_replacer(payload)
Loading