Allow setting for sending NSFW content to DMs
This commit is contained in:
parent
ad97bae9f7
commit
7c72296cce
2 changed files with 64 additions and 28 deletions
|
@ -8,7 +8,7 @@ from asyncpraw.models.reddit.submission import Submission
|
||||||
from asyncpraw.models.reddit.submission import Subreddit as Sub
|
from asyncpraw.models.reddit.submission import Subreddit as Sub
|
||||||
from asyncprawcore.exceptions import Forbidden, NotFound, Redirect
|
from asyncprawcore.exceptions import Forbidden, NotFound, Redirect
|
||||||
from jarvis_core.db import q
|
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, Cog, InteractionContext, Permissions
|
from naff import Client, Cog, InteractionContext, Permissions
|
||||||
from naff.client.utils.misc_utils import get
|
from naff.client.utils.misc_utils import get
|
||||||
from naff.models.discord.channel import ChannelTypes, GuildText
|
from naff.models.discord.channel import ChannelTypes, GuildText
|
||||||
|
@ -269,10 +269,14 @@ class RedditCog(Cog):
|
||||||
|
|
||||||
embeds = await self.post_embeds(subreddit, post)
|
embeds = await self.post_embeds(subreddit, post)
|
||||||
if post.over_18 and not ctx.channel.nsfw:
|
if post.over_18 and not ctx.channel.nsfw:
|
||||||
|
setting = await UserSetting.find_one(
|
||||||
|
q(user=ctx.author.id, type="reddit", setting="dm_nsfw")
|
||||||
|
)
|
||||||
|
if setting and setting.value:
|
||||||
try:
|
try:
|
||||||
await ctx.author.send(embeds=embeds)
|
await ctx.author.send(embeds=embeds)
|
||||||
await ctx.send("Hey! Due to content, I had to DM the result to you")
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
pass
|
||||||
await ctx.send("Hey! Due to content, I cannot share the result")
|
await ctx.send("Hey! Due to content, I cannot share the result")
|
||||||
else:
|
else:
|
||||||
await ctx.send(embeds=embeds)
|
await ctx.send(embeds=embeds)
|
||||||
|
@ -317,10 +321,14 @@ class RedditCog(Cog):
|
||||||
|
|
||||||
embeds = await self.post_embeds(subreddit, post)
|
embeds = await self.post_embeds(subreddit, post)
|
||||||
if post.over_18 and not ctx.channel.nsfw:
|
if post.over_18 and not ctx.channel.nsfw:
|
||||||
|
setting = await UserSetting.find_one(
|
||||||
|
q(user=ctx.author.id, type="reddit", setting="dm_nsfw")
|
||||||
|
)
|
||||||
|
if setting and setting.value:
|
||||||
try:
|
try:
|
||||||
await ctx.author.send(embeds=embeds)
|
await ctx.author.send(embeds=embeds)
|
||||||
await ctx.send("Hey! Due to content, I had to DM the result to you")
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
pass
|
||||||
await ctx.send("Hey! Due to content, I cannot share the result")
|
await ctx.send("Hey! Due to content, I cannot share the result")
|
||||||
else:
|
else:
|
||||||
await ctx.send(embeds=embeds)
|
await ctx.send(embeds=embeds)
|
||||||
|
@ -353,10 +361,14 @@ class RedditCog(Cog):
|
||||||
|
|
||||||
embeds = await self.post_embeds(subreddit, post)
|
embeds = await self.post_embeds(subreddit, post)
|
||||||
if post.over_18 and not ctx.channel.nsfw:
|
if post.over_18 and not ctx.channel.nsfw:
|
||||||
|
setting = await UserSetting.find_one(
|
||||||
|
q(user=ctx.author.id, type="reddit", setting="dm_nsfw")
|
||||||
|
)
|
||||||
|
if setting and setting.value:
|
||||||
try:
|
try:
|
||||||
await ctx.author.send(embeds=embeds)
|
await ctx.author.send(embeds=embeds)
|
||||||
await ctx.send("Hey! Due to content, I had to DM the result to you")
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
pass
|
||||||
await ctx.send("Hey! Due to content, I cannot share the result")
|
await ctx.send("Hey! Due to content, I cannot share the result")
|
||||||
else:
|
else:
|
||||||
await ctx.send(embeds=embeds)
|
await ctx.send(embeds=embeds)
|
||||||
|
@ -389,10 +401,14 @@ class RedditCog(Cog):
|
||||||
|
|
||||||
embeds = await self.post_embeds(subreddit, post)
|
embeds = await self.post_embeds(subreddit, post)
|
||||||
if post.over_18 and not ctx.channel.nsfw:
|
if post.over_18 and not ctx.channel.nsfw:
|
||||||
|
setting = await UserSetting.find_one(
|
||||||
|
q(user=ctx.author.id, type="reddit", setting="dm_nsfw")
|
||||||
|
)
|
||||||
|
if setting and setting.value:
|
||||||
try:
|
try:
|
||||||
await ctx.author.send(embeds=embeds)
|
await ctx.author.send(embeds=embeds)
|
||||||
await ctx.send("Hey! Due to content, I had to DM the result to you")
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
pass
|
||||||
await ctx.send("Hey! Due to content, I cannot share the result")
|
await ctx.send("Hey! Due to content, I cannot share the result")
|
||||||
else:
|
else:
|
||||||
await ctx.send(embeds=embeds)
|
await ctx.send(embeds=embeds)
|
||||||
|
@ -413,14 +429,34 @@ class RedditCog(Cog):
|
||||||
|
|
||||||
embeds = await self.post_embeds(post.subreddit, post)
|
embeds = await self.post_embeds(post.subreddit, post)
|
||||||
if post.over_18 and not ctx.channel.nsfw:
|
if post.over_18 and not ctx.channel.nsfw:
|
||||||
|
setting = await UserSetting.find_one(
|
||||||
|
q(user=ctx.author.id, type="reddit", setting="dm_nsfw")
|
||||||
|
)
|
||||||
|
if setting and setting.value:
|
||||||
try:
|
try:
|
||||||
await ctx.author.send(embeds=embeds)
|
await ctx.author.send(embeds=embeds)
|
||||||
await ctx.send("Hey! Due to content, I had to DM the result to you")
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
pass
|
||||||
await ctx.send("Hey! Due to content, I cannot share the result")
|
await ctx.send("Hey! Due to content, I cannot share the result")
|
||||||
else:
|
else:
|
||||||
await ctx.send(embeds=embeds)
|
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.find_one(
|
||||||
|
q(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:
|
def setup(bot: Client) -> None:
|
||||||
"""Add RedditCog to JARVIS"""
|
"""Add RedditCog to JARVIS"""
|
||||||
|
|
4
poetry.lock
generated
4
poetry.lock
generated
|
@ -307,7 +307,7 @@ python-versions = ">=3.5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jarvis-core"
|
name = "jarvis-core"
|
||||||
version = "0.9.2"
|
version = "0.10.1"
|
||||||
description = "JARVIS core"
|
description = "JARVIS core"
|
||||||
category = "main"
|
category = "main"
|
||||||
optional = false
|
optional = false
|
||||||
|
@ -328,7 +328,7 @@ umongo = "^3.1.0"
|
||||||
type = "git"
|
type = "git"
|
||||||
url = "https://git.zevaryx.com/stark-industries/jarvis/jarvis-core.git"
|
url = "https://git.zevaryx.com/stark-industries/jarvis/jarvis-core.git"
|
||||||
reference = "main"
|
reference = "main"
|
||||||
resolved_reference = "83117c1b3c5540acadeac3005f4d8e69cbf743fc"
|
resolved_reference = "06a6dd8434b42cd4df7ee073eedbe2a3430ab379"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jinxed"
|
name = "jinxed"
|
||||||
|
|
Loading…
Add table
Reference in a new issue