Exemple #1
0
def __user_info__(user_id):
    gmuted = sql.is_user_gmuted(user_id)
    user = sql.get_gmuted_user(user_id)
    text =""

    if gmuted:
        text = "This user is currently globally muted."
        if user.reason:
            text += "\nReason: {}".format(html.escape(user.reason))
    return text
Exemple #2
0
def gmute_notification(update: Update, context: CallbackContext, user_id, should_message=False):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]
    user = context.bot.get_chat(user_id)
    user_r = sql.get_gmuted_user(user_id)
    
    
    chatmute_text = "User {} is currently globally muted and is silenced from {} with an " \
                   "immediate effect.".format(mention_html(user.id, user.first_name or "Deleted Account"), chat.title)
    
    if sql.is_user_gmuted(user_id):
        if user_r.reason:
            chatmute_text += "\n<b>Reason</b>: {}".format(user_r.reason)
                
        if should_message:
            try:
                msg.reply_text(chatmute_text, parse_mode=ParseMode.HTML)
            except:
                context.bot.send_message(chat.id, 
                                         chatmute_text, parse_mode=ParseMode.HTML)
                LOGGER.exception()
Exemple #3
0
def fmute(update: Update, context: CallbackContext):
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    args = message.text.split(" ")
    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 SUDO_USERS:
        message.reply_text("You're playing with fire! Sudo war is catastrophic.")
        return

    if int(user_id) in SUPPORT_USERS:
        message.reply_text("I can't silence a support user! Only my creator can!")
        return
    
    if int(user_id) in SUPER_ADMINS:
        message.reply_text("This is one of the super admin users appointed by the hierarchy. "
                           "Therefore, I can't touch this user!")
        return

    if user_id == context.bot.id:
        message.reply_text("Only my creator can decide the fate!")
        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:
            msg = "User {} is already globally muted; I'd change the reason, " \
                  "but you haven't given me one...".format(mention_html(user_chat.id, user_chat.first_name 
                                                                        or "Deleted Account"))

            message.reply_text(msg, parse_mode=ParseMode.HTML)
            return

        old_reason = sql.update_gmute_reason(user_id, user_chat.username or user_chat.first_name, reason)
        user_id, new_reason = extract_user_and_text(message, args)
        
        if old_reason == new_reason:
            same_reason = "User {} has already been globally muted, with the " \
                          "exact same reason.".format(mention_html(user_chat.id, user_chat.first_name or  
                                                                   "Deleted Account"))
            
            message.reply_text(same_reason, parse_mode=ParseMode.HTML)
            return
        
        if old_reason:
            muter = update.effective_user  # type: Optional[User]
            send_gmute = "<b>Emendation of Global mute</b>" \
                        "\n#GMUTE" \
                        "\n<b>Status:</b> <code>Amended</code>" \
                        "\n<b>Name:</b> {}".format(mention_html(user_chat.id, user_chat.first_name or 
                                                                "Deleted Account"))
    
            if user_chat.last_name:
                send_gmute += "\n<b>Surname:</b> {}".format(mention_html(user_chat.id, user_chat.last_name))
            
            if user_chat.username:
                send_gmute += "\n<b>Username:</b> @{}".format(html.escape(user_chat.username))
            
            if  user_chat:
                send_gmute += "\n<b>ID:</b> <code>{}</code>".format(user_chat.id)
            
            if muter.id in SUDO_USERS:
                send_gmute += "\n<b>Sudo:</b> {}".format(mention_html(muter.id, muter.first_name))
            
            if muter.id in SUPPORT_USERS:
                send_gmute += "\n<b>Support:</b> {}".format(mention_html(muter.id, muter.first_name))
            
            if reason:
                send_gmute += "\n<b>Previous:</b> {}".format(old_reason)
                send_gmute += "\n<b>Amended:</b> {}".format(new_reason)
            
            context.bot.send_message(chat_id=GBAN_LOG, text=send_gmute, parse_mode=ParseMode.HTML)
            old_msg = "User {} is already globally muted, for the following reason:\n" \
                      "<code>{}</code>\n" \
                      "I've gone and updated it with your new reason!".format(mention_html(user_chat.id, 
                                                                              user_chat.first_name or "Deleted Account"), 
                                                                              old_reason)

            message.reply_text(old_msg, parse_mode=ParseMode.HTML)
        
        else:
            muter = update.effective_user  # type: Optional[User]
            send_gmute = "<b>Emendation of Global mute</b>" \
                        "\n#GMUTE" \
                        "\n<b>Status:</b> <code>New reason</code>" \
                        "\n<b>Name:</b> {}".format(mention_html(user_chat.id, user_chat.first_name or 
                                                                "Deleted Account"))
    
            if user_chat.last_name:
                send_gmute += "\n<b>Surname:</b> {}".format(mention_html(user_chat.id, user_chat.last_name))
            
            if user_chat.username:
                send_gmute += "\n<b>Username:</b> @{}".format(html.escape(user_chat.username))
            
            if  user_chat:
                send_gmute += "\n<b>ID:</b> <code>{}</code>".format(user_chat.id)
            
            if muter.id in SUDO_USERS:
                send_gmute += "\n<b>Sudo:</b> {}".format(mention_html(muter.id, muter.first_name))
            
            if muter.id in SUPPORT_USERS:
                send_gmute += "\n<b>Support:</b> {}".format(mention_html(muter.id, muter.first_name))
            
            if reason:
                send_gmute += "\n<b>Reason:</b> {}".format(new_reason)
            
            context.bot.send_message(chat_id=GBAN_LOG, text=send_gmute, parse_mode=ParseMode.HTML)
            msg = "User {} is already globally muted, but had no reason set; " \
                  "I've gone and updated it!".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account"))

            message.reply_text(msg, parse_mode=ParseMode.HTML)

        return

    starting = "Starting global mutes for {}...".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account"))

    message.reply_text(starting, parse_mode=ParseMode.HTML)
    
    muter = update.effective_user  # type: Optional[User]
    send_gmute = "<b>Global mute</b>" \
                "\n#GMUTE" \
                "\n<b>Status:</b> <code>Enforced</code>" \
                "\n<b>Name:</b> {}".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account"))
    
    if user_chat.last_name:
        send_gmute += "\n<b>Surname:</b> {}".format(mention_html(user_chat.id, user_chat.last_name))
    
    if user_chat.username:
        send_gmute += "\n<b>Username:</b> @{}".format(html.escape(user_chat.username))
    
    if  user_chat:
        send_gmute += "\n<b>ID:</b> <code>{}</code>".format(user_chat.id)
    
    if muter.id in SUDO_USERS:
        send_gmute += "\n<b>Sudo:</b> {}".format(mention_html(muter.id, muter.first_name))
    
    if muter.id in SUPPORT_USERS:
        send_gmute += "\n<b>Support:</b> {}".format(mention_html(muter.id, muter.first_name))
    
    if reason:
        send_gmute += "\n<b>Reason:</b> {}".format(reason)
             

    context.bot.send_message(chat_id=GBAN_LOG, text=send_gmute, parse_mode=ParseMode.HTML)
    sql.gmute_user(user_id, user_chat.username or user_chat.first_name, reason)
    
    fmute_id = update.effective_chat  # type: Optional[Chat]
    chats = get_users_by_chat(fmute_id.id, user_id)
    for chat in chats:
        chat_id = chat.chat

        # Check if this group has disabled gmutes
        if not sql.does_chat_gmute(chat_id):
            continue

        try:
            context.bot.restrict_chat_member(update.effective_chat.id, int(user_id), MUTE_PERMISSIONS)
        except BadRequest as excp:
            if excp.message in GMUTE_ERRORS:
                pass
            else:
                message.reply_text("Could not fmute due to: {}".format(excp.message))
                sql.ungmute_user(user_id)
                return
        except TelegramError:
            pass
    
    silence_t = "User {} has been successfully globally muted".format(mention_html(user_chat.id, user_chat.first_name or 
                                                               "Deleted Account"))

    context.bot.send_message(chat_id=GBAN_LOG, text=silence_t, parse_mode=ParseMode.HTML)
    message.reply_text("User {} has been globally muted!".format(mention_html(user_chat.id, user_chat.first_name 
                                                            or "Deleted Account")), parse_mode=ParseMode.HTML)
