Esempio n. 1
0
def give_reward_for_template(template):

    if template.author_id is None:
        print(1)
        return

    updated = prototypes.ContributionPrototype._db_filter(
        type=relations.CONTRIBUTION_TYPE.TEMPLATE,
        entity_id=template.id,
        account=template.author_id,
        reward_given=False).update(reward_given=True)

    if not updated:
        return

    cards_logic.give_new_cards(
        account_id=template.author_id,
        operation_type='give-card-for-linguistic-template',
        allow_premium_cards=True,
        available_for_auction=True)

    message = '''Поздравляем! Ваша [url={template}]фраза[/url] добавлена в игру!\n\nВ награду вы можете получить дополнительную карту судьбы (на странице игры). Карту можно будет продать на рынке.'''

    message = message.format(
        template=full_url('http', 'linguistics:templates:show', template.id))

    pm_tt_api.send_message(sender_id=accounts_logic.get_system_user_id(),
                           recipients_ids=[template.author_id],
                           body=message,
                           async=False)
Esempio n. 2
0
    def create_reject_request_message(self, initiator):
        message = '''
Игрок %(clan_leader_link)s отказал вам в принятии в гильдию %(clan_link)s.
''' % {'clan_leader_link': '[url="%s"]%s[/url]' % (full_url('http', 'accounts:show', initiator.id), initiator.nick_verbose),
       'clan_link': '[url="%s"]%s[/url]' % (full_url('http', 'accounts:clans:show', self.clan.id), self.clan.name)}

        pm_tt_api.send_message(sender_id=initiator.id,
                              recipients_ids=[self.account.id],
                              body=message)
Esempio n. 3
0
    def create_remove_member_message(self, initiator, removed_account):
        message = '''
Игрок %(clan_leader_link)s исключил вас из гильдии %(clan_link)s.
''' % {'clan_leader_link': '[url="%s"]%s[/url]' % (full_url('http', 'accounts:show', initiator.id), initiator.nick_verbose),
       'clan_link': '[url="%s"]%s[/url]' % (full_url('http', 'accounts:clans:show', self.id), self.name)}

        pm_tt_api.send_message(sender_id=initiator.id,
                              recipients_ids=[removed_account.id],
                              body=message)
