Ejemplo n.º 1
0
    def send_addition_sycee_via_mail(self, sycee):
        # XXX 充值额外赠送通过邮件发送
        drop = make_standard_drop_from_template()
        drop['sycee'] = sycee

        m = Mail(self.char_id)
        m.add(u"充值额外赠送", u"感谢您的充值,请领取额外赠送", attachment=json.dumps(drop))
Ejemplo n.º 2
0
def notify(payment_id):
    instance = Payment.objects.get(
        id=payment_id
    )
    user = instance.user
    order = instance.order

    context = {
        'order': order,
        'payment': instance,
        'user': user,
        'BASE_URL': BASE_URL
    }

    template = 'mail/payment.html'
    title = 'Подтверждение оплаты заказа № {public_id}'.format(
        public_id=order.public_id
    )
    mail = Mail(
        title=title,
        template=template,
        recipient=user.email,
        context=context
    )
    mail.send()
Ejemplo n.º 3
0
    def send_reward(self, goods_id):
        if goods_id == 1:
            # 不再有月卡
            mail_message = "char {0} try to buy goods: {1}".format(self.char_id, goods_id)
            mail_admins(mail_message, mail_message, fail_silently=True)
            return


        p = PURCHASE[goods_id]

        first = len(self.mongo_record.times) == 0

        buy_times = self.buy_times_of_this_goods(goods_id)
        is_first = buy_times == 0

        # if p.tp_obj.continued_days > 0:
        #     self.send_reward_yueka(goods_id, is_first)
        # else:
        #     self.send_reward_sycee(goods_id, is_first)

        self.send_reward_sycee(goods_id, is_first)

        self.mongo_record.times[str(goods_id)] = buy_times + 1
        self.mongo_record.save()

        self.send_notify()

        title = u'充值成功'
        content = u'获得了: {0}'.format(p.first_des if is_first else p.des)
        mail = Mail(self.char_id)
        mail.add(title, content)

        # 首冲奖励
        if first:
            self.send_first_reward()
Ejemplo n.º 4
0
def activatecode_use(request):
    char_id = request._char_id
    code_id = request._proto.code_id

    data = {'char_id': char_id, 'code_id': code_id}

    try:
        res = api_activatecode_use(data)
    except APIFailure:
        raise SanguoException(errormsg.SERVER_FAULT, char_id,
                              "ActivateCode Use",
                              "APIFailure. api_activatecode_use")

    if res['ret'] != 0:
        raise SanguoException(
            res['ret'], char_id, "ActivateCode use",
            "api_activatecode_use ret = {0}".format(res['ret']))

    # DONE
    package = res['data']['package']
    drop = get_drop_from_raw_package(package)

    mail = Mail(char_id)
    mail.add(ACTIVATECODE_MAIL_TITLE,
             ACTIVATECODE_MAIL_CONTENT,
             arrow.utcnow().format('YYYY-MM-DD HH:mm:ss'),
             attachment=json.dumps(drop))

    return None
Ejemplo n.º 5
0
    def send_reward(self, goods_id):
        p = PURCHASE[goods_id]

        first = len(self.mongo_record.times) == 0

        buy_times = self.mongo_record.times.get(str(goods_id), 0)
        is_first = buy_times == 0

        if p.tp_obj.continued_days > 0:
            self.send_reward_yueka(goods_id, is_first)
        else:
            self.send_reward_sycee(goods_id, is_first)

        self.mongo_record.times[str(goods_id)] = buy_times + 1
        self.mongo_record.save()

        self.send_notify()

        title = u'充值成功'
        content = u'获得了: {0}'.format(p.first_des if p.first_des else p.des)
        mail = Mail(self.char_id)
        mail.add(title, content)

        # 首冲奖励
        if first:
            self.send_first_reward()
Ejemplo n.º 6
0
def send_mail(request):
    data = request.body
    data = json.loads(data)

    char_ids = data.get('char_id', None)
    if char_ids:
        cids = char_ids
    else:
        chars = MongoCharacter.objects.all()
        cids = [c.id for c in chars]

    mail_name = data['mail']['name']
    mail_content = data['mail']['content']
    mail_send_at = data['mail']['send_at']

    attachment = data['mail'].get('attachment', '')
    if attachment:
        attachment = json.dumps(
            get_drop_from_raw_package(data['mail']['attachment'])
        )

    for cid in cids:
        m = Mail(cid)
        m.add(mail_name, mail_content, create_at=mail_send_at, attachment=attachment)

    return {'ret': 0}
Ejemplo n.º 7
0
def _vip_change(char_id, old_vip, new_vip, **kwargs):
    Prison(char_id).vip_changed(new_vip)
    m = Mail(char_id)
    m.add(name=MAIL_VIP_CHANGED_TITLE, content=MAIL_VIP_CHANGED_CONTENT.format(new_vip))

    # 增加掠夺次数
    plunder_times_change_value = VIP_FUNCTION[new_vip].plunder - VIP_FUNCTION[old_vip].plunder
    if plunder_times_change_value:
        plunder = Plunder(char_id)
        plunder.change_current_plunder_times(plunder_times_change_value, allow_overflow=True)

    vip_activies = []
    if has_activity(22001):
        vip_activies.append(22001)
    if has_activity(40007):
        vip_activies.append(40007)
    if has_activity(40008):
        vip_activies.append(40008)
    if has_activity(50006):
        vip_activies.append(50006)

    if vip_activies:
        ActivityStatic(char_id).send_update_notify(activity_ids=vip_activies)

    ae = ActivityEntry(char_id, 50006)
    if ae and ae.is_valid():
        ae.enable(new_vip)
        ActivityStatic(char_id).send_update_notify(activity_ids=[50006])
Ejemplo n.º 8
0
    def send_reward(self, goods_id):
        p = PURCHASE[goods_id]

        first = len(self.mongo_record.times) == 0

        buy_times = self.mongo_record.times.get(str(goods_id), 0)
        is_first = buy_times == 0

        if p.tp_obj.continued_days > 0:
            self.send_reward_yueka(goods_id, is_first)
        else:
            self.send_reward_sycee(goods_id, is_first)

        self.mongo_record.times[str(goods_id)] = buy_times + 1
        self.mongo_record.save()

        self.send_notify()

        title = u'充值成功'
        content = u'获得了: {0}'.format(p.first_des if p.first_des else p.des)
        mail = Mail(self.char_id)
        mail.add(title, content)

        # 首冲奖励
        if first:
            self.send_first_reward()
Ejemplo n.º 9
0
    def send_first_reward(self):
        standard_drop = get_drop(PURCHASE_FIRST_REWARD_PACKAGE_IDS)

        mail = Mail(self.char_id)
        mail.add(MAIL_PURCHASE_FIRST_TITLE,
                 MAIL_PURCHASE_FIRST_CONTENT,
                 attachment=json.dumps(standard_drop))
Ejemplo n.º 10
0
    def send_reward(self, goods_id):
        if goods_id == 1:
            # 不再有月卡
            mail_message = "char {0} try to buy goods: {1}".format(self.char_id, goods_id)
            mail_admins(mail_message, mail_message, fail_silently=True)
            return


        p = PURCHASE[goods_id]

        first = len(self.mongo_record.times) == 0

        buy_times = self.buy_times_of_this_goods(goods_id)
        is_first = buy_times == 0

        # if p.tp_obj.continued_days > 0:
        #     self.send_reward_yueka(goods_id, is_first)
        # else:
        #     self.send_reward_sycee(goods_id, is_first)

        self.send_reward_sycee(goods_id, is_first)

        self.mongo_record.times[str(goods_id)] = buy_times + 1
        self.mongo_record.save()

        self.send_notify()

        title = u'充值成功'
        content = u'获得了: {0}'.format(p.first_des if is_first else p.des)
        mail = Mail(self.char_id)
        mail.add(title, content)

        # 首冲奖励
        if first:
            self.send_first_reward()
Ejemplo n.º 11
0
def notify_new_user(payment_id, password):
    instance = Payment.objects.get(
        id=payment_id
    )
    user = instance.user
    order = instance.order
    print('Полученный пароль')
    print(password)

    context = {
        'order': order,
        'payment': instance,
        'user': user,
        'BASE_URL': BASE_URL,
        'password': password
    }

    template = 'mail/payment-new-user.html'
    title = 'Подтверждение оплаты заказа № {public_id}'.format(
        public_id=order.public_id
    )
    mail = Mail(
        title=title,
        template=template,
        recipient=user.email,
        context=context
    )
    mail.send()
