def check_and_mute(update, user_id, should_message=True): if sql.is_user_gmuted(user_id): context.bot.restrict_chat_member(update.effective_chat.id, user_id, can_send_messages=False) if should_message: update.effective_message.reply_text( "This is a bad person, I'll silence them for you!")
def __user_book__(user_id): is_gmuted = sql.is_user_gmuted(user_id) text = "<b>Globally Muted : </b>{}" if user_id == dispatcher.bot.id: return "" if int(user_id) in OFFICERS: return "" if is_gmuted: text = text.format("Yes") user = sql.get_gmuted_user(user_id) if user.reason: text += "\nReason: {}".format(html.escape(user.reason)) else: text = text.format("No") return text
def __user_book__(user_id): is_gmuted = sql.is_user_gmuted(user_id) text = "<b>Globally Muted : </b>{}" if int(user_id ) in SUDO_USERS + DEV_USERS + SUPPORT_USERS + WHITELIST_USERS: text = text.format("❓") return text if is_gmuted: text = text.format("Yes") user = sql.get_gmuted_user(user_id) if user.reason: text += "\nReason: {}".format(html.escape(user.reason)) else: text = text.format("No") return text
def gmute(update, context): message = update.effective_message # type: Optional[Message] chat = update.effective_chat args = context.args user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return if int(user_id) in OFFICERS: message.reply_text("I Can't Gmute My Officer.") return if user_id == context.bot.id: message.reply_text("I can't gmute myself.") return if not reason: message.reply_text( "Please give a reason why are you want to gmute this user!") return try: user_chat = context.bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text("That's not a user!") return if sql.is_user_gmuted(user_id): if not reason: message.reply_text( "This user is already gmuted; I'd change the reason, but you haven't given me one..." ) return success = sql.update_gmute_reason( user_id, user_chat.username or user_chat.first_name, reason) if success: message.reply_text( "This user is already gmuted; I've gone and updated the gmute reason though!" ) else: message.reply_text("I thought this person was gmuted.") return message.reply_text("Gets duct tape ready 😉") muter = update.effective_user # type: Optional[User] sql.gmute_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gmutes if not sql.does_chat_gmute(chat_id): continue try: context.bot.restrict_chat_member( chat_id, user_id, permissions=ChatPermissions(can_send_messages=False)) except BadRequest as excp: if excp.message == "User is an administrator of the chat": pass elif excp.message == "Chat not found": pass elif excp.message == "Not enough rights to restrict/unrestrict chat member": pass elif excp.message == "User_not_participant": pass elif excp.message == "Peer_id_invalid": # Suspect this happens when a group is suspended by telegram. pass elif excp.message == "Group chat was deactivated": pass elif excp.message == "Need to be inviter of a user to kick it from a basic group": pass elif excp.message == "Chat_admin_required": pass elif excp.message == "Only the creator of a basic group can kick group administrators": pass elif excp.message == "Method is available only for supergroups": pass elif excp.message == "Can't demote chat creator": pass else: message.reply_text("Unexpected Error!") context.bot.send_message( ERROR_DUMP, "Could not gmute due to: {}".format(excp.message)) sql.ungmute_user(user_id) return except TelegramError: pass message.reply_text("They won't be talking again anytime soon.")
def ungmute(update, context): message = update.effective_message # type: Optional[Message] bot = context.bot args = context.args user_id = extract_user(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("That's not a user!") return if not sql.is_user_gmuted(user_id): message.reply_text("This user is not gmuted!") return muter = update.effective_user # type: Optional[User] message.reply_text("I'll let {} speak again, globally.".format( user_chat.first_name)) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gmutes if not sql.does_chat_gmute(chat_id): continue try: member = context.bot.get_chat_member(chat_id, user_id) if member.status == 'restricted': context.bot.restrict_chat_member( chat_id, int(user_id), permissions=ChatPermissions( can_send_messages=True, can_invite_users=True, can_pin_messages=True, can_send_polls=True, can_change_info=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, )) except BadRequest as excp: if excp.message == "User is an administrator of the chat": pass elif excp.message == "Chat not found": pass elif excp.message == "Not enough rights to restrict/unrestrict chat member": pass elif excp.message == "User_not_participant": pass elif excp.message == "Method is available for supergroup and channel chats only": pass elif excp.message == "Not in the chat": pass elif excp.message == "Channel_private": pass elif excp.message == "Chat_admin_required": pass else: message.reply_text("Unexpected Error!") bot.send_message( ERROR_DUMP, "Could not un-gmute due to: {}".format(excp.message)) return except TelegramError: pass sql.ungmute_user(user_id) message.reply_text("Person has been un-gmuted.")