예제 #1
0
    def __new__(cls, char_id, union_id=None):
        mongo_member = MongoUnionMember._get_collection().find_one(
                {'_id': char_id},
                {'joined': 1}
        )
        if not mongo_member:
            return UnionDummy(char_id)

        char_union_id = mongo_member['joined']
        if not char_union_id and not union_id:
            return UnionDummy(char_id)

        if not union_id:
            union_id = char_union_id

        # FIXME 本来是有这个判断的,但是目前为了省事,对于这个最后返回的是 UnionMember
        # 其实应该为这个添加一个新类: UnionObserver
        # 表示自己加入了一个工会,但是要查看其他工会的信息
        # if char_union_id != union_id:
        #     return UnionDummy(char_id)

        mongo_union = MongoUnion._get_collection().find_one(
                {'_id': union_id},
                {'owner': 1}
        )

        if char_id == mongo_union['owner']:
            return UnionOwner(char_id, union_id)
        return UnionMember(char_id, union_id)
예제 #2
0
    def cron_job():
        condition = {"$or": [
            {"checkin_times": {"$gt": 0}},
            {"boss_times": {"$gt": 0}}
        ]}

        updater = {
            'checkin_times': 0,
            'boss_times': 0
        }

        members = MongoUnionMember._get_collection().find(condition, {'_id': 1})
        MongoUnionMember._get_collection().update({}, {'$set': updater}, multi=True)

        for m in members:
            Member(m['_id']).send_personal_notify()
예제 #3
0
    def __new__(cls, char_id, union_id=None):
        mongo_member = MongoUnionMember._get_collection().find_one(
            {'_id': char_id}, {'joined': 1})
        if not mongo_member:
            return UnionDummy(char_id)

        char_union_id = mongo_member['joined']
        if not char_union_id and not union_id:
            return UnionDummy(char_id)

        if not union_id:
            union_id = char_union_id

        # FIXME 本来是有这个判断的,但是目前为了省事,对于这个最后返回的是 UnionMember
        # 其实应该为这个添加一个新类: UnionObserver
        # 表示自己加入了一个工会,但是要查看其他工会的信息
        # if char_union_id != union_id:
        #     return UnionDummy(char_id)

        mongo_union = MongoUnion._get_collection().find_one({'_id': union_id},
                                                            {'owner': 1})

        if char_id == mongo_union['owner']:
            return UnionOwner(char_id, union_id)
        return UnionMember(char_id, union_id)
예제 #4
0
    def cron_job():
        condition = {
            "$or": [{
                "checkin_times": {
                    "$gt": 0
                }
            }, {
                "boss_times": {
                    "$gt": 0
                }
            }]
        }

        updater = {'checkin_times': 0, 'boss_times': 0}

        members = MongoUnionMember._get_collection().find(
            condition, {'_id': 1})
        MongoUnionMember._get_collection().update({}, {'$set': updater},
                                                  multi=True)

        for m in members:
            Member(m['_id']).send_personal_notify()
예제 #5
0
    def get_battle_members(self):
        # 获取可参加工会战的会员
        now = arrow.utcnow().timestamp
        hours24 = 24 * 3600
        checkin_limit = now - hours24

        condition = {
            '$and': [
                {'joined': self.union_id},
                {'last_checkin_timestamp': {'$gte': checkin_limit}}
            ]
        }
        docs = MongoUnionMember._get_collection().find(condition, {'_id': 1})
        return [doc['_id'] for doc in docs]
예제 #6
0
    def get_battle_members(self):
        # 获取可参加工会战的会员
        now = arrow.utcnow().timestamp
        hours24 = 24 * 3600
        checkin_limit = now - hours24

        condition = {
            '$and': [{
                'joined': self.union_id
            }, {
                'last_checkin_timestamp': {
                    '$gte': checkin_limit
                }
            }]
        }
        docs = MongoUnionMember._get_collection().find(condition, {'_id': 1})
        return [doc['_id'] for doc in docs]
