def unmute(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) == False: message.reply_text("You don't have enough rights to unmute people") return "" user_id = extract_user(message, args) if not user_id: message.reply_text( "You'll need to either give me a username to unmute, or reply to someone to be unmuted." ) return "" member = chat.get_member(int(user_id)) if member.status != "kicked" and member.status != "left": if ( member.can_send_messages and member.can_send_media_messages and member.can_send_other_messages and member.can_add_web_page_previews ): message.reply_text("This user already has the right to speak.") else: 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, ), ) message.reply_text("Yep! this user can start talking again...") return ( "<b>{}:</b>" "\n#UNMUTE" "\n<b>Admin:</b> {}" "\n<b>User:</b> {}".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), ) ) else: message.reply_text( "This user isn't even in the chat, unmuting them won't make them talk more than they " "already do!" ) return ""
def kick(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) is False: message.reply_text("You don't have enough rights to kick users!") return "" user_id, reason = extract_user_and_text(message, args) if not user_id: return "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return "" else: raise if is_user_ban_protected(chat, user_id): message.reply_text("Yeahh... let's start kicking admins?") return "" if user_id == context.bot.id: message.reply_text("Yeahhh I'm not gonna do that") return "" res = chat.unban_member(user_id) # unban on current user = kick if res: # context.bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker context.bot.sendMessage( chat.id, "Untill we meet again {}.".format( mention_html(member.user.id, member.user.first_name)), parse_mode=ParseMode.HTML, ) log = ("<b>{}:</b>" "\n#KICKED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {} (<code>{}</code>)".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id, )) if reason: log += "\n<b>Reason:</b> {}".format(reason) return log else: message.reply_text("Get Out!.") return ""
def unmute(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) == False: message.reply_text( "Non hai i permessi sufficienti per smutare qualcuno!") return "" user_id = extract_user(message, args) if not user_id: message.reply_text( "Per ora non posso leggerti la mente per sapere chi smutare perciò almeno dimmi chi smutare." ) return "" member = chat.get_member(int(user_id)) if member.status != "kicked" and member.status != "left": if (member.can_send_messages and member.can_send_media_messages and member.can_send_other_messages and member.can_add_web_page_previews): message.reply_text("Questo utente non è mutato, genio.") else: 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, ), ) message.reply_text( "Ok hai il diritto di parlare ma non cagare il cazzo per evitare un altro mute" ) return ("<b>{}:</b>" "\n#UNMUTE" "\n<b>Admin:</b> {}" "\n<b>Utente:</b> {}".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), )) else: message.reply_text("ma sei scemo?" "L'utente non è nel gruppo!") return ""
def mute(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) == False: message.reply_text( "Non hai i permessi sufficienti per mutare qualcuno!") return "" user_id = extract_user(message, args) if not user_id: message.reply_text( "Sei quello intelligente della famiglia vero? devi specificarmi l'utente da mutare." ) return "" if user_id == context.bot.id: message.reply_text( "Ho capito che magari ti sto antipatico ma non mi muterò mai da solo!" ) return "" member = chat.get_member(int(user_id)) if member: if is_user_admin(chat, user_id, member=member): message.reply_text( "Beh per mutare un admin dovrei avere i superpoteri") elif member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member( chat.id, user_id, permissions=ChatPermissions(can_send_messages=False)) message.reply_text("Ok ora statti zitto🤐") return ("<b>{}:</b>" "\n#MUTE" "\n<b>Admin:</b> {}" "\n<b>Utente:</b> {}".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), )) else: message.reply_text("Beh questo utente è gia mutato 🤐") else: message.reply_text("Ma sei scemo? l'utente non è presente nel gruppo!") return ""
def mute(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) == False: message.reply_text( "You don't have enough rights to restrict someone from talking!" ) return "" user_id = extract_user(message, args) if not user_id: message.reply_text( "You'll need to either give me a username to mute, or reply to someone to be muted." ) return "" if user_id == context.bot.id: message.reply_text("Yeahh... I'm not muting myself!") return "" member = chat.get_member(int(user_id)) if member: if is_user_admin(chat, user_id, member=member): message.reply_text("Well i'm not gonna stop an admin from talking!") elif member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member( chat.id, user_id, permissions=ChatPermissions(can_send_messages=False) ) message.reply_text("👍🏻 muted! 🤐") return ( "<b>{}:</b>" "\n#MUTE" "\n<b>Admin:</b> {}" "\n<b>User:</b> {}".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), ) ) else: message.reply_text("This user is already taped 🤐") else: message.reply_text("This user isn't in the chat!") return ""
def unban(update, context): message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] args = context.args if user_can_ban(chat, user, context.bot.id) is False: message.reply_text( "You don't have enough rights to unban people here!") return "" user_id, reason = extract_user_and_text(message, args) if not user_id: return "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return "" else: raise if user_id == context.bot.id: message.reply_text("How would I unban myself if I wasn't here...?") return "" if is_user_in_chat(chat, user_id): message.reply_text( "Why are you trying to unban someone who's already in this chat?") return "" chat.unban_member(user_id) message.reply_text("Done, they can join again!") log = ("<b>{}:</b>" "\n#UNBANNED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {} (<code>{}</code>)".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id, )) if reason: log += "\n<b>Reason:</b> {}".format(reason) return log
def ban(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) is False: message.reply_text("You don't have enough rights to ban users!") return "" user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("Hey ! Please atleast refer some user to ban!") return "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return "" else: raise if is_user_ban_protected(chat, user_id, member): message.reply_text("I'm not gonna ban an admin ! Lol ") return "" if user_id == context.bot.id: message.reply_text("I'm not gonna Ban myself, are you crazy ?") return "" log = ("<b>{}:</b>" "\n#BANNED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {} (<code>{}</code>)".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id, )) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: chat.kick_member(user_id) # context.bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker context.bot.sendMessage( chat.id, "{} Got Crushed By Ban Hammer !".format( mention_html(member.user.id, member.user.first_name)), parse_mode=ParseMode.HTML, ) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text("Banned!", quote=False) return log else: LOGGER.warning(update) LOGGER.exception( "ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message, ) message.reply_text("Well damn, I can't ban that user.") return ""
def temp_ban(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) is False: message.reply_text( "You don't have enough rights to temporarily ban someone!") return "" user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("Hey ! Please atleast refer some user to ban...") return "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return "" else: raise if is_user_ban_protected(chat, user_id, member): message.reply_text("Wew! let's start banning Admins themselves?...") return "" if user_id == context.bot.id: message.reply_text("I'm not gonna Ban myself, are you crazy ?") return "" if not reason: message.reply_text( "You haven't specified a time to ban this user for!") return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" bantime = extract_time(message, time_val) if not bantime: return "" log = ("<b>{}:</b>" "\n#TEMP BANNED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {} (<code>{}</code>)" "\n<b>Time:</b> {}".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id, time_val, )) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: chat.kick_member(user_id, until_date=bantime) # context.bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker message.reply_text( "Banned! User will be banned for {}.".format(time_val)) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text("Bye.. we'll meet after {} !".format(time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception( "ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message, ) message.reply_text("Well damn, I can't ban that user.") return ""
def temp_mute(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) == False: message.reply_text( "You don't have enough rights to restrict someone from talking!") return "" 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 "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("I can't seem to find this user") return "" else: raise if is_user_admin(chat, user_id, member): message.reply_text("I really wish I could mute admins...") return "" if user_id == context.bot.id: message.reply_text("I'm not gonna MUTE myself, are you crazy?") return "" if not reason: message.reply_text( "You haven't specified a time to mute this user for!") return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" mutetime = extract_time(message, time_val) if not mutetime: return "" log = ("<b>{}:</b>" "\n#TEMP MUTED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {}" "\n<b>Time:</b> {}".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), time_val, )) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: if member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member( chat.id, user_id, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False), ) message.reply_text("shut up! 🤐 Taped for {}!".format(time_val)) return log else: message.reply_text("This user is already muted.") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text("shut up! 🤐 Taped for {}!".format(time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception( "ERROR muting user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message, ) message.reply_text("Well damn, I can't mute that user.") return ""
def temp_mute(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args if user_can_ban(chat, user, context.bot.id) == False: message.reply_text("Non hai abbastanza permessi per mutare scemo!") return "" user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("O sono scemo io o lo sei tu, DIMMI CHI MUTARE.") return "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "Non ho trovato questo utente forse ho bisogno di un nuovo paio di occhiali, oppure tu hai bisogno di un nuovo cervello": message.reply_text("Non trovo questo utente") return "" else: raise if is_user_admin(chat, user_id, member): message.reply_text("Perchè cazzo dovrei mutare un admin") return "" if user_id == context.bot.id: message.reply_text("Te lo scordi, non mi muterò mai da solo?") return "" if not reason: message.reply_text("Almeno dimmi per quanto mutarlo!") return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" mutetime = extract_time(message, time_val) if not mutetime: return "" log = ("<b>{}:</b>" "\n#TEMP MUTED" "\n<b>Admin:</b> {}" "\n<b>Utente:</b> {}" "\n<b>Tempo:</b> {}".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), time_val, )) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: if member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member( chat.id, user_id, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False), ) message.reply_text( "zitto coglione! 🤐 sarai mutato per {}!".format(time_val)) return log else: message.reply_text("questo utente è gia mutato.") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text( "Statti zitto coglione! 🤐 imarrai muto per {}!".format( time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception( "ERROR muting user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message, ) message.reply_text("Non riesco a mutare questo utente.") return ""