Add missing SEARCH_ROLE check

Rene Teigen 1 year ago
parent 2513cdf348
commit 471d634e18

@ -956,6 +956,7 @@ class Commands(discord.Cog, name="Commands"):
name="search",
description="Search google alongside GPT3 for something",
guild_ids=ALLOWED_GUILDS,
checks=[Check.check_search_roles()],
)
@discord.option(name="query", description="The query to search", required=True)
@discord.option(

@ -8,6 +8,7 @@ DALLE_ROLES = EnvService.get_dalle_roles()
GPT_ROLES = EnvService.get_gpt_roles()
INDEX_ROLES = EnvService.get_index_roles()
TRANSLATOR_ROLES = EnvService.get_translator_roles()
SEARCH_ROLES = EnvService.get_search_roles()
ALLOWED_GUILDS = EnvService.get_allowed_guilds()
@ -99,3 +100,22 @@ class Check:
return True
return inner
@staticmethod
def check_search_roles() -> Callable:
async def inner(ctx: discord.ApplicationContext):
if SEARCH_ROLES == [None]:
return True
if not any(
role.name.lower() in SEARCH_ROLES for role in ctx.user.roles
):
await ctx.defer(ephemeral=True)
await ctx.respond(
f"You don't have permission, list of roles is {SEARCH_ROLES}",
ephemeral=True,
delete_after=10,
)
return False
return True
return inner

@ -153,7 +153,7 @@ class EnvService:
print(
"TRANSLATOR_ROLES is not defined properly in the environment file!"
"Please copy your server's role and put it into TRANSLATOR in the .env file."
'For example a line should look like: `TRANSLATOR="Translate"`'
'For example a line should look like: `TRANSLATOR_ROLES="Translate"`'
)
print("Defaulting to allowing all users to use Translator commands...")
return [None]
@ -165,6 +165,32 @@ class EnvService:
)
return translator_roles
@staticmethod
def get_search_roles():
# DALLE_ROLES is a comma separated list of string roles
# It can also just be one role
# Read these allowed roles and return as a list of strings
try:
search_roles = os.getenv("SEARCH_ROLES")
except Exception:
search_roles = None
if search_roles is None:
print(
"SEARCH_ROLES is not defined properly in the environment file!"
"Please copy your server's role and put it into SEARCH in the .env file."
'For example a line should look like: `SEARCH_ROLES="Translate"`'
)
print("Defaulting to allowing all users to use Search commands...")
return [None]
search_roles = (
search_roles.lower().split(",")
if "," in search_roles
else [search_roles.lower()]
)
return search_roles
@staticmethod
def get_gpt_roles():
# GPT_ROLES is a comma separated list of string roles

Loading…
Cancel
Save