From e7d2e3bcc407bb5bbaed69f635e91775016a6e3b Mon Sep 17 00:00:00 2001 From: Lemon Rose Date: Sun, 24 Sep 2023 15:15:22 +0530 Subject: [PATCH] [ConversationGames] disallow r rated in non-nsfw --- conversationgames/core.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/conversationgames/core.py b/conversationgames/core.py index 3df25c20..813fb61c 100644 --- a/conversationgames/core.py +++ b/conversationgames/core.py @@ -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 @@ -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""" @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)