예제 #1
0
def update_warn(update,context):
    query = update.callback_query
    user_id = query.message.reply_to_message.from_user.id
    chat_id = query.message.reply_to_message.chat_id
    get_user = UserRepository().getUserByGroup([user_id,chat_id])
    get_group = GroupRepository().getById(chat_id)
    max_warn = get_group['max_warn']
    warn_count = get_user['warn_count'] if get_user is not None else 0
    if query.data == 'upWarn':
        if warn_count != max_warn:
            data_warn = [(user_id,chat_id)]
            UserRepository().updateWarn(data_warn)
            msg = 'You Upwarned: <a href="tg://user?id={}">{}</a>'.format(user_id,user_id)
            query.edit_message_text(msg, parse_mode='HTML')
        else:
            ban_user_by_id(update,context,user_id)
            msg = "The user has been banned because it has reached the maximum number of warns"
            query.edit_message_text(msg, parse_mode='HTML')
    if query.data == 'downWarn':
        if warn_count != 0:
            data_warn = [(user_id,chat_id)]
            UserRepository().downWarn(data_warn)
            msg = 'You Downwarned: <a href="tg://user?id={}">{}</a>'.format(user_id,user_id)
            query.edit_message_text(msg, parse_mode='HTML')
        else:
            msg = "The user cannot be downwarned anymore!"
            query.edit_message_text(msg, parse_mode='HTML')
    if query.data == 'removeWarn':
        data_warn = [(user_id,chat_id)]
        UserRepository().removeWarn(data_warn)
        msg = 'You have removed the Warns from user: <a href="tg://user?id={}">{}</a>'.format(user_id,user_id)
        query.edit_message_text(msg, parse_mode='HTML')
예제 #2
0
def init(update,context):
    text = update.message.text
    if update.message.reply_to_message:
        user = user_reply_object(update)
        row = UserRepository().getById(user.id)
        if row:
            message(update, context, text="<b>The user search returned the following results:</b>\nTelegram Id: <code>{}</code>\nUsername: {}\nLast Update: {}"
            .format(
                row['tg_id'],
                row['tg_username'],
                row['updated_at'].isoformat()
                ))
        else:
            message(update,context, text="The user is not present in the database")
    else:
        input_user_id = text[8:].strip().split(" ", 1)
        user_id = input_user_id[0]
        if user_id != "":
            row = UserRepository().getByUsername(user_id)
            if row:
                message(update, context, text="<b>The user search returned the following results:</b>\nTelegram Id: <code>{}</code>\nUsername: {}\nLast Update: {}"
                .format(
                    row['tg_id'],
                    row['tg_username'],
                    row['updated_at'].isoformat()
                    ))
            else:
                message(update,context, text="The user is not present in the database")
        else:
            message(update,context,"Attention the user id you entered does not exist!")
예제 #3
0
def save_user(member, chat):
    # Save the user in the database and check that it exists if it exists and has changed nickname overwrite
    user = UserRepository().getById(member.id)
    username = "******" + member.username
    default_count_warn = 0
    if user:
        data = [(username, member.id)]
        UserRepository().update(data)
    else:
        data = [(member.id, username, default_count_warn)]
        UserRepository().add(data)
    data_mtm = [(member.id, chat, default_count_warn)]
    UserRepository().add_into_mtm(data_mtm)
예제 #4
0
def get_owner_list() -> list:
    rows = UserRepository().getOwners()
    arr_owners = []
    for a in rows:
        owners = int(a['tg_id'])
        arr_owners.append(owners)
    return arr_owners
예제 #5
0
def mute_user_by_username_time(update,
                               context,
                               username,
                               value,
                               mute_time=3600):
    bot = context.bot
    chat = update.effective_chat.id
    user = UserRepository().getByUsername(username)
    if user is None:
        print('User not found')
    if value == True:
        mute = bot.restrict_chat_member(
            chat,
            user['tg_id'],
            ChatPermissions(can_send_messages=False,
                            can_send_media_messages=False,
                            can_send_other_messages=False,
                            can_add_web_page_previews=False),
            until_date=int(time.time() + mute_time))
    else:
        mute = bot.restrict_chat_member(
            chat,
            user['tg_id'],
            ChatPermissions(can_send_messages=True,
                            can_send_media_messages=True,
                            can_send_other_messages=True,
                            can_add_web_page_previews=True),
            until_date=int(time.time() + mute_time))
    return mute
