Example #1
0
    def find_applied_clubs(cls, server_id):
        docs = MongoChampionship.db(server_id).find({'applied': True},
                                                    {'_id': 1})

        club_ids = [doc['_id'] for doc in docs]
        club_ids = set(club_ids)

        vip_ids = VIP.query_char_ids(server_id, min_level=AUTO_APPLY_VIP_LEVEL)

        if vip_ids:
            club_docs = MongoCharacter.db(server_id).find(
                {'_id': {
                    '$in': vip_ids
                }}, {'level': 1})

            for doc in club_docs:
                if doc['level'] >= APPLY_CLUB_LEVEL_LIMIT:
                    club_ids.add(doc['_id'])

        return list(club_ids)
Example #2
0
    def _send_to_one_server(sid, m, attachment):
        if m.has_condition():
            club_level = m.condition_club_level
            vip_level = m.condition_vip_level

            if m.condition_login_at_1:
                login_range = [
                    arrow.get(m.condition_login_at_1).timestamp,
                    arrow.get(m.condition_login_at_2).timestamp,
                ]
            else:
                login_range = None

            exclude_char_ids = m.get_parsed_condition_exclude_chars()

            result_list = []
            if club_level or login_range:
                result_list.append(Club.query_char_ids(sid, min_level=club_level, login_range=login_range))

            if vip_level:
                result_list.append(VIP.query_char_ids(sid, vip_level))

            if not result_list:
                return

            result = set(result_list[0])
            for i in range(1, len(result_list)):
                result &= set(result_list[i])

            result -= set(exclude_char_ids)

            to_char_ids = list(result)
            if not to_char_ids:
                return
        else:
            to_char_ids = ModelCharacter.objects.filter(server_id=sid).values_list('id', flat=True)
            to_char_ids = list(to_char_ids)

        SharedMail(sid).add(to_char_ids, m.title, m.content, attachment=attachment)