예제 #7
0
    def cronjob_auto_transfer_union(cls):
        transfer_dict = {}

        now = arrow.utcnow()
        local_date = now.to(settings.TIME_ZONE).date()
        timestamp = now.timestamp - 3600 * 24 * 3

        unions = MongoUnion._get_collection().find({}, {'owner': 1})
        owner_union_id_dict = {doc['owner']: doc['_id'] for doc in unions}

        conditions = {
            '$and': [{
                '_id': {
                    '$in': owner_union_id_dict.keys()
                }
            }, {
                'last_checkin_timestamp': {
                    '$lte': timestamp
                }
            }]
        }

        member_docs = MongoUnionMember._get_collection().find(
            conditions, {'last_checkin_timestamp': 1})

        for doc in member_docs:
            char_id = doc['_id']
            union_id = owner_union_id_dict[char_id]

            last_checkin_date = arrow.get(doc['last_checkin_timestamp']).to(
                settings.TIME_ZONE).date()
            days = (local_date - last_checkin_date).days
            # 昨天签到了,今天检测的时候, days 就是1
            # 但是从逻辑上看,应该是连续签到的,
            # 前天签到,昨天没有,今天检测的时候,days是2
            # 逻辑看来是已经 一天 没有签到了
            # 所以 days 在这里 -1
            days -= 1

            if days < 3:
                continue

            u = Union(char_id, union_id)
            if days >= 7:
                # transfer
                next_owner = u.find_next_owner()

                transfer_dict[union_id] = (char_id, next_owner)
                if next_owner:
                    u.transfer(next_owner)

                    m = Mail(char_id)
                    m.add(
                        MAIL_UNION_OWNER_TRANSFER_DONE_TITLE,
                        MAIL_UNION_OWNER_TRANSFER_DONE_CONTENT.format(
                            get_char_property(char_id, 'name')))
            else:
                members = u.member_list
                for mid in members:
                    m = Mail(mid)
                    m.add(
                        MAIL_UNION_OWNER_TRANSFER_NOTIFY_TITLE,
                        MAIL_UNION_OWNER_TRANSFER_NOTIFY_CONTENT.format(days))

        return transfer_dict
예제 #8
0
 def member_list(self):
     # 成员ID列表
     members = MongoUnionMember._get_collection().find(
         {'joined': self.union_id}, {'_id': 1})
     return [i['_id'] for i in members]
예제 #9
0
 def applied_list(self):
     # 申请者ID列表
     members = MongoUnionMember._get_collection().find(
         {'applied': self.union_id}, {'_id': 1})
     return [i['_id'] for i in members]
예제 #10
0
    def cronjob_auto_transfer_union(cls):
        transfer_dict = {}

        now = arrow.utcnow()
        local_date = now.to(settings.TIME_ZONE).date()
        timestamp = now.timestamp - 3600 * 24 * 3

        unions = MongoUnion._get_collection().find({}, {'owner': 1})
        owner_union_id_dict = {doc['owner']: doc['_id'] for doc in unions}

        conditions = {
            '$and': [
                {'_id': {'$in': owner_union_id_dict.keys()}},
                {'last_checkin_timestamp': {'$lte': timestamp}}
            ]
        }

        member_docs = MongoUnionMember._get_collection().find(
                conditions,
                {'last_checkin_timestamp':1}
        )

        for doc in member_docs:
            char_id = doc['_id']
            union_id = owner_union_id_dict[char_id]

            last_checkin_date = arrow.get(doc['last_checkin_timestamp']).to(settings.TIME_ZONE).date()
            days = (local_date - last_checkin_date).days
            # 昨天签到了,今天检测的时候, days 就是1
            # 但是从逻辑上看,应该是连续签到的,
            # 前天签到,昨天没有,今天检测的时候,days是2
            # 逻辑看来是已经 一天 没有签到了
            # 所以 days 在这里 -1
            days -= 1

            if days < 3:
                continue

            u = Union(char_id, union_id)
            if days >= 7:
                # transfer
                next_owner = u.find_next_owner()

                transfer_dict[union_id] = (char_id, next_owner)
                if next_owner:
                    u.transfer(next_owner)

                    m = Mail(char_id)
                    m.add(
                        MAIL_UNION_OWNER_TRANSFER_DONE_TITLE,
                        MAIL_UNION_OWNER_TRANSFER_DONE_CONTENT.format(get_char_property(char_id, 'name'))
                    )
            else:
                members = u.member_list
                for mid in members:
                    m = Mail(mid)
                    m.add(
                        MAIL_UNION_OWNER_TRANSFER_NOTIFY_TITLE,
                        MAIL_UNION_OWNER_TRANSFER_NOTIFY_CONTENT.format(days)
                    )

        return transfer_dict
예제 #11
0
 def member_list(self):
     # 成员ID列表
     members = MongoUnionMember._get_collection().find({'joined': self.union_id}, {'_id': 1})
     return [i['_id'] for i in members]
예제 #12
0
 def applied_list(self):
     # 申请者ID列表
     members = MongoUnionMember._get_collection().find({'applied': self.union_id}, {'_id': 1})
     return [i['_id'] for i in members]