Ejemplo n.º 1
0
def submit():
    """
    Submit one name.
    """
    # TODO captcha
    try:
        if request.form.get('name'):
            # egg
            name = _process_name(request.form.get('name'))
            database.add_name(name)
        elif request.form.get('fullname'):
            name = _process_name(request.form.get('fullname'))
            names = name.split(' ', 1)
            if len(names) == 1:
                # maybe accidental one name submission
                database.add_name(name)
            else:
                database.upvote_name(name, thumbs=0)
        else:
            raise ValueError()
    except ValueError:
        return egg(message='Naughty...')
    return egg(message=random.choice([
        'The scratching of ink to page...',
        'The words soak...',
        'That which is given, considered...',
        'A flutter of script...',
    ]))
Ejemplo n.º 2
0
def downLeader():
    command = request.form.get('command')
    if not command:
        return leaderboard(message="Hmm?")
    rotkey = session['rotkey']
    name = super_safe_decrypt(urllib.parse.unquote(request.form.get('name')), session['PREV_NONCE'] + rotkey)
    if command == 'flip':
        database.flip_leader(name)
        message = "The pages thrum with feedback..."
    elif command == 'down':
        database.upvote_name(name, thumbs=-1)
        message = "A judgement made, the Chosen shift..."
    else:
        message = "Hmm?"
    return leaderboard(message=message, patience=30)
Ejemplo n.º 3
0
def rate():
    """
    Rate a name.
    """
    name = request.form['name']
    rotkey = session['rotkey']
    name = super_safe_decrypt(urllib.parse.unquote(name), session['PREV_NONCE'] + rotkey)
    judgement = ord(request.form['judgement'])

    message = f'Your judgement is rendered.'
    if judgement == 128077:  # upvote
        database.upvote_name(name, thumbs=2)
        message += ' The Onomancer nods...'
    elif judgement == 128154:  # love
        database.upvote_name(name, thumbs=3)
        message += ' The Onomancer smiles...'
    elif judgement == 128148:  # hate
        database.upvote_name(name, thumbs=-2)
        message += ' The Onomancer frowns...'
    elif judgement == 128078:  # thumbs down
        database.upvote_name(name, thumbs=-1)
        message += ' The Onomancer stares...'

    return vote(message=message)
Ejemplo n.º 4
0
def collect():
    if request.method == 'POST':
        token = request.form['token']
        collection = [
            super_safe_decrypt(urllib.parse.unquote(name), token * 10)
            for name in json.loads(request.form['collection'])
        ]
        command = request.form['command']
        name_to_burn = 'name' in request.form and super_safe_decrypt(
            urllib.parse.unquote(request.form['name']),
            token * 10,
        )
        anim = {}
        if command == 'flip':
            flipped = ' '.join(name_to_burn.split(' ')[::-1])
            database.upvote_name(flipped, thumbs=0)
            collection[collection.index(name_to_burn)] = flipped
            anim = {'type': 'reverb', 'who': flipped}
        elif command == 'fire':
            rookie = database.collect(1)[0]
            collection[collection.index(name_to_burn)] = rookie
            anim = {'type': 'burning', 'who': rookie}
        elif command == 'reverb':
            collection = sorted(collection, key=lambda _: random.random())
            anim = {'type': 'reverb_all', 'who': None}
        elif command == 'fireworks':
            anim = {'type': 'burn_all', 'who': None}
            res = redirect(url_for('collect'))
            res.set_cookie('anim', json.dumps(anim), max_age=10)
            return res
        res = redirect(url_for(
            'collect',
            t=token[:8],
            f=_curse_collection(*collection),
        ))
        res.set_cookie('anim', json.dumps(anim), max_age=10)
        return res
    token = request.args.get('token') or request.args.get('t')
    if not token:
        token = secrets.token_hex(4)
        return redirect(url_for(
            'collect',
            t=token,
            f=_curse_collection(*database.collect()),
        ))

    anim = request.cookies.get('anim', {})
    if anim:
        anim = json.loads(anim)

    saves = {
        'save1': request.cookies.get('save1'),
        'save2': request.cookies.get('save2'),
        'save3': request.cookies.get('save3'),
    }
    # f is for friends
    if request.args.get('load'):
        loaded = saves[request.args['load']]
        collection = [
            (
                name,
                range(_curse_name(name)[0]),
                _curse_name(name)[1],
                '',
            )
            for name in _uncurse_collection(loaded)
        ]
    else:
        collection = [
            (
                name,
                range(_curse_name(name)[0]),
                _curse_name(name)[1],
                _get_animation(name, anim),
            )
            for name in _uncurse_collection(request.args['f'])
        ]
    friends = [n[0] for n in collection]
    friend_code = _curse_collection(*friends).decode()
    if request.args.get('save'):
        saves[request.args['save']] = friend_code
    if request.args.get('clear'):
        saves[request.args['clear']] = None
    res = make_response(render_template(
        'collect.html',
        lineup=collection[:9],
        rotation=collection[9:],
        message=random.choice([
            'A collection of chosen...',
            'Your hand...',
            'A drawing of pages...',
        ]),
        token=token * 10,
        collection=json.dumps([super_secret(n, token * 10) for n in friends]),
        friends=friend_code,
        saves=saves,
    ))
    if request.args.get('save'):
        res.set_cookie(request.args['save'], value=friend_code, max_age=100000000)
    if request.args.get('clear'):
        res.delete_cookie(request.args['clear'])
    return res
