Exemplo n.º 1
0
 def handle(self):
     accounts = self.account_service.find(self.last_ran_before,
                                          self.runs_unchanged_min,
                                          self.runs_unchanged_max,
                                          self.prioritise)
     evntbus.emit(GotAccountsEvent(accounts))
     return accounts
Exemplo n.º 2
0
    def handle(self):
        account = self.account_service.find_one_by_slug(self.slug)
        if not account:
            raise NotFoundError('Account not found: {}'.format(self.slug))
        highscore = self.highscore_service.create(account, self.skills)
        evntbus.emit(HighScoreCreatedEvent(account, highscore))
        existing = self.highscore_service.find_by_xp_sum(
            account.id, highscore.calc_xp_sum()
        )
        now = datetime.utcnow()
        new_data = {
            'runs_unchanged': account.runs_unchanged + 1,
            'last_run_at': now,
        }
        if len(existing) == 1:
            new_data['run_changed_at'] = now
            new_data['runs_unchanged'] = 0
        updated = self.account_service.update_one([
            ['id', account.id]
        ], new_data)

        if not updated:
            raise RHError('Failed to update account')

        return highscore
Exemplo n.º 3
0
 def handle(self):
     highscore = cmdbus.dispatch(GetOsrsHighScoreCommand(self.nickname))
     if not highscore:
         raise ValueError('Account does not exist')
     account = self.account_service.create(self.nickname)
     evntbus.emit(AccountCreatedEvent(account))
     return account
Exemplo n.º 4
0
 def handle(self):
     account = self.account_service.find_one_by_slug(self.slug)
     if not account:
         raise NotFoundError('Account not found: {}'.format(self.slug))
     highscores = self.highscore_service.find(
         account.id, self.created_after, self.created_before, self.skills
     )
     evntbus.emit(GotHighScoresEvent(account, highscores))
     return highscores
Exemplo n.º 5
0
def test_decorator(event):
    evntbus.reset()

    @listen(type(event))
    def increment_v1(e):
        e.set_v1(2)

    assert event.get_v1() is 1
    evntbus.emit(event)
    assert event.get_v1() is 2
Exemplo n.º 6
0
def test_listen(event):
    evntbus.reset()

    def increment_v1(e):
        e.set_v1(2)

    evntbus.listen(type(event), increment_v1)
    assert event.get_v1() is 1
    evntbus.emit(event)
    assert event.get_v1() is 2
Exemplo n.º 7
0
 def handle(self):
     account = self.account_service.find_one_by_slug(self.slug)
     if not account:
         raise NotFoundError('Account not found: {}'.format(self.slug))
     highscore = self.highscore_service.find_one_by_account(
         account.id, self.id
     )
     if not highscore:
         raise NotFoundError('Highscore not found: {}'.format(self.id))
     evntbus.emit(GotHighScoreEvent(account, highscore))
     return highscore
Exemplo n.º 8
0
    def handle(self):
        account = self.account_service.find_one_by_slug(self.slug)
        if not account:
            raise NotFoundError('Account not found: {}'.format(self.slug))
        update_data = dict()
        valid_updates = ['nickname']
        for update in valid_updates:
            if update not in self.data:
                continue
            update_data[update] = self.data[update]

        if not len(update_data):
            raise ValueError('No updates specified')

        updated = self.account_service.update(account, update_data)
        if not updated:
            raise RHError('Unable to update account')
        evntbus.emit(AccountUpdatedEvent(account))
        return account
Exemplo n.º 9
0
def test_priorities(event):
    evntbus.reset()

    def increment_v1(e):
        val = e.get_v1()
        e.set_v1(val + 1)

    @listen(type(event), 4)
    def run_second(e):
        assert e.get_v1() is 2
        increment_v1(e)

    @listen(type(event))
    def run_first(e):
        assert e.get_v1() is 1
        increment_v1(e)

    assert event.get_v1() is 1
    evntbus.emit(event)
    assert event.get_v1() is 3
Exemplo n.º 10
0
 def handle(self):
     account = self.account_service.find_one_by_slug(self.slug)
     if not account:
         raise NotFoundError('Account not found: {}'.format(self.slug))
     evntbus.emit(GotAccountEvent(account))
     return account
Exemplo n.º 11
0
 def handle(self):
     jwt = self.jwt_service.make(self.user)
     evntbus.emit(JwtCreatedEvent(jwt))
     return jwt
Exemplo n.º 12
0
def test_emit_with_no_listeners(event):
    evntbus.reset()
    evntbus.emit(event)