diff --git a/discord_bot/.example.env b/discord_bot/.example.env index 88c6ea6..03599dd 100644 --- a/discord_bot/.example.env +++ b/discord_bot/.example.env @@ -1,4 +1,5 @@ DISCORD_BOT_TOKEN=your-token-here +DISCORD_ALLOWED_ROLES="123,456" GITHUB_APP_ID=000000 GITHUB_APP_KEY_FILE=your-path-to-secret-key-file-here GITHUB_APP_INSTALLATION_ID=111111 \ No newline at end of file diff --git a/discord_bot/bot.py b/discord_bot/bot.py index cc96d06..3c7d30a 100644 --- a/discord_bot/bot.py +++ b/discord_bot/bot.py @@ -20,7 +20,7 @@ tree = app_commands.CommandTree(client) github: Github repo: Repository -allowed_role:str|None +allowed_roles:list[int]|None = None state_file_path = "./state.json" state = {} @@ -184,14 +184,13 @@ async def save_song(interaction: Interaction, message: Message): if message.id in state["msgs"]: await interaction.response.send_message("Already parsed this song!", ephemeral=True) return - if allowed_role: - role_id = int(allowed_role) + if allowed_roles: if not isinstance(interaction.user, Member): await interaction.response.send_message("You do not have permission to save songs!", ephemeral=True) return allowed = False for role in interaction.user.roles: - if role.id == role_id: + if role.id in allowed_roles: allowed = True break if not allowed: @@ -251,7 +250,10 @@ def read_state(): if not token: print("No discord token provided!") sys.exit(1) - allowed_role = os.environ.get("DISCORD_ALLOWED_ROLE") + allowed_roles_str = os.environ.get("DISCORD_ALLOWED_ROLES") + + if allowed_roles_str: + allowed_roles = [int(role) for role in allowed_roles_str.split(",")] app_id = os.environ.get("GITHUB_APP_ID") private_key_path = os.environ.get("GITHUB_APP_KEY_FILE")