예제 #6
0
def init(update, context):
    if update.message.reply_to_message:
        user = user_reply_object(update)
        user_id = user.id
        row = UserRepository().getOwnerById(user.id)
        if row:
            message(update, context,
                    "This owner already exists in the database")
        else:
            username = "******" + user.username
            data = [(user_id, username)]
            UserRepository().add_owner(data)
            message(update, context,
                    "You have entered a new owner in the database!")
    else:
        message(update, context,
                "Error! This command should be used in response to the user!")
예제 #7
0
def check_status(update,context):
    chat = chat_object(update)
    user = user_object(update)
    get_superban_user_id = update.effective_user.id
    user_db = UserRepository().getById(user.id)
    get_superban = SuperbanRepository().getById(get_superban_user_id)
    default_count_warn = 0
    get_group = GroupRepository().getById(chat.id)
    user_photo = user.get_profile_photos(user.id)
    user_set_photo = get_group['set_user_profile_picture']
    #warn_count = user_db['warn_count'] if user_db is not None else 0
    #max_warn = get_group['max_warn']
    #if warn_count == max_warn:
        #ban_user(update,context)
        #msg = "#Automatic Handler\n<code>{}</code> has reached the maximum number of warns"
        #message(update,context,msg.format(user.id))

    if user.username is None or "":
        kick_user(update, context)
        msg = "#Automatic Handler\n<code>{}</code> set a username! You were kicked for safety!"
        message(update,context,msg.format(user.id))
    if user_photo.total_count == 0 and user_set_photo == 1:
        kick_user(update, context)
        msg = "#Automatic Handler\n<code>{}</code> set a profile picture! You were kicked for safety!"
        message(update,context,msg.format(user.id))
    if user_db:
        username = "******"+user.username
        data = [(username,user.id)]
        UserRepository().update(data)
        data_mtm = [(user.id, chat.id, default_count_warn)]
        UserRepository().add_into_mtm(data_mtm)
    if user_db is None or "":
        username = "******"+user.username
        default_warn = 0
        data = [(user.id,username,default_warn)]
        UserRepository().add(data)
        data_mtm = [(user.id, chat.id, default_count_warn)]
        UserRepository().add_into_mtm(data_mtm)
    if get_superban:
        msg = 'I got super banned <a href="tg://user?id={}">{}</a>'.format(user.id,user.first_name)
        message(update,context,msg)
        delete_message(update,context)
        ban_user(update,context)
예제 #8
0
def init(update, context):
    user = user_reply_object(update)
    chat = chat_object(update)
    user_db = UserRepository().getById(user.id)
    get_warn = UserRepository().getUserByGroup([user.id, chat.id])
    default_warn = 0
    if user_db:
        username = "******" + user.username
        data = [(username, user.id)]
        UserRepository().update(data)
        warn_count = get_warn['warn_count']
        data_mtm = [(user.id, chat.id, default_warn)]
        UserRepository().add_into_mtm(data_mtm)
        msg = Strings.USER_INFO.format(id=user.id,
                                       username=user.username,
                                       chat=chat.title,
                                       warn=warn_count)
        PrivateMessage(update, context, msg)
    else:
        username = "******" + user.username
        data = [(user.id, username, default_warn)]
        UserRepository().add(data)
        data_mtm = [(user.id, chat.id, default_warn)]
        UserRepository().add_into_mtm(data_mtm)
        msg = Strings.USER_INFO.format(id=user.id,
                                       username=user.username,
                                       chat=chat.title,
                                       warn=default_warn)
        PrivateMessage(update, context, msg)
예제 #9
0
def init(update,context):
    chat = chat_object(update)
    get_group = GroupRepository().getById(chat.id)
    max_warn = get_group['max_warn']
    current_time = datetime.datetime.utcnow().isoformat()
    default_warn = 1
    languages(update,context)
    if update.message.reply_to_message:
        reason = update.message.text[5:]
        user = user_reply_object(update)
        get_user = UserRepository().getUserByGroup([user.id,chat.id])
        warn_count = get_user['warn_count'] if get_user is not None else 0
        if warn_count != max_warn:
            buttons = []
            buttons.append(InlineKeyboardButton('➖ 1', callback_data='downWarn'))
            buttons.append(InlineKeyboardButton('➕ 1', callback_data='upWarn'))
            buttons.append(InlineKeyboardButton(languages.button_remove, callback_data='removeWarn'))
            menu = build_menu(buttons,3)
            if get_user:
                default_warn_count = 0
                username = "******"+user.username
                data = [(username,current_time,user.id)]
                UserRepository().update(data)
                data_mtm = [(user.id, chat.id, default_warn_count)]
                UserRepository().add_into_mtm(data_mtm)
                data_warn = [(user.id,chat.id)]
                UserRepository().updateWarn(data_warn)
                if reason:
                    msg = languages.warn_with_reason.format(mention_html(user.id, user.first_name),chat.title,chat.id,reason)
                    update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML')
                else:
                    msg = languages.warn_user.format(mention_html(user.id, user.first_name),chat.title,chat.id)
                    update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML')
                log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>".format(mention_html(user.id, user.first_name),chat.title,chat.id)
                if reason:
                    log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>\nReason: {}".format(mention_html(user.id, user.first_name),chat.title,chat.id,reason)
                telegram_loggers(update,context,log_txt)
            else:
                username = "******"+user.username
                data = [(user.id,username,current_time,current_time)]
                UserRepository().add(data)
                data_mtm = [(user.id, chat.id, default_warn)]
                UserRepository().add_into_mtm(data_mtm)
                if reason:
                    message(update,context,languages.warn_with_reason.format(username,chat.title,chat.id,reason))
                else:
                    message(update,context,languages.warn_user.format(username,chat.title,chat.id))
                log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>".format(mention_html(user.id, user.first_name),chat.title,chat.id)
                if reason:
                    log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>\nReason: {}".format(mention_html(user.id, user.first_name),chat.title,chat.id,reason)
                telegram_loggers(update,context,log_txt)
        else:
            ban_user_reply(update,context)
            buttons = []
            buttons.append(InlineKeyboardButton('Remove', callback_data='removeWarn'))
            menu = build_menu(buttons,2)
            msg = languages.warn_user_max.format(user.username,chat.title)
            update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML')
    else:
        message(update,context,languages.error_response_user_msg)
예제 #10
0
def init(update, context):
    user = user_reply_object(update)
    chat = chat_object(update)
    get_user = UserRepository().getUserByGroup([user.id, chat.id])
    get_group = GroupRepository().getById(chat.id)
    warn_count = get_user['warn_count'] if get_user is not None else 0
    max_warn = get_group['max_warn']
    default_warn = 1

    if warn_count != max_warn:
        if get_user:
            default_warn_count = 0
            username = "******" + user.username
            data = [(username, user.id)]
            UserRepository().update(data)
            data_mtm = [(user.id, chat.id, default_warn_count)]
            UserRepository().add_into_mtm(data_mtm)
            data_warn = [(user.id, chat.id)]
            UserRepository().updateWarn(data_warn)
            message(
                update, context,
                "{} was warned by the group {}".format(username, chat.title))
            log_txt = "#Log {} was warned by the group {}".format(
                username, chat.title)
            telegram_loggers(update, context, log_txt)
        else:
            username = "******" + user.username
            data = [(user.id, username, default_warn)]
            UserRepository().add(data)
            data_mtm = [(user.id, chat.id, default_warn)]
            UserRepository().add_into_mtm(data_mtm)
            message(
                update, context,
                "{} was warned by the group {}".format(username, chat.title))
            log_txt = "#Log {} was warned by the group {}".format(
                username, chat.title)
            telegram_loggers(update, context, log_txt)
    else:
        ban_user_reply(update, context)
        message(
            update, context,
            "User @{} has reached the maximum number\n of warns in the {} group and has been banned"
            .format(user.username, chat.title))
예제 #11
0
파일: functions.py 프로젝트: mdnmdn/nebula8
def ban_user_by_username(update, context, username):
    bot = context.bot
    chat = update.effective_chat.id
    user = UserRepository().getByUsername(username)
    ban = bot.kick_chat_member(chat, user['tg_id'])
    return ban
