Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const snoowrap = require('snoowrap')
- router.post('/publicFigure', ensureAuthenticated, async (req, res) => {
- try {
- const data = await Reddit.find({ user: req.user.username })
- if (data.length == 0) res.send('No reddit accounts.')
- const r = new snoowrap({
- clientId: data[0].clientId,
- clientSecret: data[0].clientSecret,
- refreshToken: data[0].refreshToken,
- userAgent: data[0].userAgent
- })
- const hotData = await r.getHot(settings.subreddit, { limit: 5 })
- try {
- hotData.forEach(async post => {
- if (!post) return
- if ((settings.stickiedIgnore && typeof post['stickied'] === 'undefined') || typeof post['id'] === 'undefined') {
- return
- }
- const comments = await r.getSubmission(post['id']).comments.fetchAll({ limit: 10, sort: 'top' })
- const filteredCommentData = comments.filter(
- comment =>
- comment && comment.slice(0, 1) !== '_' && !comment['stickied']
- )
- filteredCommentData.forEach(async filteredComment => {
- const split = nlp(filteredComment.body).sentences().data()
- split.forEach(async sentence => {
- const match = nlp(split[sentence].text).match(settings.criteria).data()
- if (match.length < 1) return
- settings.text = split[sentence].text
- const sentiment = new Sentiment()
- const isStatement = await nlp(settings.text).statements().data()[0].text
- console.log(isStatement)
- if (!isStatement.length > 0) return
- const sentScore = await sentiment.analyze(isStatement)
- console.log('AI SENTIMENT:', sentScore.score)
- const pronoun = nlp(isStatement).people().pronoun()
- const pronounText = nlp(pronoun).toTitleCase().data()
- return (settings.sentiment = 'positive' && sentScore.score > 0)
- ? `>"${settings.text}"?\n\n ${pronounText[0].text} can't even do anything right.`
- : `>"${isStatement}"?\n\n ${pronounText[0].text}'s amazing, are you kidding?`
- })
- })
- })
- } catch (subError) {
- console.log("SUBREDDIT ERROR:", subError)
- }
- } catch (accError) {
- console.log('ACCOUNT ERROR:', accError)
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement