Exemplo n.º 1
0
def private_message_handler(BOT, update):
    telegram_user = update.message.from_user
    username = telegram_user.username
    name = telegram_user.full_name
    user_id = telegram_user.id
    group_chat_id = update.message.chat_id
    user = Bounter.get_bounter(telegram_id=user_id)
    '''
    if len(name) >= 39:
        update.message.reply_text("Your name is too long. You may not be able to participate in this dalecoin bounty program")
        return
    '''
    if user:
        if 'dalecoin.org' in name and user.is_active_bounter:
            pass
        elif 'dalecoin.org' in name and not user.is_active_bounter:
            user.is_active_bounter = True
            Bounter.break_point(user_id)
        elif user.is_active_bounter and not ('dalecoin.org' in name):
            Bounter.break_point(user_id, update_week=True)
            user.is_active_bounter = False
    elif 'dalecoin.org' in name:
        new_user = Bounter.add_bounter(user_id, name, username)
        new_user.is_active_bounter = True
    else:
        user = Bounter.add_bounter(user_id, name, username)

    address = update.message.text
    if address:
        if len(address.split(' ')) == 1 and address.startswith('0x'):
            user.eth_address = address
            update.message.reply_text(
                'ETH address has been updated successfully')

    db_commit()
Exemplo n.º 2
0
def handle_new_chat_member(BOT, update):
    if update.message.chat_id != BOUNTY_GROUP_ID:
        return
    telegram_user = telegram_user = update.message.from_user
    username = telegram_user.username
    name = telegram_user.full_name
    user_id = telegram_user.id
    group_chat_id = update.message.chat_id

    if len(name) >= 39:
        update.message.reply_text(
            "Your name is too long. You may not be able to participate in this dalecoin bounty program"
        )
        return

    user = Bounter.get_bounter(telegram_id=user_id)
    if user:
        if 'dalecoin.org' in name:
            Bounter.set_is_active_bounter(user_id, True)
            #Bounter.break_point(user_id, update_week=False)
        Bounter.break_point(user_id, update_week=False)
        #BOT.send_message(group_chat_id, "welcome")
        db_commit()
        return

    Bounter.add_bounter(user_id, name, username)
    db_commit()
Exemplo n.º 3
0
def group_message_handler(BOT, update):
    if update.message.chat_id != BOUNTY_GROUP_ID:
        return
    telegram_user = telegram_user = update.message.from_user
    username = telegram_user.username
    name = telegram_user.full_name
    user_id = telegram_user.id
    group_chat_id = update.message.chat_id
    user = Bounter.get_bounter(telegram_id=user_id)
    if len(name) >= 39:
        update.message.reply_text(
            "Your name is too long. You may not be able to participate in this dalecoin bounty program"
        )
        return
    if user:
        if 'dalecoin.org' in name and user.is_active_bounter:
            return
        elif 'dalecoin.org' in name and not user.is_active_bounter:
            user.is_active_bounter = True
            Bounter.break_point(user_id)
        elif user.is_active_bounter and not ('dalecoin.org' in name):
            Bounter.break_point(user_id, update_week=True)
            user.is_active_bounter = False
    elif 'dalecoin.org' in name:
        new_user = Bounter.add_bounter(user_id, name, username)
        new_user.is_active_bounter = True
    else:
        Bounter.add_bounter(user_id, name, username)

    db_commit()
Exemplo n.º 4
0
def handle_user_change_name(BOT, update):
    print(update.message)
    if update.message.chat_id != BOUNTY_GROUP_ID:
        return
    telegram_user = telegram_user = update.message.from_user
    username = telegram_user.username
    name = telegram_user.full_name
    user_id = telegram_user.id
    group_chat_id = update.message.chat_id
    user = Bounter.get_bounter(telegram_id=user_id)
    if user:
        if 'dalecoin.org' in name and user.is_active_bounter:
            return
        elif 'dalecoin.org' in name and not user.is_active_bounter:
            user.is_active_bounter = True
            Bounter.break_point(user_id)
        elif user.is_active_bounter and not ('dalecoin.org' in name):
            Bounter.break_point(user_id, update_week=True)
            user.is_active_bounter = False
    elif 'dalecoin.org' in name:
        new_user = Bounter.add_bounter(user_id, name, username)
        new_user.is_active_bounter = True
    else:
        Bounter.add_bounter(user_id, name, username)

    db_commit()
Exemplo n.º 5
0
def handle_bounty_command(BOT, update):
    """
    if update.message.chat_id != -201473564:
        return
    """
    telegram_user = telegram_user = update.message.from_user
    username = telegram_user.username
    name = telegram_user.full_name
    user_id = telegram_user.id
    group_chat_id = update.message.chat_id
    user = Bounter.get_bounter(telegram_id=user_id)
    """
    if user:
        t_diff = datetime.utcnow() - user.last_break_point
        print(t_diff.seconds)
        wks = Bounter.get_wks(user)
        bounty_status = 'active' if user.is_active_bounter else 'Not active'
        if not user.is_active_bounter:
            update.message.reply_text(f'Bounty status: {bounty_status}\nWeeks completed: {user.number_of_weeks_completed}')
            return
        update.message.reply_text(f'Bounty status: {bounty_status}\nWeeks completed: {wks}')
        return
    """
    update.message.reply_text(
        'Bounty has ended. Please check google sheet for bounty report.')
Exemplo n.º 6
0
def handle_user_left_chat(BOT, update):
    #if update.message.chat_id != -201473564:
    if update.message.chat_id != BOUNTY_GROUP_ID:
        return
    telegram_user = telegram_user = update.message.from_user
    username = telegram_user.username
    name = telegram_user.full_name
    user_id = telegram_user.id
    group_chat_id = update.message.chat_id
    user = Bounter.get_bounter(telegram_id=user_id)

    if user:
        Bounter.break_point(user_id, update_week=True)
        user.is_active_bounter = False
    db_commit()
Exemplo n.º 7
0
def scan_change_name(BOT, job):
    users = Bounter.query.all()
    user_ids = [user.telegram_id for user in users]
    all_users = [BOT.get_chat_member(BOUNTY_GROUP_ID, id) for id in user_ids]
    for user in all_users:
        try:
            name = user.user.full_name
            print(name)
            user_id = user.user.id
            bounter = Bounter.get_bounter(user_id)
            if len(name) >= 39:
                return
            if user.status == 'left':
                if bounter.is_active_bounter:
                    Bounter.break_point(user_id, update_week=True)
                    bounter.is_active_bounter = False
                    db_commit()
                    print(f"{name} is deactivated")
                continue
            if 'dalecoin.org' in name and bounter.is_active_bounter:
                #print(f"{name} is active")
                pass
            elif ('dalecoin.org' not in name) and bounter.is_active_bounter:
                Bounter.break_point(user_id, update_week=True)
                bounter.is_active_bounter = False
                db_commit()
                print(f"{name} is deactivated")

            elif 'dalecoin.org' in name and not bounter.is_active_bounter:
                Bounter.break_point(user_id)
                bounter.is_active_bounter = True
                db_commit()
                print(f"{name} is activated")

        except AttributeError as identifier:
            name = user.first_name
            print('no name')