diff --git a/README.md b/README.md index a3dd725..86363ab 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ A Telegram bot for interacting with the [WEEE-Open/grillo](https://github.com/WE git clone https://github.com/yourusername/grillo-bot.git cd grillo-bot python -m venv venv -source venv/bin/activate # On Windows: venv\Scripts\activate +source venv/bin/activate # On Windows: venv\Scripts\activate powershell: .\venv\Scripts\Activate.ps1 pip install -r requirements.txt cp .env.example .env # Edit .env with your tokens diff --git a/bot.py b/bot.py index 01e7c92..918fd1a 100644 --- a/bot.py +++ b/bot.py @@ -32,6 +32,7 @@ async def help(update: Update, context: ContextTypes.DEFAULT_TYPE, pre: str = "" "/status - Check current lab status\n" "/clockin - Clock in to the lab\n" "/clockout - Clock out from the lab\n" + "/ring - Ring the bell at a location\n" ) async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: @@ -136,6 +137,19 @@ async def clockout(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: logger.error(f"Error clocking out: {e}") await update.effective_message.reply_text(f"❌ Error clocking out: {str(e)}") +async def ring(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Ring the bell at a location.""" + # Precompute to use in exception handling too + location_id = " ".join(context.args) if context.args else "default" + grillo = get_user_client_by_telegram(update.effective_user.id) + success = grillo.ring_location(location_id) + if success[0]: + await update.effective_message.reply_text(f"🔔 Successfully rang the bell at location '{location_id}'.") + elif not success[0] and "error" in success[1]: + await update.effective_message.reply_text(f"❌ Error ringing the bell: {success[1]['error']}") + else: + await update.effective_message.reply_text(f"❌ Failed to ring the bell at location '{location_id}'.") + async def unknown_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: """Handle unknown commands.""" await update.effective_message.reply_text( @@ -168,6 +182,7 @@ def main() -> None: status, clockin, clockout, + ring, ] aliases = { "info": help, diff --git a/grillo_client.py b/grillo_client.py index 656fab7..c451fbd 100644 --- a/grillo_client.py +++ b/grillo_client.py @@ -115,7 +115,8 @@ def ring_location(self, location_id: str = "default") -> bool: Returns: True if successful """ - raise NotImplementedError("ring_location method not implemented yet.") + res = self._make_request("POST", f"/locations/{location_id}/ring") + return res.json().get("success", False), res.json() # Audit (lab time tracking) endpoints def get_audits(self, date_string: Optional[str] = None, user: Optional[str] = None) -> List[Dict[str, Any]]: