diff --git a/jarvis/cogs/autoreact.py b/jarvis/cogs/autoreact.py index 221a468..bc2dba5 100644 --- a/jarvis/cogs/autoreact.py +++ b/jarvis/cogs/autoreact.py @@ -178,6 +178,24 @@ class AutoReactCog(Extension): await self.delete_autoreact(ctx, channel) await ctx.send(f"Removed {emote} from {channel.mention} autoreact.") + @autoreact.subcommand( + sub_cmd_name="delete", + sub_cmd_description="Delete an autoreact", + ) + @slash_option( + name="channel", + description="Channel to remove autoreact from", + opt_type=OptionTypes.CHANNEL, + required=True, + ) + @check(admin_or_permissions(Permissions.MANAGE_GUILD)) + async def _autoreact_delete(self, ctx: InteractionContext, channel: GuildText) -> None: + result = self.delete_autoreact(ctx, channel) + if not result: + await ctx.send(f"No autoreact found in {channel.mention}", ephemeral=True) + else: + await ctx.send(f"Autoreact removed from {channel.mention}") + @autoreact.subcommand( sub_cmd_name="list", sub_cmd_description="List all autoreacts on a channel", diff --git a/jarvis/cogs/reddit.py b/jarvis/cogs/reddit.py index cedc8e0..b69b4c1 100644 --- a/jarvis/cogs/reddit.py +++ b/jarvis/cogs/reddit.py @@ -8,7 +8,7 @@ from asyncpraw.models.reddit.submission import Submission from asyncpraw.models.reddit.submission import Subreddit as Sub from asyncprawcore.exceptions import Forbidden, NotFound, Redirect from jarvis_core.db import q -from jarvis_core.db.models import Subreddit, SubredditFollow +from jarvis_core.db.models import Subreddit, SubredditFollow, UserSetting from naff import Client, Extension, InteractionContext, Permissions from naff.client.utils.misc_utils import get from naff.models.discord.channel import ChannelTypes, GuildText @@ -56,7 +56,7 @@ class RedditCog(Extension): fields = [] content = "" og_post = None - if not post.is_self: + if "crosspost_parent_list" in vars(post): og_post = post # noqa: F841 post = await self.api.submission(post.crosspost_parent_list[0]["id"]) await post.load() @@ -76,9 +76,14 @@ class RedditCog(Extension): break if "selftext" in vars(post) and post.selftext: + text = post.selftext + if post.spoiler: + text = "||" + text + "||" content += "\n\n" + post.selftext if len(content) > 900: content = content[:900] + "..." + if post.spoiler: + content += "||" content += f"\n\n[View this post]({url})" if not images and not content: @@ -264,11 +269,15 @@ class RedditCog(Extension): embeds = await self.post_embeds(subreddit, post) if post.over_18 and not ctx.channel.nsfw: - try: - await ctx.author.send(embeds=embeds) - await ctx.send("Hey! Due to content, I had to DM the result to you") - except Exception: - await ctx.send("Hey! Due to content, I cannot share the result") + setting = await UserSetting.find_one( + q(user=ctx.author.id, type="reddit", setting="dm_nsfw") + ) + if setting and setting.value: + try: + await ctx.author.send(embeds=embeds) + except Exception: + pass + await ctx.send("Hey! Due to content, I cannot share the result") else: await ctx.send(embeds=embeds) @@ -312,11 +321,15 @@ class RedditCog(Extension): embeds = await self.post_embeds(subreddit, post) if post.over_18 and not ctx.channel.nsfw: - try: - await ctx.author.send(embeds=embeds) - await ctx.send("Hey! Due to content, I had to DM the result to you") - except Exception: - await ctx.send("Hey! Due to content, I cannot share the result") + setting = await UserSetting.find_one( + q(user=ctx.author.id, type="reddit", setting="dm_nsfw") + ) + if setting and setting.value: + try: + await ctx.author.send(embeds=embeds) + except Exception: + pass + await ctx.send("Hey! Due to content, I cannot share the result") else: await ctx.send(embeds=embeds) @@ -348,11 +361,15 @@ class RedditCog(Extension): embeds = await self.post_embeds(subreddit, post) if post.over_18 and not ctx.channel.nsfw: - try: - await ctx.author.send(embeds=embeds) - await ctx.send("Hey! Due to content, I had to DM the result to you") - except Exception: - await ctx.send("Hey! Due to content, I cannot share the result") + setting = await UserSetting.find_one( + q(user=ctx.author.id, type="reddit", setting="dm_nsfw") + ) + if setting and setting.value: + try: + await ctx.author.send(embeds=embeds) + except Exception: + pass + await ctx.send("Hey! Due to content, I cannot share the result") else: await ctx.send(embeds=embeds) @@ -384,11 +401,15 @@ class RedditCog(Extension): embeds = await self.post_embeds(subreddit, post) if post.over_18 and not ctx.channel.nsfw: - try: - await ctx.author.send(embeds=embeds) - await ctx.send("Hey! Due to content, I had to DM the result to you") - except Exception: - await ctx.send("Hey! Due to content, I cannot share the result") + setting = await UserSetting.find_one( + q(user=ctx.author.id, type="reddit", setting="dm_nsfw") + ) + if setting and setting.value: + try: + await ctx.author.send(embeds=embeds) + except Exception: + pass + await ctx.send("Hey! Due to content, I cannot share the result") else: await ctx.send(embeds=embeds) @@ -403,19 +424,37 @@ class RedditCog(Extension): await post.load() except (NotFound, Forbidden, Redirect) as e: self.logger.debug(f"Submission {sid} raised {e.__class__.__name__} in post") - await ctx.send("Subreddit may be private, quarantined, or nonexistent.", ephemeral=True) + await ctx.send("Post could not be found.", ephemeral=True) return embeds = await self.post_embeds(post.subreddit, post) if post.over_18 and not ctx.channel.nsfw: - try: - await ctx.author.send(embeds=embeds) - await ctx.send("Hey! Due to content, I had to DM the result to you") - except Exception: - await ctx.send("Hey! Due to content, I cannot share the result") + setting = await UserSetting.find_one( + q(user=ctx.author.id, type="reddit", setting="dm_nsfw") + ) + if setting and setting.value: + try: + await ctx.author.send(embeds=embeds) + except Exception: + pass + await ctx.send("Hey! Due to content, I cannot share the result") else: await ctx.send(embeds=embeds) + @reddit.subcommand( + sub_cmd_name="dm_nsfw", sub_cmd_description="DM NSFW posts if channel isn't NSFW" + ) + @slash_option(name="dm", description="Send DM?", opt_type=OptionTypes.BOOLEAN, required=True) + async def _reddit_dm(self, ctx: InteractionContext, dm: bool) -> None: + setting = await UserSetting.find_one( + q(user=ctx.author.id, type="reddit", setting="dm_nsfw") + ) + if not setting: + setting = UserSetting(user=ctx.author.id, type="reddit", setting="dm_nsfw", value=dm) + setting.value = dm + await setting.commit() + await ctx.send(f"Reddit DM NSFW setting is now set to {dm}", ephemeral=True) + def setup(bot: Client) -> None: """Add RedditCog to JARVIS""" diff --git a/poetry.lock b/poetry.lock index 2697614..59e1b34 100644 --- a/poetry.lock +++ b/poetry.lock @@ -307,7 +307,7 @@ python-versions = ">=3.5" [[package]] name = "jarvis-core" -version = "0.9.2" +version = "0.10.1" description = "JARVIS core" category = "main" optional = false @@ -328,7 +328,7 @@ umongo = "^3.1.0" type = "git" url = "https://git.zevaryx.com/stark-industries/jarvis/jarvis-core.git" reference = "main" -resolved_reference = "83117c1b3c5540acadeac3005f4d8e69cbf743fc" +resolved_reference = "06a6dd8434b42cd4df7ee073eedbe2a3430ab379" [[package]] name = "jinxed" diff --git a/pyproject.toml b/pyproject.toml index 8543fed..0a833e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "jarvis" -version = "2.0.0" +version = "2.0.1" description = "J.A.R.V.I.S. admin bot" authors = ["Zevaryx "]