Merge pull request #48 from Hikari-Haru/slashgroups-refactor
Slashgroups refactor and separation of commands based on roles
commit
dd6be231d5
@ -1,22 +1,50 @@
|
||||
import discord
|
||||
|
||||
from models.env_service_model import EnvService
|
||||
from typing import Callable
|
||||
|
||||
|
||||
ALLOWED_ROLES = EnvService.get_allowed_roles()
|
||||
ADMIN_ROLES = EnvService.get_admin_roles()
|
||||
DALLE_ROLES = EnvService.get_dalle_roles()
|
||||
GPT_ROLES = EnvService.get_gpt_roles()
|
||||
ALLOWED_GUILDS = EnvService.get_allowed_guilds()
|
||||
|
||||
|
||||
class Check:
|
||||
def check_valid_roles() -> Callable:
|
||||
def check_admin_roles() -> Callable:
|
||||
async def inner(ctx: discord.ApplicationContext):
|
||||
if not any(role.name in ALLOWED_ROLES for role in ctx.user.roles):
|
||||
if not any(role.name.lower() in ADMIN_ROLES for role in ctx.user.roles):
|
||||
await ctx.defer(ephemeral=True)
|
||||
await ctx.respond(
|
||||
"You don't have permission to use this.",
|
||||
f"You don't have permission to use this.",
|
||||
ephemeral=True,
|
||||
delete_after=10,
|
||||
)
|
||||
return False
|
||||
return True
|
||||
return inner
|
||||
|
||||
def check_dalle_roles() -> Callable:
|
||||
async def inner(ctx: discord.ApplicationContext):
|
||||
if not any(role.name.lower() in DALLE_ROLES for role in ctx.user.roles):
|
||||
await ctx.defer(ephemeral=True)
|
||||
await ctx.respond(
|
||||
"You don't have permission to use this.",
|
||||
ephemeral=True,
|
||||
delete_after=10,
|
||||
)
|
||||
return False
|
||||
return True
|
||||
return inner
|
||||
|
||||
def check_gpt_roles() -> Callable:
|
||||
async def inner(ctx: discord.ApplicationContext):
|
||||
if not any(role.name.lower() in GPT_ROLES for role in ctx.user.roles):
|
||||
await ctx.defer(ephemeral=True)
|
||||
await ctx.respond(
|
||||
"You don't have permission to use this.",
|
||||
ephemeral=True,
|
||||
delete_after=10,
|
||||
)
|
||||
return False
|
||||
return True
|
||||
return inner
|
@ -1,7 +1,11 @@
|
||||
OPENAI_TOKEN="<openai_api_token>"
|
||||
DISCORD_TOKEN="<discord_bot_token>"
|
||||
DEBUG_GUILD="755420092027633774"
|
||||
DEBUG_CHANNEL="907974109084942396"
|
||||
ALLOWED_GUILDS="971268468148166697,971268468148166697"
|
||||
ALLOWED_ROLES="Admin,gpt"
|
||||
DEBUG_GUILD="<debug_guild_id>"
|
||||
DEBUG_CHANNEL="<debug_channel_id>"
|
||||
# make sure not to include an id the bot doesn't have access to
|
||||
ALLOWED_GUILDS="<guild_id>,<guild_id>"
|
||||
# no spaces, case sensitive, these define which roles have access to what. E.g if GPT_ROLES="gpt", then anyone with the "gpt" role can use GPT3 commands.
|
||||
ADMIN_ROLES="admin,owner"
|
||||
DALLE_ROLES="admin,openai,dalle"
|
||||
GPT_ROLES="admin,openai,gpt"
|
||||
WELCOME_MESSAGE="Hi There! Welcome to our Discord server. We hope you'll enjoy our server and we look forward to engaging with you!"
|
||||
|
Loading…
Reference in new issue