From b347c106531e5c4bb632ff341d76cb2ba75c86a9 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 26 Apr 2022 12:21:37 +0200 Subject: [PATCH] fixed /setadmin function --- telegram_bot/api_handling/api_handler.py | 5 +++-- telegram_bot/bot.py | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index 181fd71..63cfcdf 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -9,6 +9,7 @@ __license__ = "None" #side-dependencies: none #Work in Progress +from email import header import sys import os import requests as r @@ -340,14 +341,14 @@ class API_Handler: Args: email (string): email of the user - is_admin (String): "true" if user should be Admin, "false" if not + is_admin (bool): "true" if user should be Admin, "false" if not Returns: int: status code """ with r.Session() as s: headers = {'Authorization': 'Bearer ' + self.token} # only bot token is needed, user is chosen by email - req = s.put(self.db_adress + "/user/setAdmin", json={"admin": str(is_admin),"email": str(email)}) + req = s.put(self.db_adress + "/user/setAdmin", json={"admin": is_admin,"email": str(email)}, headers=headers) return req.status_code diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 67baf98..331b29d 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -136,7 +136,7 @@ def set_admin(message): bot.reply_to(message, "You have to be an admin to use this command") return - bot.send_message(chat_id=user_id, text='send email and "true" if this account should have admin rights, else "false"\n in format: ,') # ask for email and admin rights to set + bot.send_message(chat_id=user_id, text='send email and true if this account should have admin rights, else false\n in format: ,') # request email and admin rights to change to bot.register_next_step_handler(message, set_admin_step) def set_admin_step(message): @@ -149,8 +149,11 @@ def set_admin_step(message): return email = args_message[0] - is_admin = args_message[1] - + is_admin = False # default: False + + if args_message[1].lower() == "true": # if user types true, set is_admin to true + is_admin = True + status = api_handler.set_admin(email, is_admin) # set admin in db if(status == 200):