Skip to content

Commit

Permalink
Merge pull request #23 from JvPeek/develop
Browse files Browse the repository at this point in the history
feat: Multiple allow roles
  • Loading branch information
awsdcrafting authored Jan 24, 2024
2 parents 5258431 + 80ad609 commit 83554c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions discord_bot/.example.env
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions discord_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 83554c8

Please sign in to comment.