예제 #12
0
def check_status(update, context):
    # Telegram Variables
    bot = context.bot
    chat = chat_object(update)
    user = user_object(update)
    get_superban_user_id = update.effective_user.id
    user_photo = user.get_profile_photos(user.id)

    #Get Group via Database
    get_group = GroupRepository().getById(chat.id)
    #Get User via Database
    user_db = UserRepository().getById(user.id)
    #Get User via Database in Many to Many Association
    get_user = UserRepository().getUserByGroup([user.id, chat.id])
    #Get User in Superban Table
    get_superban = SuperbanRepository().getById(get_superban_user_id)
    #Get User Warn
    warn_count = get_user[
        'warn_count'] if get_user is not None else DEFAULT_COUNT_WARN
    #Get Max Warn in group
    max_warn = get_group[
        'max_warn'] if get_group is not None else DEFAULT_MAX_WARN

    if get_group:
        user_set_photo = get_group['set_user_profile_picture']
        type_no_username = get_group['type_no_username']
    else:
        user_set_photo = 0
    #Check if the user has a username if he does not have a username I perform a temporary kick and check that the user is not a service account
    if update.effective_user.id == SERVICE_ACCOUNT:
        print("Service Account")
    elif user.username is None or user.username == "":
        if type_no_username == 1:
            kick_user(update, context)
            msg = "#Automatic Handler\n<code>{}</code> set an username! You were kicked for safety!"
            message(update, context, msg.format(user.id))
        elif type_no_username == 2:
            msg = "#Automatic Handler\n<code>{}</code> set an username!"
            message(update, context, msg.format(user.id))
        elif type_no_username == 3:
            mute_user_by_id(update, context, user.id, True)
            msg = "#Automatic Handler\n<code>{}</code> set an username! You were Muted for safety!"
            message(update, context, msg.format(user.id))
        elif type_no_username == 4:
            ban_user(update, context)
            msg = "#Automatic Handler\n<code>{}</code> was banned because they didn't have an username"
            message(update, context, msg.format(user.id))
        elif type_no_username == 5:
            kick_user(update, context)
        else:
            print("No action even if you don't have a username")
    else:
        #Check if the user exists on the database if it exists makes an update of his username and his latest update if not exist insert it
        if user_db:
            #Get the Current Time
            current_time = datetime.datetime.utcnow().isoformat()
            username = "******" + user.username
            data = [(username, current_time, user.id)]
            UserRepository().update(data)
            data_mtm = [(user.id, chat.id, DEFAULT_COUNT_WARN)]
            UserRepository().add_into_mtm(data_mtm)
        else:
            #Get the Current Time
            current_time = datetime.datetime.utcnow().isoformat()
            username = "******" + user.username
            data = [(user.id, username, current_time, current_time)]
            UserRepository().add(data)
            data_mtm = [(user.id, chat.id, DEFAULT_COUNT_WARN)]
            UserRepository().add_into_mtm(data_mtm)
    #Check if the user has a profile photo
    if user_photo.total_count == 0 and user_set_photo == 1:
        kick_user(update, context)
        msg = "#Automatic Handler\n<code>{}</code> set a profile picture! You were kicked for safety!"
        message(update, context, msg.format(user.id))
    #Check if the user has been blacklisted
    if get_superban:
        superban_reason = get_superban['motivation_text']
        msg = '#Automatic Handler\nI got super banned <a href="tg://user?id={}">{}</a> <code>[{}]</code>\nFor the following Reason: {}'.format(
            user.id, user.first_name, user.id, superban_reason)
        message(update, context, msg)
        delete_message(update, context)
        ban_user(update, context)
    #Check if the user has reached the maximum number of warns and ban him
    if warn_count == max_warn:
        ban_user(update, context)
        msg = "#Automatic Handler\n<code>{}</code> has reached the maximum number of warns"
        message(update, context, msg.format(user.id))

    if flood_manager.check_flood_wait(
            update) == 1 and get_group['set_antiflood'] == 1:
        bot.delete_message(update.effective_message.chat_id,
                           update.message.message_id)
        kick_user(update, context)
        msg = "#Automatic Handler\n<code>{}</code> has been kicked for flood".format(
            user.id)
        message(update, context, msg.format(user.id))