add bucketlist access control, drop credential hashing, gitignore radio_check

This commit is contained in:
esef committed 2026-07-25 13:10:00 +03:00
1 parent d1536666f7
commit 66f9eb774c
3 files changed
+17 -8

No files matched your search

+1
View File
@@ -22,3 +22,4 @@ firebase_service_account.json
**/.codewhale/* **/.codewhale/*
!**/.codewhale/constitution.json !**/.codewhale/constitution.json
.deepseek/ .deepseek/
radio_check.sh
+15 -8
View File
@@ -1,6 +1,5 @@
"""Bucketlist cog — modal-based bucket list, Firestore Admin SDK.""" """Bucketlist cog — modal-based bucket list, Firestore Admin SDK."""
###################################################################### ######################################################################
import hashlib
import logging import logging
import os import os
from datetime import datetime, timezone from datetime import datetime, timezone
@@ -146,15 +145,19 @@ class Bucketlist(commands.Cog):
def __init__(self, bot: commands.Bot) -> None: def __init__(self, bot: commands.Bot) -> None:
self.bot = bot self.bot = bot
# build the subcollection path key from credentials # --- access control ---
bl_user = os.getenv("BUCKETLIST_USER", "") raw = os.getenv("BUCKETLIST_ACCESS", "")
bl_pass = os.getenv("BUCKETLIST_PASS", "") self._allowed: set[int] = {
combined = f"{bl_user}:{bl_pass}" int(uid.strip()) for uid in raw.split(",") if uid.strip()
self._hash = hashlib.sha256(combined.encode()).hexdigest() }
def _items_ref(self, db): def _items_ref(self, db):
"""Return the Firestore subcollection ref gated behind the credential hash.""" """Return the Firestore collection ref for bucketlist items."""
return db.collection("bucketlist_data").document(self._hash).collection("items") return db.collection("bucketlist")
def _check(self, user_id: int) -> bool:
"""Return True if the user is authorised to modify the bucketlist."""
return user_id in self._allowed
#this command lists all the bucketlist commands, not an actual bucketlist command## #this command lists all the bucketlist commands, not an actual bucketlist command##
@commands.command() @commands.command()
@@ -170,11 +173,15 @@ class Bucketlist(commands.Cog):
@commands.command(name="bucket") @commands.command(name="bucket")
async def bucket_cmd(self, ctx: commands.Context) -> None: async def bucket_cmd(self, ctx: commands.Context) -> None:
"""Send a button that opens the add-item form.""" """Send a button that opens the add-item form."""
if not self._check(ctx.author.id):
return await ctx.reply("You don't have access to the bucketlist.", delete_after=5)
await ctx.reply("Click below to add an item:", view=BucketButton()) await ctx.reply("Click below to add an item:", view=BucketButton())
@commands.command(name="unbucket") @commands.command(name="unbucket")
async def unbucket_cmd(self, ctx: commands.Context) -> None: async def unbucket_cmd(self, ctx: commands.Context) -> None:
"""Open a dropdown to pick and remove a bucketlist item.""" """Open a dropdown to pick and remove a bucketlist item."""
if not self._check(ctx.author.id):
return await ctx.reply("You don't have access to the bucketlist.", delete_after=5)
await self._unbucket_dropdown(ctx) await self._unbucket_dropdown(ctx)
async def _unbucket_dropdown(self, ctx: commands.Context) -> None: async def _unbucket_dropdown(self, ctx: commands.Context) -> None:
+1
View File
@@ -43,4 +43,5 @@ TIMESTAMP_FRIEND_987654321098765432=Japan
TIMESTAMP_FRIEND_555555555555555555=US East TIMESTAMP_FRIEND_555555555555555555=US East
#bucketlist access #bucketlist access
# users allowed to use !bucket / !unbucket (comma-separated Discord user IDs)
BUCKETLIST_ACCESS=123456789012345678 BUCKETLIST_ACCESS=123456789012345678