replapi-it
Version:
An all-in-one API for replit.com
55 lines (53 loc) • 1.89 kB
JavaScript
const Collection = require('../structures/collection');
const Post = require('../structures/post');
class PostManager {
constructor(client, parent) {
this.
this.cache = new Collection();
this.
if (!this.
}
async fetch() {
let res;
switch(this.
case 'Client':
let [id, options2 = {cache: true}] = [...arguments];
res = await this.
if (!res.post) return null;
let post = new Post(this.
await post.update(res.post);
if (options2.cache) this.cache.set(post.id, post);
return post;
case 'User':
case 'CurrentUser':
let [options = {}] = [...arguments];
options = {cache: true, limit: 10, order: 'new', ...options};
res = await this.
let posts = res.userByUsername.posts.items;
let c = new Collection();
for (let p of posts) {
let post = new Post(this.
await post.update(p);
if (options.cache) this.cache.set(post.id, post);
c.set(post.id, post);
}
return c;
}
}
async trending(options = {}) {
options = {cache: true, limit: 10, tags: [], ...options};
let res = await this.
let posts = res.replPosts.items;
let c = new Collection();
for (let p of posts) {
let post = new Post(this.
await post.update(p);
if (options.cache) this.cache.set(post.id, post);
c.set(post.id, post);
}
return c;
}
}
module.exports = PostManager;