Ejemplo n.º 12
0
def notify_created_user(pk, model, password):
    template = 'mail/club-price-created.html'

    try:
        user = User.objects.get(pk=pk)
    except ObjectDoesNotExist:
        user = None

    if user is None:
        pass

    else:
        instance = Product.objects.get(model=model)
        instance.set_club_price(user.marketing_group)
        sale = round(
            ((instance.price - instance.club_price) / instance.price) * 100)

        context = {
            'instance': instance,
            'user': user,
            'BASE_URL': BASE_URL,
            'return_url': instance.absolute_url,
            'sale': sale,
            'password': password
        }

        mail = Mail(title='Клубная цена',
                    template=template,
                    recipient=user.email,
                    context=context)
        mail.send()
Ejemplo n.º 13
0
    def send_reward_with_custom_price(self, goods_id, price):
        # 这里 price 是新台币,而且不一定是这个goods_id所对应的价格
        # 所以这里按照比例给东西
        p = PURCHASE[goods_id]

        xintaibi = p.rmb * 5

        buy_div, buy_mod = divmod(price, xintaibi)
        for i in xrange(buy_div):
            self.send_reward(goods_id)

        if buy_mod:
            # 换算成对应的元宝
            sycee = buy_mod * 2

            # 任意金额也要双倍!!!
            buy_times = self.buy_times_of_this_goods(goods_id)
            if buy_times == 0:
                actual_sycee = sycee * 2
            else:
                actual_sycee = sycee

            resource = Resource(self.char_id, "Purchase With Custom Price")
            resource.add(purchase_got=sycee, purchase_actual_got=actual_sycee)

            self.mongo_record.times[str(goods_id)] = buy_times + 1
            self.mongo_record.save()
            self.send_notify()

            title = u'充值成功'
            content = u'获得了 {0} 元宝'.format(actual_sycee)
            mail = Mail(self.char_id)
            mail.add(title, content)
Ejemplo n.º 14
0
    def cron_job(self):
        # 由系统的定时任务触发
        # linux cronjob 每天定时执行
        self.hang.used = 0
        self.hang.save()

        if self.hang_doing:
            stage_id = self.hang_doing.stage_id
            if not self.hang_doing.finished:
                # 到结算点就终止
                self.finish(set_hang=False)
        else:
            stage_id = max_star_stage_id(self.char_id)

        self.send_notify()

        remained = self.get_hang_remained()
        if remained and stage_id:
            stage = STAGES[stage_id]
            exp = remained / 15 * stage.normal_exp
            gold = remained / 15 * stage.normal_gold * 0.5
            standard_drop = make_standard_drop_from_template()
            standard_drop['exp'] = int(exp)
            standard_drop['gold'] = int(gold)

            m = Mail(self.char_id)
            m.add(
                HANG_RESET_MAIL_TITLE, HANG_RESET_MAIL_CONTENT,
                arrow.utcnow().to(
                    settings.TIME_ZONE).format('YYYY-MM-DD HH:mm:ss'),
                json.dumps(standard_drop))
Ejemplo n.º 15
0
    def cron_job(self):
        # 由系统的定时任务触发
        # linux cronjob 每天定时执行
        self.hang.used = 0
        self.hang.save()

        if self.hang_doing:
            stage_id = self.hang_doing.stage_id
            if not self.hang_doing.finished:
                # 到结算点就终止
                self.finish(set_hang=False)
        else:
            stage_id = max_star_stage_id(self.char_id)

        self.send_notify()

        remained = self.get_hang_remained()
        if remained and stage_id:
            stage = STAGES[stage_id]
            exp = remained / 15 * stage.normal_exp
            gold = remained / 15 * stage.normal_gold * 0.5
            standard_drop = make_standard_drop_from_template()
            standard_drop['exp'] = int(exp)
            standard_drop['gold'] = int(gold)

            m = Mail(self.char_id)
            m.add(
                HANG_RESET_MAIL_TITLE,
                HANG_RESET_MAIL_CONTENT,
                arrow.utcnow().to(settings.TIME_ZONE).format('YYYY-MM-DD HH:mm:ss'),
                json.dumps(standard_drop)
            )
Ejemplo n.º 16
0
    def trig(self):
        if not self.is_valid():
            return

        now = arrow.utcnow().to(settings.TIME_ZONE)
        if now.hour != 20:
            return

        date_str = now.format('YYYY-MM-DD')
        key = 'activity40006#{0}#{1}'.format(
            date_str, self.char_id
        )

        try:
            MongoKeyRecord.objects.get(id=key)
        except DoesNotExist:
            kr = MongoKeyRecord(id=key)
            kr.value = 1
            kr.save()

            m = Mail(self.char_id)
            m.add(
                self.activity_data.mail_title,
                self.activity_data.mail_content,
                attachment=json.dumps(get_drop([self.activity_data.package]))
            )
Ejemplo n.º 17
0
    def trig(self, *args):
        if not self.is_valid():
            return

        ac_record = ActivityConditionRecord(self.char_id, self.CONDITION_ID, self.activity_time)
        send_times = ac_record.send_times()

        if send_times >= 10:
            return

        condition = Q(char_id=self.char_id) & Q(purchase_at__gte=self.activity_time.nearest_open_date.timestamp) & Q(purchase_at__lte=self.activity_time.nearest_close_date.timestamp)
        logs = MongoPurchaseLog.objects.filter(condition)

        sycee_list = [log.sycee for log in logs if log.sycee >= self.CONDITION_VALUE]

        if len(sycee_list) > send_times:
            for i in range(len(sycee_list) - send_times):
                attachment = get_drop([self.activity_data.package])
                mail = Mail(self.char_id)
                mail.add(
                    self.activity_data.mail_title,
                    self.activity_data.mail_content,
                    attachment=json.dumps(attachment)
                )

                ac_record.add_send(1)
Ejemplo n.º 18
0
    def send_reward_with_custom_price(self, goods_id, price):
        # 这里 price 是新台币,而且不一定是这个goods_id所对应的价格
        # 所以这里按照比例给东西
        p = PURCHASE[goods_id]

        xintaibi = p.rmb * 5

        buy_div, buy_mod = divmod(price, xintaibi)
        for i in xrange(buy_div):
            self.send_reward(goods_id)

        if buy_mod:
            # 换算成对应的元宝
            sycee = buy_mod * 2

            # 任意金额也要双倍!!!
            buy_times = self.buy_times_of_this_goods(goods_id)
            if buy_times == 0:
                actual_sycee = sycee * 2
            else:
                actual_sycee = sycee

            resource = Resource(self.char_id, "Purchase With Custom Price")
            resource.add(purchase_got=sycee, purchase_actual_got=actual_sycee)

            self.mongo_record.times[str(goods_id)] = buy_times + 1
            self.mongo_record.save()
            self.send_notify()

            title = u'充值成功'
            content = u'获得了 {0} 元宝'.format(actual_sycee)
            mail = Mail(self.char_id)
            mail.add(title, content)
Ejemplo n.º 19
0
 def send_mail(self):
     attachment = get_drop([self.activity_data.package])
     mail = Mail(self.char_id)
     mail.add(
         self.activity_data.mail_title,
         self.activity_data.mail_content,
         attachment=json.dumps(attachment)
     )
Ejemplo n.º 20
0
    def trig(self, extra_sycee):
        if not self.is_valid():
            return

        attachment = make_standard_drop_from_template()
        attachment["sycee"] = extra_sycee

        mail = Mail(self.char_id)
        mail.add(self.activity_data.mail_title, self.activity_data.mail_content, attachment=json.dumps(attachment))
Ejemplo n.º 21
0
def get_attachment(request):
    mail_id = request._proto.id
    m = Mail(request._char_id)
    attachment = m.get_attachment(mail_id)

    response = GetAttachmentResponse()
    response.ret = 0
    response.attachment.MergeFrom(standard_drop_to_attachment_protomsg(attachment))
    return pack_msg(response)
Ejemplo n.º 22
0
    def send_first_reward(self):
        standard_drop = get_drop(PURCHASE_FIRST_REWARD_PACKAGE_IDS)

        mail = Mail(self.char_id)
        mail.add(
            MAIL_PURCHASE_FIRST_TITLE,
            MAIL_PURCHASE_FIRST_CONTENT,
            attachment=json.dumps(standard_drop)
        )
Ejemplo n.º 23
0
def _vip_change(char_id, old_vip, new_vip, **kwargs):
    Prison(char_id).vip_changed(new_vip)
    m = Mail(char_id)
    m.add(name=MAIL_VIP_CHANGED_TITLE, content=MAIL_VIP_CHANGED_CONTENT.format(new_vip))

    # 增加掠夺次数
    plunder_times_change_value = VIP_FUNCTION[new_vip].plunder - VIP_FUNCTION[old_vip].plunder
    if plunder_times_change_value:
        plunder = Plunder(char_id)
        plunder.change_current_plunder_times(plunder_times_change_value, allow_overflow=True)
Ejemplo n.º 24
0
def get_attachment(request):
    mail_id = request._proto.id
    m = Mail(request._char_id)
    attachment = m.get_attachment(mail_id)

    response = GetAttachmentResponse()
    response.ret = 0
    response.attachment.MergeFrom(
        standard_drop_to_attachment_protomsg(attachment))
    return pack_msg(response)
Ejemplo n.º 25
0
def send_new_password(pk, password):
    user = User.objects.get(pk=pk)
    context = {'user': user, 'password': password, 'BASE_URL': BASE_URL}
    template = 'mail/password-confirmation.html'

    mail = Mail(title='Смена пароля',
                template=template,
                recipient=user.email,
                context=context)
    mail.send()
Ejemplo n.º 26
0
def generate_verification_mail(pk):
    user = User.objects.get(pk=pk)
    context = {'user': user, 'BASE_URL': BASE_URL}
    template = 'mail/verification.html'
    title = 'Подтверждение регистрации'

    mail = Mail(title=title,
                template=template,
                recipient=user.email,
                context=context)
    mail.send()
Ejemplo n.º 27
0
    def test_open_mail_normal(self):
        m = Mail(self.char_id)
        mid = m.add('xxx', 'yyy', timezone.utc_timestamp())
        self.assertEqual(m.mail.mails[str(mid)].has_read, False)

        self._open(mid)

        m = Mail(self.char_id)
        self.assertEqual(m.count(), 1)
        self.assertEqual(m.mail.mails[str(mid)].has_read, True)

        app_test_helper._mongo_teardown_func()
Ejemplo n.º 28
0
    def trig(self, extra_sycee):
        if not self.is_valid():
            return

        attachment = make_standard_drop_from_template()
        attachment['sycee'] = extra_sycee

        mail = Mail(self.char_id)
        mail.add(
            self.activity_data.mail_title,
            self.activity_data.mail_content,
            attachment=json.dumps(attachment)
        )
Ejemplo n.º 29
0
def login_notify(char_id):
    hero_objs = char_heros_obj(char_id)

    Char(char_id).send_notify()

    hero_notify(char_id, hero_objs)
    Item(char_id).send_notify()

    f = Formation(char_id)
    f.send_socket_notify()
    f.send_formation_notify()

    hang = Hang(char_id)
    hang.send_notify()

    Plunder(char_id).send_notify()

    p = Prison(char_id)
    p.send_prisoners_notify()

    Arena(char_id).send_notify()

    f = Friend(char_id)
    f.send_friends_notify()
    f.send_friends_amount_notify()

    m = Mail(char_id)
    m.send_mail_notify()

    CheckIn(char_id).send_notify()


    stage = Stage(char_id)
    stage.send_already_stage_notify()
    stage.send_new_stage_notify()

    stage_elite = EliteStage(char_id)
    stage_elite.send_notify()
    stage_elite.send_remained_times_notify()

    stage_activity = ActivityStage(char_id)
    stage_activity.send_notify()
    stage_activity.send_remained_times_notify()

    HeroPanel(char_id).send_notify()
    Task(char_id).send_notify()
    Achievement(char_id).send_notify()
    HeroSoul(char_id).send_notify()
    FunctionOpen(char_id).send_notify()
    Levy(char_id).send_notify()
    Attachment(char_id).send_notify()
Ejemplo n.º 30
0
    def someone_refuse_me(self, from_id):
        from_id = int(from_id)
        if from_id in self.mf.pending:
            self.mf.pending.remove(from_id)
        self.mf.save()

        from_char_name = get_char_property(from_id, 'name')

        mail = Mail(self.char_id)
        mail.add(MAIL_FRIEND_REFUSE_TITLE,
                 MAIL_FRIEND_REFUSE_CONTENT.format(from_char_name))

        self.send_remove_friend_notify([from_id])
        self.send_friends_amount_notify()
Ejemplo n.º 31
0
def _send_reward(rank, mongo_union):
    data = _get_reward_by_rank(rank)
    contribute_points = data.pop('union_contribute_points')

    u = Union(mongo_union.owner)
    u.add_contribute_points(contribute_points)

    members = u.member_list

    attachment = json.dumps(data)
    for mid in members:
        m = Mail(mid)
        m.add(MAIL_UNION_BATTLE_REWARD_TITLE,
              MAIL_UNION_BATTLE_REWARD_CONTENT,
              attachment=attachment)
