def promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": return "" if user_can_promote(chat, user, bot.id) is False: message.reply_text(tld(chat.id, "admin_no_promote_perm")) return "" if not chatD.get_member(bot.id).can_promote_members: message.reply_text(tld(chat.id, "admin_err_no_perm")) return "" user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "common_err_no_user")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text(tld(chat.id, "admin_err_user_admin")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "admin_err_self_promote")) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chatD.get_member(bot.id) bot.promoteChatMember(chatD.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, can_invite_users=bot_member.can_invite_users, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages, can_promote_members=bot_member.can_promote_members) message.reply_text(tld(chat.id, "admin_promote_success").format( mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name), html.escape(chatD.title)), parse_mode=ParseMode.HTML) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#PROMOTED" \ f"\n<b>• Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>• User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
@run_async @bot_admin @user_admin @loggable def promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat if conn := connected(bot, update, chat, user.id): chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": return "" if user_can_promote(chat, user, bot.id) is False: message.reply_text(tld(chat.id, "admin_no_promote_perm")) return "" if not chatD.get_member(bot.id).can_promote_members: message.reply_text(tld(chat.id, "admin_err_no_perm")) return "" member = chatD.get_member(user.id) if not member.can_promote_members and member.status != 'creator': update.effective_message.reply_text( tld(chat.id, "admin_err_user_no_perm")) return "" user_id = extract_user(message, args) if not user_id:
def demote(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat message = update.effective_message user = update.effective_user conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": return "" if user_can_promote(chat, user, bot.id) is False: message.reply_text(tld(chat.id, "admin_no_promote_perm")) return "" if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text(tld(chat.id, "admin_err_no_perm")) return "" user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "common_err_no_user")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'creator': message.reply_text(tld(chat.id, "admin_err_demote_creator")) return "" if not user_member.status == 'administrator': message.reply_text(tld(chat.id, "admin_err_demote_noadmin")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "admin_err_self_demote")) return "" try: bot.promoteChatMember(int(chatD.id), int(user_id), can_change_info=False, can_post_messages=False, can_edit_messages=False, can_delete_messages=False, can_invite_users=False, can_restrict_members=False, can_pin_messages=False, can_promote_members=False) try: ADMIN_CACHE.pop(update.effective_chat.id) except Exception: pass message.reply_text(tld(chat.id, "admin_demote_success").format( mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name), html.escape(chatD.title)), parse_mode=ParseMode.HTML) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#DEMOTED" \ f"\n<b>• Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>• User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}" except BadRequest: message.reply_text(tld(chat.id, "admin_err_cant_demote")) return ""