user authorization for calendar added

This commit is contained in:
esef committed 2026-07-13 11:23:14 +03:00
1 parent f16d848e42
commit c66195d4cd
3 files changed
+17 -3

No files matched your search

+13 -2
View File
@@ -1,12 +1,12 @@
"""Calendar cog — modal-based booking, Firestore Admin SDK.""" """Calendar cog — modal-based booking, Firestore Admin SDK."""
###################################################################### ######################################################################
import logging import logging
import os
import re import re
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
import discord import discord
from discord.ext import commands from discord.ext import commands
from google.cloud.firestore import AsyncClient
from firebase_website import get_db from firebase_website import get_db
from .calendar_data import COUNTRY_TZ from .calendar_data import COUNTRY_TZ
@@ -141,19 +141,30 @@ class BookButton(discord.ui.View):
class Calendar(commands.Cog): class Calendar(commands.Cog):
"""Book events via a popup form.""" """Book events via a popup form — restricted to authorized users."""
def __init__(self, bot: commands.Bot) -> None: def __init__(self, bot: commands.Bot) -> None:
self.bot = bot self.bot = bot
raw = os.getenv("CALENDAR_USERS", "")
self._allowed: set[int] = {
int(uid.strip()) for uid in raw.split(",") if uid.strip()
}
def _check(self, user_id: int) -> bool:
return user_id in self._allowed
@commands.command(name="book") @commands.command(name="book")
async def book_cmd(self, ctx: commands.Context) -> None: async def book_cmd(self, ctx: commands.Context) -> None:
"""Send a button that opens the booking form.""" """Send a button that opens the booking form."""
if not self._check(ctx.author.id):
return await ctx.reply("You are not a maomao member.", delete_after=5)
await ctx.reply("Click below to book an event:", view=BookButton()) await ctx.reply("Click below to book an event:", view=BookButton())
@commands.command(name="unbook") @commands.command(name="unbook")
async def unbook_cmd(self, ctx: commands.Context, date: str = "", *, title: str = "") -> None: async def unbook_cmd(self, ctx: commands.Context, date: str = "", *, title: str = "") -> None:
"""Remove an event. Usage: !unbook DD-MM-YYYY Title""" """Remove an event. Usage: !unbook DD-MM-YYYY Title"""
if not self._check(ctx.author.id):
return await ctx.reply("You don't have access to the calendar.", delete_after=5)
if not DATE_RE.match(date) or not title.strip(): if not DATE_RE.match(date) or not title.strip():
return await ctx.reply("Usage: `!unbook 20-07-2026 Demo Review`") return await ctx.reply("Usage: `!unbook 20-07-2026 Demo Review`")
+3
View File
@@ -25,6 +25,9 @@ DEEPSEEK_API=lol you thought
# firebase service account (for Admin SDK) # firebase service account (for Admin SDK)
GOOGLE_APPLICATION_CREDENTIALS="/home/esef/discordbot/firebase-service-account.json" GOOGLE_APPLICATION_CREDENTIALS="/home/esef/discordbot/firebase-service-account.json"
# users allowed to use !book / !unbook (comma-separated Discord user IDs)
CALENDAR_USERS="id1,id2,id3"
#mis ids member speicific stuff #mis ids member speicific stuff
MELLO="" MELLO=""
FEROX="" FEROX=""
+1 -1
View File
@@ -1 +1 @@
this is what u get from google lol "this is what u get from google lol"