Skip to content

Commit ef53009

Browse files
committed
Add autoembedder support for Reddit
1 parent 6e46643 commit ef53009

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

cogs/events.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
from loguru import logger
1212

1313
from modules import emoji_literals, exceptions, queries, util
14-
from modules.media_embedders import BaseEmbedder, InstagramEmbedder, TikTokEmbedder
14+
from modules.media_embedders import (
15+
BaseEmbedder,
16+
InstagramEmbedder,
17+
RedditEmbedder,
18+
TikTokEmbedder,
19+
)
1520
from modules.misobot import MisoBot
1621

1722

@@ -379,6 +384,12 @@ async def parse_media_auto_embed(
379384
if posts:
380385
await self.embed_posts(posts, message, embedder)
381386

387+
if media_settings["reddit"]:
388+
embedder = RedditEmbedder(self.bot)
389+
posts = embedder.extract_links(message.content)
390+
if posts:
391+
await self.embed_posts(posts, message, embedder)
392+
382393
@staticmethod
383394
async def easter_eggs(message: discord.Message):
384395
"""Easter eggs handler"""

cogs/media.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from bs4 import BeautifulSoup
1313
from discord.ext import commands
1414
from loguru import logger
15+
16+
from modules import emojis, exceptions, util
1517
from modules.media_embedders import (
1618
BaseEmbedder,
1719
InstagramEmbedder,
@@ -21,8 +23,6 @@
2123
)
2224
from modules.misobot import MisoBot
2325

24-
from modules import emojis, exceptions, util
25-
2626

2727
class Media(commands.Cog):
2828
"""Fetch various media"""
@@ -63,14 +63,18 @@ async def youtube(self, ctx: commands.Context, *, query):
6363
)
6464

6565
@util.patrons_only()
66-
@commands.group()
66+
@commands.group(usage="<instagram | tiktok | reddit>")
6767
async def autoembedder(
68-
self, ctx: commands.Context, provider: Literal["instagram", "tiktok"]
68+
self, ctx: commands.Context, provider: Literal["instagram", "tiktok", "reddit"]
6969
):
7070
"""Set up automatic embeds for various media sources
7171
7272
The links will be expanded automatically when detected in chat,
73-
without requiring the use of the corresponding command
73+
without requiring the use of the corresponding command.
74+
75+
Supported providers: `instagram`, `tiktok`, `reddit`
76+
77+
Example: >autoembedder tiktok toggle
7478
"""
7579
if ctx.guild is None:
7680
raise exceptions.CommandError("Unable to get current guild")

modules/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ async def user_is_donator(user: discord.User, bot: "MisoBot") -> bool:
884884

885885

886886
async def patron_check(ctx):
887-
if user_is_donator(ctx.author, ctx.bot):
887+
if await user_is_donator(ctx.author, ctx.bot):
888888
return True
889889
raise PatronCheckFailure
890890

0 commit comments

Comments
 (0)