def user_demote_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed owner can do this!")) return msg = update.effective_message # type: Optional[Message] user_id = extract_user(msg, args) if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "I can't extract a user from this.")) return #else: # return if user_id == bot.id: update.effective_message.reply_text( tld( chat.id, "What are you trying to do? Demoting me from your federation?") ) return if sql.search_user_in_fed(fed_id, user_id) == False: update.effective_message.reply_text( tld( chat.id, "I can't demote user which not a fed admin! If you wanna bring him to tears, promote him first!" )) return res = sql.user_demote_fed(fed_id, user_id) if res == True: update.effective_message.reply_text(tld(chat.id, "Get out of here!")) else: update.effective_message.reply_text( tld(chat.id, "I can not remove him, I am powerless!"))
def user_demote_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_user fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id): msg = update.effective_message user_id = extract_user(msg, args) if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "common_err_no_user")) return else: LOGGER.warning('error') if user_id == bot.id: update.effective_message.reply_text(tld(chat.id, "feds_demote_bot")) return if sql.search_user_in_fed(fed_id, user_id) == False: update.effective_message.reply_text( tld(chat.id, "feds_demote_target_not_admin")) return res = sql.user_demote_fed(fed_id, user_id) if res == True: update.effective_message.reply_text( tld(chat.id, "feds_demote_success")) else: update.effective_message.reply_text( tld(chat.id, "feds_demote_failed")) else: update.effective_message.reply_text(tld(chat.id, "feds_owner_only")) return
def user_demote_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id): msg = update.effective_message # type: Optional[Message] user_id = extract_user(msg, args) if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and (not args or ( len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities( [MessageEntity.TEXT_MENTION]))): msg.reply_text("I cannot extract users from this message") return else: LOGGER.warning('error') if user_id == bot.id: update.effective_message.reply_text("Are you trying to demote me as a federation admin? Do you think I am stupid?") return if sql.search_user_in_fed(fed_id, user_id) == False: update.effective_message.reply_text("I cannot demote people who are not federation admins!") return res = sql.user_demote_fed(fed_id, user_id) if res == True: update.effective_message.reply_text("Get out of here!") else: update.effective_message.reply_text("Demotion failed!") else: update.effective_message.reply_text("Only federation owners can do this!") return