Exemple #1
0
 def put(self):
     data = request.get_json()
     data['id'] = current_bot.self.puid
     creators = data.pop('creators', [])
     mp_forward = data.pop('mp_forward', [])
     obj = GroupSettings.create(**data)
     if creators:
         obj.creators.clear()
         obj.creators.extend(creators)
         obj.save()
     if mp_forward:
         obj.mp_forward.clear()
         obj.mp_forward.extend(mp_forward)
         obj.save()
     return {}
Exemple #2
0
    def get(self):
        uid = current_bot.self.puid
        query = db.session.query
        user = query(User).get(uid)

        data = {
            'users': [u.to_dict() for u in user.friends],
            'groups': [group.to_dict() for group in user.groups],
            'mps': [mp.to_dict() for mp in user.mps]
        }
        settings = GroupSettings.get(uid)
        data.update(settings.to_dict())
        data['creators'] = list(
            set(u['id'] for u in data['users'])
            & set(str(u, 'u8') for u in data['creators']))
        return data
Exemple #3
0
 def __getattr__(self, item):
     settings = GroupSettings.get(self.uid)
     return getattr(settings, item, None)