Ejemplo n.º 32
0
    def login_process(self):
        from core.mail import Mail

        if not self.mongo_arena or not self.mongo_arena.beaten_record:
            return

        def _make_content(record):
            if record.old_score > record.new_score:
                template = MAIl_ARENA_BEATEN_LOST_TEMPLATE
                # des = '-{0}'.format(abs(record.old_score - record.new_score))
            else:
                template = MAIl_ARENA_BEATEN_WIN_TEMPLATE
                # des = '+{0}'.format(abs(record.old_score - record.new_score))

            # return template.format(record.name, record.old_score, record.new_score, des)
            return template.format(record.name)

        contents = [_make_content(record) for record in self.mongo_arena.beaten_record[-1:-5:-1]]

        content_header = u'共受到{0}次挑战,积分从{1}变成{2}\n'.format(
            len(self.mongo_arena.beaten_record),
            self.mongo_arena.beaten_record[0].old_score,
            self.mongo_arena.beaten_record[-1].new_score,
        )

        content_body = u'\n'.join(contents)

        content = content_header + content_body
        if len(self.mongo_arena.beaten_record) > 4:
            content += u'\n...'

        Mail(self.char_id).add(MAIL_ARENA_BEATEN_TITLE, content, send_notify=False)

        self.mongo_arena.beaten_record = []
        self.mongo_arena.save()
Ejemplo n.º 33
0
    def trig(self):
        ac_record = ActivityConditionRecord(self.char_id, self.CONDITION_ID, self.activity_time)
        if ac_record.in_send():
            return

        value = self.get_current_value(self.char_id)
        if value < self.CONDITION_VALUE:
            return

        p = BasePurchaseAction(self.char_id)
        p.send_reward_yueka(purchase_notify=False)

        m = Mail(self.char_id)
        m.add("获得月卡", "您的累积充值已经达到了300元宝,获得了活动月卡奖励,300元宝的额外奖励已经放入您的帐号之中,请注意查收。从明天开始,接下来的30天,您将会每天获得100元宝。")

        ac_record.add_send()
Ejemplo n.º 34
0
    def someone_refuse_me(self, from_id):
        from_id = int(from_id)
        if from_id in self.mf.pending:
            self.mf.pending.remove(from_id)
        self.mf.save()

        from_char_name = get_char_property(from_id, 'name')

        mail = Mail(self.char_id)
        mail.add(
            MAIL_FRIEND_REFUSE_TITLE,
            MAIL_FRIEND_REFUSE_CONTENT.format(from_char_name)
        )

        self.send_remove_friend_notify([from_id])
        self.send_friends_amount_notify()
Ejemplo n.º 35
0
def _send_reward(rank, mongo_union):
    data = _get_reward_by_rank(rank)
    contribute_points = data.pop('union_contribute_points')

    u = Union(mongo_union.owner)
    u.add_contribute_points(contribute_points)

    members = u.member_list

    attachment = json.dumps(data)
    for mid in members:
        m = Mail(mid)
        m.add(
            MAIL_UNION_BATTLE_REWARD_TITLE,
            MAIL_UNION_BATTLE_REWARD_CONTENT,
            attachment=attachment
        )
Ejemplo n.º 36
0
def send_mail(args):
    from core.character import get_char_ids_by_last_login
    from core.mail import Mail

    data = json.loads(args['data'])

    name = data['name']
    content = data['content']
    create_at = data['create_at']
    attachment = data['attachment']
    char_ids = data['char_ids']

    if not char_ids:
        char_ids = get_char_ids_by_last_login(limit=14)

    for cid in char_ids:
        m = Mail(cid)
        m.add(name, content, create_at=create_at, attachment=attachment)
Ejemplo n.º 37
0
def send_mail(args):
    from core.character import get_char_ids_by_last_login
    from core.mail import Mail

    data = json.loads(args['data'])

    name = data['name']
    content = data['content']
    create_at = data['create_at']
    attachment = data['attachment']
    char_ids = data['char_ids']

    if not char_ids:
        char_ids = get_char_ids_by_last_login(limit=14)

    for cid in char_ids:
        m = Mail(cid)
        m.add(name, content, create_at=create_at, attachment=attachment)
Ejemplo n.º 38
0
    def trig(self, char_id):
        value = self.get_current_value(char_id)
        passed, not_passed = self.select_conditions(value)

        if not passed:
            return

        passed = self.get_passed_for_send_mail(passed)

        for p in passed:
            ac_record = ActivityConditionRecord(char_id, p, self.activity_time)
            if ac_record.in_send():
                continue

            mail = Mail(char_id)
            mail.add(self.get_mail_title(p), self.get_mail_content(p), attachment=self.get_mail_attachment(p))

            ac_record.add_send()
Ejemplo n.º 39
0
def send_yueka_reward(char_id, sycee, remained_days):
    standard_drop = make_standard_drop_from_template()
    standard_drop['sycee'] = sycee

    content = MAIL_YUEKA_CONTENT_TEMPLATE.format(sycee, remained_days)

    Mail(char_id).add(MAIL_YUEKA_TITLE,
                      content,
                      attachment=json.dumps(standard_drop),
                      only_one=True)
Ejemplo n.º 40
0
    def trig(self, *args):
        if not self.is_valid():
            return

        ac_record = ActivityConditionRecord(self.char_id, self.CONDITION_ID, self.activity_time)
        send_times = ac_record.send_times()

        if send_times > 0:
            return

        attachment = get_drop([self.activity_data.package])
        mail = Mail(self.char_id)
        mail.add(
            self.activity_data.mail_title,
            self.activity_data.mail_content,
            attachment=json.dumps(attachment)
        )

        ac_record.add_send(1)
Ejemplo n.º 41
0
def reset():
    logger = Logger('reset_arena_day.log')

    amount = redis_client.zcard(REDIS_ARENA_KEY)
    logger.write("Reset Arena Day: Start. chars amount: {0}".format(amount))

    arena_scores = redis_client.zrange(REDIS_ARENA_KEY, 0, -1, withscores=True)

    for char_id, score in arena_scores:
        attachment = _get_reward_by_score(score)
        if not attachment:
            continue

        char_id = int(char_id)
        mail = Mail(char_id)
        mail.add(MAIL_ARENA_DAY_REWARD_TITLE, MAIL_ARENA_DAY_REWARD_CONTENT, attachment=attachment)

    logger.write("Reset Arena Day: Complete")
    logger.close()
Ejemplo n.º 42
0
def clean():
    logger = Logger("clean_mail.log")
    logger.write("Clean Mail Start.")

    DIFF = arrow.utcnow().replace(days=-MAIL_KEEP_DAYS)
    mails = MongoMail.objects.all()
    amount = 0
    for m in mails:
        char_mail = Mail(m.id, mailobj=m)
        for k, v in m.mails.items():
            create_at = arrow.get(v.create_at, 'YYYY-MM-DD HH:mm:ss').replace(tzinfo=pytz.utc)
            if create_at < DIFF:
                char_mail.delete(k)
                amount += 1

        if len(char_mail.mail.mails) == 0:
            m.delete()

    logger.write("Clean Mail Complete. Cleaned Amount: {0}".format(amount))
    logger.close()
Ejemplo n.º 43
0
    def trig(self):
        if not self.is_valid():
            return

        now = arrow.utcnow().to(settings.TIME_ZONE)
        now_begin = arrow.Arrow(now.year, now.month, now.day).replace(tzinfo=now.tzinfo)

        condition = (
            Q(char_id=self.char_id) & Q(purchase_at__gte=now_begin.timestamp) & Q(purchase_at__lte=now.timestamp)
        )
        logs = MongoPurchaseLog.objects.filter(condition)
        if logs.count() == 0 or logs.count() > 1:
            # 没有充值,或者充值次数大于1,都返回
            # 只有当天第一次充值的时候,才给额外的东西
            return

        attachment = get_drop([self.activity_data.package])

        mail = Mail(self.char_id)
        mail.add(self.activity_data.mail_title, self.activity_data.mail_content, attachment=json.dumps(attachment))
Ejemplo n.º 44
0
def clean(signum):
    logger = Logger("clean_mail.log")
    logger.write("Start")

    try:
        amount = 0

        mails = MongoMail._get_collection().find({}, {'_id': 1})
        for m in mails:
            char_id = m['_id']

            char_mail = Mail(char_id)
            cleaned = char_mail.delete_expired(MAIL_KEEP_DAYS)
            amount += cleaned
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Clean Mail Complete. Cleaned Amount: {0}".format(amount))
    finally:
        logger.close()