Esempio n. 4
0
def reset_bans(context):

    context.master_account.reset_ban_forum()
    context.master_account.reset_ban_game()

    pm_tt_api.send_message(sender_id=logic.get_system_user_id(),
                          recipients_ids=[context.master_account.id],
                          body='С вас сняли все ограничения, наложенные ранее.')

    return dext_views.AjaxOk()
    def setUp(self):
        super(PersonalMessagesTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        pm_tt_api.send_message(self.account_1.id, [self.account_2.id],
                               'test text')

        self.message = MessagePrototype.get_priority_message()
Esempio n. 6
0
    def _confirm(self):
        self._model.is_confirmed = True
        self.save()

        account_link = '[url={}]{}[/url]'.format(
            full_url('http', 'accounts:show', self.friend_2.id),
            self.friend_2.nick_verbose)
        message = 'игрок {account_link} подтвердил, что вы являетесь друзьями'.format(
            account_link=account_link)

        pm_tt_api.send_message(sender_id=accounts_logic.get_system_user_id(),
                               recipients_ids=[self.friend_1.id],
                               body=message)
    def test_mail_send__to_system_user(self):
        from the_tale.accounts.logic import get_system_user

        Message.objects.all().delete()

        pm_tt_api.send_message(self.account_1.id, [get_system_user().id],
                               'test text')

        message = MessagePrototype.get_priority_message()

        self.assertEqual(len(mail.outbox), 0)
        message.process()
        self.assertTrue(message.state.is_PROCESSED)
        self.assertEqual(len(mail.outbox), 0)
Esempio n. 8
0
    def create_request_message(self, initiator):
        message = '''
Игрок %(account)s просит принять его в вашу гильдию:

%(text)s

----------
принять или отклонить предложение вы можете на этой странице: %(invites_link)s
''' % {'account': '[url="%s"]%s[/url]' % (full_url('http', 'accounts:show', self.account.id), self.account.nick_verbose),
       'text': self.text,
       'invites_link': '[url="%s"]Заявки в гильдию[/url]' % full_url('http', 'accounts:clans:membership:for-clan')}

        pm_tt_api.send_message(sender_id=initiator.id,
                              recipients_ids=[self.clan.get_leader().id],
                              body=message)
Esempio n. 9
0
    def create_invite_message(self, initiator):
        message = '''
Игрок %(clan_leader_link)s предлагает вам вступить в гильдию %(clan_link)s:

%(text)s

----------
принять или отклонить предложение вы можете на этой странице: %(invites_link)s
''' % {'clan_leader_link': '[url="%s"]%s[/url]' % (full_url('http', 'accounts:show', initiator.id), initiator.nick_verbose),
       'text': self.text,
       'clan_link': '[url="%s"]%s[/url]' % (full_url('http', 'accounts:clans:show', self.clan.id), self.clan.name),
       'invites_link': '[url="%s"]Приглашения в гильдию [/url]' % full_url('http', 'accounts:clans:membership:for-account')}

        pm_tt_api.send_message(sender_id=initiator.id,
                              recipients_ids=[self.account.id],
                              body=message)
Esempio n. 10
0
    def increment_level(self, send_message=False):
        self.level += 1

        self.add_message('hero_common_journal_level_up',
                         hero=self,
                         level=self.level)

        self.force_save_required = True

        if send_message:  # TODO: move out logic
            pm_tt_api.send_message(
                sender_id=accounts_logic.get_system_user_id(),
                recipients_ids=[self.account_id],
                body='Поздравляем, Ваш герой получил {} уровень!'.format(
                    self.level),
                async=True)
Esempio n. 11
0
    def on_process_transaction_frozen(self, **kwargs):
        lots = tt_api.close_lot(item_type=self.item_type,
                                price=self.price,
                                buyer_id=self.account_id)
        if not lots:
            self.custom_error = 'Не удалось купить карту: только что её купил другой игрок.'
            return False

        cards_tt_api.change_cards_owner(old_owner_id=accounts_logic.get_system_user_id(),
                                        new_owner_id=self.account_id,
                                        operation_type='#close_sell_lots',
                                        new_storage=cards_relations.STORAGE.FAST,
                                        cards_ids=[lot.item_id for lot in lots])

        cards_info = cards_logic.get_cards_info_by_full_types()

        lot = lots[0]

        lot_name = cards_info[lot.full_type]['name']

        # change receiver to lot owner

        invoice = self.transaction.get_invoice()

        invoice._model.recipient_type = bank_relations.ENTITY_TYPE.GAME_ACCOUNT
        invoice._model.recipient_id = lot.owner_id
        invoice._model.save()

        bank_prototypes.InvoicePrototype.create(recipient_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
                                                recipient_id=lot.owner_id,
                                                sender_type=bank_relations.ENTITY_TYPE.GAME_LOGIC,
                                                sender_id=0,
                                                currency=bank_relations.CURRENCY_TYPE.PREMIUM,
                                                amount=-logic.get_commission(self.price),
                                                description_for_sender='Комиссия с продажи «{}»'.format(lot_name),
                                                description_for_recipient='Комиссия с продажи «{}»'.format(lot_name),
                                                operation_uid='{}-cards-hero-good'.format(conf.payments_settings.MARKET_COMMISSION_OPERATION_UID, lot.full_type),
                                                force=True)

        pm_tt_api.send_message(sender_id=accounts_logic.get_system_user_id(),
                               recipients_ids=[lot.owner_id],
                               body=good_bought_message(name=lot_name, price=self.price - logic.get_commission(self.price)),
                               async=True)

        return True
Esempio n. 12
0
    def request_friendship(cls, friend_1, friend_2, text=None):
        own_request = cls._get_for(friend_1, friend_2)
        if own_request:
            if text is not None:  #
                own_request._model.text = text
                own_request.save()
            return own_request

        his_request = cls._get_for(friend_2, friend_1)
        if his_request:
            his_request._confirm()
            return his_request

        model = cls._model_class.objects.create(friend_1=friend_1._model,
                                                friend_2=friend_2._model,
                                                text=text)
        prototype = cls(model=model)

        message = '''
игрок %(account_link)s предлагает вам дружить:

%(text)s

----------
принять или отклонить предложение вы можете на этой странице: %(friends_link)s
''' % {
            'account_link':
            '[url="%s"]%s[/url]' % (full_url(
                'http', 'accounts:show', friend_1.id), friend_1.nick_verbose),
            'text':
            text,
            'friends_link':
            '[url="%s"]предложения дружбы[/url]' %
            full_url('http', 'accounts:friends:candidates')
        }

        # send message from name of user, who request friendship
        # since many users try to respod to system user
        pm_tt_api.send_message(sender_id=friend_1.id,
                               recipients_ids=[friend_2.id],
                               body=message)

        return prototype
Esempio n. 13
0
def portal_day_started(sender, **kwargs):
    accounts_query = AccountPrototype.live_query().filter(
        active_end_at__gt=datetime.datetime.now(),
        ban_game_end_at__lt=datetime.datetime.now(),
        ban_forum_end_at__lt=datetime.datetime.now(),
        premium_end_at__lt=datetime.datetime.now())

    accounts_number = accounts_query.count()
    if accounts_number < 1:
        return

    account = None

    for i in range(1000):
        account_model = accounts_query[random.randint(0, accounts_number - 1)]
        account = AccountPrototype(model=account_model)

        # explicity check for premium, since infinit subscribers does not filtered by previouse query
        if not account.is_premium:
            break
    else:
        return  # if not premium account does not found

    settings[portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY] = str(account.id)

    environment.workers.accounts_manager.cmd_run_account_method(
        account_id=account.id,
        method_name=AccountPrototype.prolong_premium.__name__,
        data={'days': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY})

    message = '''
Поздравляем!

Ваш герой выбран героем дня и Вы получаете %(days)d дней подписки!
''' % {
        'days': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY
    }

    pm_tt_api.send_message(sender_id=accounts_logic.get_system_user_id(),
                           recipients_ids=[account.id],
                           body=message,
                           async=True)
Esempio n. 14
0
def ban(context):

    if context.form.c.ban_type.is_FORUM:
        context.master_account.ban_forum(context.form.c.ban_time.days)
        message = 'Вы лишены права общаться на форуме. Причина: \n\n%(message)s'
    elif context.form.c.ban_type.is_GAME:
        context.master_account.ban_game(context.form.c.ban_time.days)
        message = 'Ваш герой лишён возможности влиять на мир игры. Причина: \n\n%(message)s'
    elif context.form.c.ban_type.is_TOTAL:
        context.master_account.ban_forum(context.form.c.ban_time.days)
        context.master_account.ban_game(context.form.c.ban_time.days)
        message = 'Вы лишены права общаться на форуме, ваш герой лишён возможности влиять на мир игры. Причина: \n\n%(message)s'
    else:
        raise dext_views.ViewError(code='unknown_ban_type', message='Неизвестный тип бана')

    pm_tt_api.send_message(sender_id=logic.get_system_user_id(),
                          recipients_ids=[context.master_account.id],
                          body=message % {'message': context.form.c.description})

    return dext_views.AjaxOk()
Esempio n. 15
0
    def remove_friendship(cls, initiator, friend):
        request = cls.get_for_bidirectional(initiator, friend)

        if request is None:
            return

        account_link = '[url="{}"]{}[/url]'.format(
            full_url('http', 'accounts:show', initiator.id),
            initiator.nick_verbose)

        if request.is_confirmed:
            message = 'игрок {account_link} удалил вас из списка друзей'.format(
                account_link=account_link)
        else:
            message = 'игрок {account_link} отказался добавить вас в список друзей'.format(
                account_link=account_link)

        pm_tt_api.send_message(sender_id=accounts_logic.get_system_user_id(),
                               recipients_ids=[friend.id],
                               body=message)

        request.remove()
Esempio n. 16
0
    def process(self, main_task):

        if self.step.is_INITIALIZE:

            if self.sender.is_fast:
                self.state = self.STATE.SENDER_IS_FAST
                self.step = self.STEP.ERROR
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if self.recipient.is_fast:
                self.state = self.STATE.RECIPIENT_IS_FAST
                self.step = self.STEP.ERROR
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if self.sender.is_ban_any:
                self.state = self.STATE.SENDER_BANNED
                self.step = self.STEP.ERROR
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if self.recipient.is_ban_any:
                self.state = self.STATE.RECIPIENT_BANNED
                self.step = self.STEP.ERROR
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            transfer_invoice = bank_prototypes.InvoicePrototype.create(
                recipient_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
                recipient_id=self.recipient_id,
                sender_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
                sender_id=self.sender_id,
                currency=bank_relations.CURRENCY_TYPE.PREMIUM,
                amount=self.amount,
                description_for_sender='Перевод игроку «%s»: «%s».' %
                (self.recipient.nick_verbose, self.comment),
                description_for_recipient='Перевод от игрока «%s»: «%s».' %
                (self.sender.nick_verbose, self.comment),
                operation_uid='transfer-money-between-accounts-transfer')

            self.transfer_transaction = bank_transaction.Transaction(
                transfer_invoice.id)

            commission_invoice = bank_prototypes.InvoicePrototype.create(
                recipient_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
                recipient_id=self.sender_id,
                sender_type=bank_relations.ENTITY_TYPE.GAME_LOGIC,
                sender_id=0,
                currency=bank_relations.CURRENCY_TYPE.PREMIUM,
                amount=-self.commission,
                description_for_sender='Комиссия с перевода игроку «%s»: «%s».'
                % (self.recipient.nick_verbose, self.comment),
                description_for_recipient=
                'Комиссия с перевода игроку «%s»: «%s».' %
                (self.recipient.nick_verbose, self.comment),
                operation_uid=conf.accounts_settings.COMMISION_TRANSACTION_UID)

            self.commission_transaction = bank_transaction.Transaction(
                commission_invoice.id)

            main_task.extend_postsave_actions(
                (lambda: amqp_environment.environment.workers.refrigerator.
                 cmd_wait_task(main_task.id), ))

            self.step = self.STEP.WAIT
            return POSTPONED_TASK_LOGIC_RESULT.CONTINUE

        if self.step.is_WAIT:

            transfer_transaction_state = self.transfer_transaction.get_invoice_state(
            )
            commission_transaction_state = self.commission_transaction.get_invoice_state(
            )

            if transfer_transaction_state.is_REQUESTED:
                return POSTPONED_TASK_LOGIC_RESULT.WAIT

            if transfer_transaction_state.is_REJECTED:
                self.state = self.STATE.TRANSFER_TRANSACTION_REJECTED
                self.step = self.STEP.ERROR
                main_task.comment = 'invoice %d rejected' % self.transfer_transaction.invoice_id
                self.commission_transaction.cancel()
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if not transfer_transaction_state.is_FROZEN:
                self.state = self.STATE.TRANSFER_TRANSACTION_WRONG_STATE
                self.step = self.STEP.ERROR
                main_task.comment = 'invoice %d rejected' % self.transfer_transaction.invoice_id
                self.commission_transaction.cancel()
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if commission_transaction_state.is_REQUESTED:
                return POSTPONED_TASK_LOGIC_RESULT.WAIT

            if commission_transaction_state.is_REJECTED:
                self.state = self.STATE.COMMISSION_TRANSACTION_REJECTED
                self.step = self.STEP.ERROR
                main_task.comment = 'invoice %d rejected' % self.commission_transaction.invoice_id
                self.transfer_transaction.cancel()
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if not commission_transaction_state.is_FROZEN:
                self.state = self.STATE.COMMISSION_TRANSACTION_WRONG_STATE
                self.step = self.STEP.ERROR
                main_task.comment = 'invoice %d rejected' % self.commission_transaction.invoice_id
                self.transfer_transaction.cancel()
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if not (transfer_transaction_state.is_FROZEN
                    and commission_transaction_state.is_FROZEN):
                return POSTPONED_TASK_LOGIC_RESULT.WAIT

            self.transfer_transaction.confirm()
            self.commission_transaction.confirm()

            message = text = 'Игрок «{sender}» перевёл(-а) вам печеньки: {amount} шт. \n\n[quote]{comment}[/quote]'.format(
                sender=self.sender.nick_verbose,
                amount=self.amount,
                comment=self.comment)

            pm_tt_api.send_message(sender_id=logic.get_system_user_id(),
                                   recipients_ids=[self.recipient.id],
                                   body=message,
                                   async=True)

            self.state = self.STATE.PROCESSED
            self.step = self.STEP.SUCCESS
            return POSTPONED_TASK_LOGIC_RESULT.SUCCESS