Exemple #4
0
def welcome_gmute(update, context, user_id):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message
           
    if sql.is_user_gmuted(user_id):
        context.bot.restrict_chat_member(update.effective_chat.id, int(user_id), MUTE_PERMISSIONS)
Exemple #5
0
def ungmute(update: Update, context: CallbackContext):
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    args = message.text.split(" ")

    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 = context.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):
        msg = "User {} is not globally muted!".format(mention_html(user_chat.id, user_chat.first_name 
                                                                         or "Deleted Account"))
        
        message.reply_text(msg, parse_mode=ParseMode.HTML)
        return

    muter = update.effective_user  # type: Optional[User]

    message.reply_text("Removing {} from global mutes.".format(user_chat.first_name or "Deleted Account"))

    send_gmute = "<b>Regression of Global mute</b>" \
                "\n#GMUTE" \
                "\n<b>Status:</b> <code>Ceased</code>" \
                "\n<b>Name:</b> {}".format(mention_html(user_chat.id, user_chat.first_name or "Deleted Account"))
    
    if user_chat.last_name:
        send_gmute += "\n<b>Surname:</b> {}".format(mention_html(user_chat.id, user_chat.last_name))
    
    if user_chat.username:
        send_gmute += "\n<b>Username:</b> @{}".format(html.escape(user_chat.username))
    
    if  user_chat:
        send_gmute += "\n<b>ID:</b> <code>{}</code>".format(user_chat.id)
    
    if muter.id in SUDO_USERS:
        send_gmute += "\n<b>Sudo:</b> {}".format(mention_html(muter.id, muter.first_name))
    
    if muter.id in SUPPORT_USERS:
        send_gmute += "\n<b>Support:</b> {}".format(mention_html(muter.id, muter.first_name))
            
   
    context.bot.send_message(chat_id=GBAN_LOG, text=send_gmute, parse_mode=ParseMode.HTML)
    
    unfmute_id = update.effective_chat  # type: Optional[Chat]
    chats = get_users_by_chat(unfmute_id.id, user_id)
    for chat in chats:
        chat_id = chat.chat

        # 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 == 'kicked':
                context.bot.restrict_chat_member(update.effective_chat.id, int(user_id), UNMUTE_PERMISSIONS)

        except BadRequest as excp:
            if excp.message in UNGMUTE_ERRORS:
                pass
            else:
                message.reply_text("Could not un-gmute due to: {}".format(excp.message))
                context.bot.send_message(OWNER_ID, "Could not un-gmute due to: {}".format(excp.message))
                return
        except TelegramError:
            pass

    sql.ungmute_user(user_id)
    
    silence_t = "User {} has been pardoned from global mutes.".format(mention_html(user_chat.id, user_chat.first_name or 
                                                                                     "Deleted Account"))
    
    context.bot.send_message(chat_id=GBAN_LOG, text=silence_t, parse_mode=ParseMode.HTML)
    message.reply_text("User {} has been pardoned from global mutes.".format(mention_html(user_chat.id, user_chat.first_name 
                                                               or "Deleted Account")), parse_mode=ParseMode.HTML)