Skip to content

Commit

Permalink
[ConversationGames] disallow r rated in non-nsfw
Browse files Browse the repository at this point in the history
  • Loading branch information
japandotorg committed Sep 24, 2023
1 parent 0600fb7 commit e7d2e3b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions conversationgames/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from typing import Dict, Final, List, Optional

import discord
from discord.ext.commands._types import Check
from redbot.core import Config, app_commands, commands
from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import humanize_list
Expand All @@ -39,6 +40,18 @@
log: logging.Logger = logging.getLogger("red.seina.conversationgames")


def is_restricted() -> Check[commands.Context]:
async def _predicate(ctx: commands.Context) -> bool:
rating = await ctx.cog.config.guild(ctx.guild).rating() # type: ignore
if rating.lower() in ["pg", "pg13"]:
return True
elif ctx.channel.is_nsfw(): # type: ignore
return True
return False

return commands.check(_predicate)


class ConversationGames(commands.Cog):
"""Conversation games"""

Expand Down Expand Up @@ -69,6 +82,7 @@ async def _get_rating(self, guild: discord.Guild) -> Ratings:
rating = await self.config.guild(guild).rating()
return rating

@is_restricted()
@commands.guild_only()
@commands.cooldown(1, 3, commands.BucketType.guild)
@commands.bot_has_permissions(embed_links=True)
Expand All @@ -94,6 +108,7 @@ async def _wyr(self, ctx: commands.Context):
)
_view._message = _out

@is_restricted()
@commands.guild_only()
@commands.cooldown(1, 3, commands.BucketType.guild)
@commands.bot_has_permissions(embed_links=True)
Expand All @@ -119,6 +134,7 @@ async def _nhie(self, ctx: commands.Context):
)
_view._message = _out

@is_restricted()
@commands.guild_only()
@commands.cooldown(1, 3, commands.BucketType.guild)
@commands.bot_has_permissions(embed_links=True)
Expand All @@ -144,6 +160,7 @@ async def _paranoia(self, ctx: commands.Context):
)
_view._message = _out

@is_restricted()
@commands.guild_only()
@commands.cooldown(1, 3, commands.BucketType.guild)
@commands.bot_has_permissions(embed_links=True)
Expand Down Expand Up @@ -174,6 +191,7 @@ async def _truth(self, ctx: commands.Context, *, member: Optional[discord.Member
)
_view._message = _out

@is_restricted()
@commands.guild_only()
@commands.cooldown(1, 3, commands.BucketType.guild)
@commands.bot_has_permissions(embed_links=True)
Expand Down

0 comments on commit e7d2e3b

Please sign in to comment.