Ejemplo n.º 5
0
def annotate():
    message = 'The margins stained...'

    if request.method == 'POST':
        name = request.form['name']
        rotkey = session['rotkey']
        name = super_safe_decrypt(
            urllib.parse.unquote(name),
            session['PREV_NONCE'] + rotkey,
        )
        message = 'A note taken. '
        judgement = ord(request.form['judgement'])
        if judgement == 128072:  # left
            database.annotate_egg(name, first=1)
            message += 'The ink shifts left...'
        elif judgement == 128073:  # right
            database.annotate_egg(name, second=1)
            message += 'The ink shifts right...'
        elif judgement == 128588:
            database.annotate_egg(name, first=1, second=1)
            message += random.choice([
                'The ink swirls...',
                'The ink settles...',
            ])
        elif judgement == 128078:
            database.upvote_name(name, thumbs=-1)
            message += 'The ink fades...'
        elif judgement == 129335:
            message = 'The next line...'

        rotkey = secrets.token_urlsafe(100)
        session['rotkey'] = rotkey

    name = request.args.get('name', None)
    if not name:
        name = database.get_eggs(limit=1, rand=1)[0]
    else:
        rotkey = session['rotkey']
        if rotkey:
            name = super_safe_decrypt(name, session['USER_CSRF'] + rotkey)
        try:
            name = _process_name(name)
        except ValueError:
            name = database.get_eggs(limit=1, rand=1)[0]
            message = 'Naughty...'

    flag = 'flagForm' in request.args
    if flag:
        message = 'What is your reason for flagging this egg?'
    examples = {}
    if 'examples' in request.args:
        message = 'Observe context...'
        examples = database.get_annotate_examples(name)
    # rotkey already set by posts
    return make_response(render_template(
        'annotate.html',
        name=name,
        flag_form=flag,
        message=message,
        rotkey=session['USER_CSRF'] + session['rotkey'],
        examples=examples,
    ))
