예제 #1
0
파일: economy.py 프로젝트: eiritana/canvas
def level_up(user, only_once=True):
    from canvas.notifications.actions import Actions
    from canvas import last_sticker
    
    reward_stickers = 0

    while user.kv.sticker_inbox.get() >= sticker_schedule(user.kv.sticker_level.get()):
        sticker_level = user.kv.sticker_level.get()
        result = user.kv.sticker_inbox.increment_ifsufficient(-sticker_schedule(sticker_level))

        # If there weren't actually enough, the user was already rewarded in a different request. Update their
        # sticker data.
        if not result['success']:
            user_kv = user.redis.user_kv.hgetall()
            break

        user.kv.sticker_level.increment()
        reward = sticker_schedule(user.kv.sticker_level.get(), reward=True)
        user.kv.stickers.currency.increment(reward)
        reward_stickers += reward
        user_kv = user.redis.user_kv.hgetall()

        Actions.leveled_up(user, reward)
        
        if only_once:
            break
            
    if reward_stickers:
        realtime_update_sticker_counts(user)
        last_sticker.realtime_update_sticker_receipt(user)

    return reward_stickers
    def deliver(self, notification):
        if notification.action == 'invite_remixer':
            self.deliver_invite_remixer_message(notification)
        elif notification.action == 'invite_monster_remixer':
            self.deliver_invite_monster_remixer_message(notification)
        else:
            # Do the following for all types of stickering.
            last_sticker.set_sticker(notification.recipient, notification.comment_sticker)
            last_sticker.realtime_update_sticker_receipt(notification.recipient)

            # call appropriate function
            if notification.action == 'epic_stickered':
                self.deliver_epic_stickered_message(notification)
예제 #3
0
    def deliver(self, notification):
        if notification.action == 'invite_remixer':
            self.deliver_invite_remixer_message(notification)
        elif notification.action == 'invite_monster_remixer':
            self.deliver_invite_monster_remixer_message(notification)
        else:
            # Do the following for all types of stickering.
            last_sticker.set_sticker(notification.recipient,
                                     notification.comment_sticker)
            last_sticker.realtime_update_sticker_receipt(
                notification.recipient)

            # call appropriate function
            if notification.action == 'epic_stickered':
                self.deliver_epic_stickered_message(notification)