Ejemplo n.º 45
0
def clean(signum):
    logger = Logger("clean_mail.log")
    logger.write("Start")

    try:
        amount = 0

        mails = MongoMail._get_collection().find({}, {'_id': 1})
        for m in mails:
            char_id = m['_id']

            char_mail = Mail(char_id)
            cleaned = char_mail.delete_expired(MAIL_KEEP_DAYS)
            amount += cleaned
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Clean Mail Complete. Cleaned Amount: {0}".format(amount))
    finally:
        logger.close()
Ejemplo n.º 46
0
    def trig(self, *args):
        ac_record = ActivityConditionRecord(self.char_id, self.CONDITION_ID, self.activity_time)
        send_times = ac_record.send_times()

        value = self.get_current_value(self.char_id)
        times, _ = divmod(value, self.CONDITION_VALUE)
        if times <= send_times:
            return

        for i in range(times - send_times):
            p = BasePurchaseAction(self.char_id)
            p.send_reward_yueka(purchase_notify=False, as_vip_exp=False)

            m = Mail(self.char_id)
            m.add(
                "获得月卡",
                "您的累积充值已经达到了300元宝,获得了活动月卡奖励,300元宝的额外奖励已经放入您的帐号之中,请注意查收。从明天开始,接下来的30天,您将会每天获得100元宝。"
            )

        ac_record.add_send(times=times-send_times)
Ejemplo n.º 47
0
    def trig(self, *args):
        ac_record = ActivityConditionRecord(self.char_id, self.CONDITION_ID, self.activity_time)
        send_times = ac_record.send_times()

        if send_times:
            return

        value = self.get_current_value(self.char_id)
        if value < self.CONDITION_VALUE:
            return

        attachment = get_drop([self.activity_data.package])
        mail = Mail(self.char_id)
        mail.add(
            self.activity_data.mail_title,
            self.activity_data.mail_content,
            attachment=json.dumps(attachment)
        )

        ac_record.add_send(1)
Ejemplo n.º 48
0
def clean():
    logger = Logger("clean_mail.log")
    logger.write("Clean Mail Start.")

    DIFF = timezone.now() - datetime.timedelta(days=MAIL_KEEP_DAYS)
    mails = MongoMail.objects.all()
    amount = 0
    for m in mails:
        char_mail = Mail(m.id, mailobj=m)
        for k, v in m.mails.items():
            create_at = datetime.datetime.strptime(v.create_at, FORMAT)
            create_at = create_at.replace(tzinfo=pytz.utc)
            if create_at < DIFF:
                char_mail.delete(k)
                amount += 1

        if len(char_mail.mail.mails) == 0:
            m.delete()

    logger.write("Clean Mail Complete. Cleaned Amount: {0}".format(amount))
    logger.close()
Ejemplo n.º 49
0
def activatecode_use(request):
    char_id = request._char_id
    code_id = request._proto.code_id

    data = {
        'char_id': char_id,
        'code_id': code_id
    }

    try:
        res = api_activatecode_use(data)
    except APIFailure:
        raise SanguoException(
            errormsg.SERVER_FAULT,
            char_id,
            "ActivateCode Use",
            "APIFailure. api_activatecode_use"
        )

    if res['ret'] != 0:
        raise SanguoException(
            res['ret'],
            char_id,
            "ActivateCode use",
            "api_activatecode_use ret = {0}".format(res['ret'])
        )

    # DONE
    package = res['data']['package']
    drop = get_drop_from_raw_package(package)

    mail = Mail(char_id)
    mail.add(
        ACTIVATECODE_MAIL_TITLE,
        ACTIVATECODE_MAIL_CONTENT,
        arrow.utcnow().format('YYYY-MM-DD HH:mm:ss'),
        attachment=json.dumps(drop)
    )

    return None
Ejemplo n.º 50
0
def main(signum):
    logger = Logger('reset_arena_day.log')

    arena_scores = ArenaScoreManager.get_all()
    amount = len(arena_scores)
    logger.write("Reset Arena Day: Start. chars amount: {0}".format(amount))

    try:
        for char_id, score in arena_scores:
            attachment = _get_reward_by_score(score)
            if not attachment:
                continue

            char_id = int(char_id)
            mail = Mail(char_id)
            mail.add(MAIL_ARENA_DAY_REWARD_TITLE, MAIL_ARENA_DAY_REWARD_CONTENT, attachment=attachment)
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Reset Arena Day: Complete")
    finally:
        logger.close()