Ejemplo n.º 6
0
def collect():
    lineup_length = int(request.args.get('ll', 9))
    collection_length = lineup_length + int(request.args.get('rl', 5))
    settings = request.args.get('settings')
    slogan = request.args.get('say', random.choice([
        'A collection of chosen...',
        'Your hand...',
        'A drawing of pages...',
    ]))
    if collection_length > 50 or len(slogan) > 240:
        res = redirect(url_for('collect'))
        res.set_cookie('anim', json.dumps({'type': 'burn_all', 'who': None}), max_age=10)
        return res
    saves = {
        'save1': _parse_collection_cookie('save1'),
        'save2': _parse_collection_cookie('save2'),
        'save3': _parse_collection_cookie('save3'),
        'save4': _parse_collection_cookie('save4'),
        'save5': _parse_collection_cookie('save5'),
        'save6': _parse_collection_cookie('save6'),
        'save7': _parse_collection_cookie('save7'),
        'save8': _parse_collection_cookie('save8'),
        'save9': _parse_collection_cookie('save9'),
    }

    if request.method == 'POST':
        token = request.form['token']
        if request.form.get('load'):
            loaded = saves[request.form['load']]
            collection = _uncurse_collection(loaded[0])
            cname = loaded[1]
            lineup_length = loaded[2]
            collection_length = lineup_length + loaded[3]
            slogan = loaded[4] or 'What do they say?'
        else:
            collection = [
                super_safe_decrypt(urllib.parse.unquote(name), token * 10)
                for name in json.loads(request.form['collection'])
            ]
            slogan = request.form.get('say', slogan)
            lineup_length = int(request.form.get('lineup_length', 9))
            collection_length = lineup_length + int(request.form.get('rotation_length', 5))
            cname = 'Collection'
            if request.form.get('cname'):
                try:
                    cname = ' '.join([
                        _process_name(n) for n in request.form['cname'].split(' ')
                    ])
                except ValueError:
                    cname = 'Collection'
        anim = {}
        anchor = 'titleAnchor'
        if request.form.get('command'):
            command = request.form.get('command')
            name_to_burn = 'name' in request.form and super_safe_decrypt(
                urllib.parse.unquote(request.form['name']),
                token * 10,
            )
            idx = -1
            if command == 'flip':
                flipped = ' '.join(name_to_burn.split(' ')[::-1])
                database.upvote_name(flipped, thumbs=0)
                idx = collection.index(name_to_burn)
                collection[idx] = flipped
                anim = {'type': 'reverb', 'who': flipped}
            elif command == 'fire':
                rookie = database.collect(1)[0]
                idx = collection.index(name_to_burn)
                collection[idx] = rookie
                anim = {'type': 'burning', 'who': rookie}
            elif command == 'reverb':
                collection = sorted(collection, key=lambda _: random.random())
                anim = {'type': 'reverb_all', 'who': None}
            elif command == 'fireworks':
                anim = {'type': 'burn_all', 'who': None}
                res = redirect(url_for('collect'))
                res.set_cookie('anim', json.dumps(anim), max_age=10)
                return res
            elif command == 'feedback':
                stashed = Stash().bookmarked_guids()
                if not stashed:
                    rookie = database.collect(1)[0]
                else:
                    rookie = database.get_name_from_guid(random.choice(stashed))
                idx = collection.index(name_to_burn)
                collection[idx] = rookie
                anim = {'type': 'feedback', 'who': rookie}
            if idx >= lineup_length:
                anchor = 'rotationAnchor'
            elif idx >= 0:
                anchor = 'lineupAnchor'
            else:
                anchor = 'titleAnchor'

        friend_code = _curse_collection(*collection).decode()
        if request.form.get('clear'):
            saves[request.form['clear']] = None
        if request.form.get('save'):
            saves[request.form['save']] = (friend_code, cname)
        res = redirect(url_for(
            'collect',
            _anchor=anchor,
            t=token[:8],
            f=_curse_collection(*collection),
            cname=cname,
            ll=lineup_length,
            rl=collection_length - lineup_length,
            say=slogan,
        ))
        res.set_cookie('anim', json.dumps(anim), max_age=10)
        if request.form.get('save'):
            val = ':'.join([
                friend_code,
                cname,
                str(lineup_length),
                str(collection_length - lineup_length),
                slogan,
            ])
            res.set_cookie(request.form['save'], value=val, max_age=100000000)
        if request.form.get('clear'):
            res.delete_cookie(request.form['clear'])
        return res

    token = request.args.get('token') or request.args.get('t')
    if not token:
        token = secrets.token_hex(4)
        return redirect(url_for(
            'collect',
            t=token,
            f=_curse_collection(*database.collect(friends=collection_length)),
            ll=lineup_length,
            rl=collection_length - lineup_length,
        ))

    anim = request.cookies.get('anim', {})
    if anim:
        anim = json.loads(anim)
    cname = request.args.get('cname', '')

    # f is for friends
    collection = _load_collection(request.args['f'], anim=anim, lineup_length=lineup_length)

    if len(collection) < collection_length:
        names = database.collect(friends=collection_length - len(collection))
        collection.extend(_parse_collection_names(names, lineup_length=lineup_length))
    elif len(collection) > collection_length:
        collection = collection[:collection_length]

    friends = [n[0] for n in collection]

    friend_code = _curse_collection(*friends).decode()
    res = make_response(render_template(
        'collect.html',
        lineup=collection[:lineup_length],
        rotation=collection[lineup_length:],
        slogan=slogan,
        token=token * 10,
        collection=json.dumps([super_secret(n, token * 10) for n in friends]),
        friends=friend_code,
        saves=saves,
        cname=cname,
        rotation_length=collection_length - lineup_length,
        lineup_length=lineup_length,
        settings=settings,
        help=request.args.get('help', False),
    ))
    return res
Ejemplo n.º 7
0
def rate():
    """
    Rate a name.
    """
    name = request.form['name']
    rotkey = session['rotkey']
    name = super_safe_decrypt(urllib.parse.unquote(name), session['PREV_NONCE'] + rotkey)
    judgement = ord(request.form['judgement'])

    message = f'Your judgement is rendered.'
    stashed = Stash()
    if judgement == 128077:  # upvote
        database.upvote_name(name, thumbs=1)
        if request.form['reverse']:
            try:
                eggs = name.split(' ', 1)
                database.annotate_egg(eggs[0], first=1)
                database.annotate_egg(eggs[-1], second=1)
            except KeyError:
                pass
        message += ' The Onomancer nods...'
        stashed.increment_stat('👍')
    elif judgement == 128154:  # love
        database.upvote_name(name, thumbs=2)
        try:
            eggs = name.split(' ', 1)
            database.annotate_egg(eggs[0], first=1)
            database.annotate_egg(eggs[-1], second=1)
        except KeyError:
            pass
        message += ' The Onomancer smiles...'
        stashed.increment_stat('💚')
    elif judgement == 128148:  # hate
        database.upvote_name(name, thumbs=-2)
        flipped = ' '.join(name.split(' ')[::-1])
        database.upvote_name(flipped, thumbs=-2, hit_eggs=False)
        message += ' The Onomancer frowns...'
        stashed.increment_stat('💔')
    elif judgement == 128078:  # thumbs down
        flipped = ' '.join(name.split(' ')[::-1])
        database.upvote_name(flipped, thumbs=-1, hit_eggs=False)
        database.upvote_name(name, thumbs=-1)
        message += ' The Onomancer stares...'
        stashed.increment_stat('👎')

    res = vote(message=message, stashed=stashed)
    stashed.save(res)
    return res