diff options
Diffstat (limited to 'src/models/MemePoster.ts')
| -rw-r--r-- | src/models/MemePoster.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/models/MemePoster.ts b/src/models/MemePoster.ts new file mode 100644 index 0000000..27ff726 --- /dev/null +++ b/src/models/MemePoster.ts @@ -0,0 +1,39 @@ +// const { POSTER_ID, POSTER_TOKEN, POSTER_TIME } = process.env; +// import request from 'node-superfetch'; +// import { embedURL } from '../utils/Util.js'; +// import subreddits from '../assets/json/meme.json' +// const types = ['image', 'rich:video']; + +// module.exports = class MemePoster { +// constructor(client) { +// Object.defineProperty(this, 'client', { value: client }); + +// this.id = POSTER_ID; +// this.token = POSTER_TOKEN; +// this.time = Number.parseFloat(POSTER_TIME) || 3.6e+6; +// } +// async post() { +// try { +// const subreddit = subreddits[Math.floor(Math.random() * subreddits.length)]; +// const post = await this.fetchMeme(subreddit); +// if (!post) return; +// const url = embedURL(post.title, `<https://www.reddit.com${post.permalink}>`); +// await request +// .post(`https://discordapp.com/api/webhooks/${this.id}/${this.token}`) +// .send({ content: `**r/${subreddit}** ${url}\n${post.url}` }); +// } catch (err) { +// this.client.logger.error(err); +// } +// } +// async fetchMeme(subreddit) { +// const { body } = await request +// .get(`https://www.reddit.com/r/${subreddit}/hot.json`) +// .query({ limit: 100 }); +// const posts = body.data.children.filter(post => { +// if (!post.data) return false; +// return types.includes(post.data.post_hint) && post.data.url && post.data.title && !post.data.over_18; +// }); +// if (!posts.length) return null; +// return posts[Math.floor(Math.random() * posts.length)].data; +// } +// };
\ No newline at end of file |