Advertisement
Guest User

Untitled

a guest
May 26th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const snoowrap = require('snoowrap')
  2.  
  3. router.post('/publicFigure', ensureAuthenticated, async (req, res) => {
  4.   try {
  5.     const data = await Reddit.find({ user: req.user.username })
  6.  
  7.     if (data.length == 0) res.send('No reddit accounts.')
  8.  
  9.     const r = new snoowrap({
  10.       clientId: data[0].clientId,
  11.       clientSecret: data[0].clientSecret,
  12.       refreshToken: data[0].refreshToken,
  13.       userAgent: data[0].userAgent
  14.     })
  15.  
  16.     const hotData = await r.getHot(settings.subreddit, { limit: 5 })
  17.  
  18.     try {
  19.       hotData.forEach(async post => {
  20.         if (!post) return
  21.         if ((settings.stickiedIgnore && typeof post['stickied'] === 'undefined') || typeof post['id'] === 'undefined') {
  22.           return
  23.         }
  24.  
  25.         const comments = await r.getSubmission(post['id']).comments.fetchAll({ limit: 10, sort: 'top' })
  26.  
  27.         const filteredCommentData = comments.filter(
  28.           comment =>
  29.             comment && comment.slice(0, 1) !== '_' && !comment['stickied']
  30.         )
  31.  
  32.         filteredCommentData.forEach(async filteredComment => {
  33.           const split = nlp(filteredComment.body).sentences().data()
  34.  
  35.           split.forEach(async sentence => {
  36.             const match = nlp(split[sentence].text).match(settings.criteria).data()
  37.  
  38.             if (match.length < 1) return
  39.             settings.text = split[sentence].text
  40.  
  41.             const sentiment = new Sentiment()
  42.  
  43.             const isStatement = await nlp(settings.text).statements().data()[0].text
  44.  
  45.             console.log(isStatement)
  46.  
  47.             if (!isStatement.length > 0) return
  48.  
  49.             const sentScore = await sentiment.analyze(isStatement)
  50.             console.log('AI SENTIMENT:', sentScore.score)
  51.  
  52.             const pronoun = nlp(isStatement).people().pronoun()
  53.  
  54.             const pronounText = nlp(pronoun).toTitleCase().data()
  55.  
  56.             return (settings.sentiment = 'positive' && sentScore.score > 0)
  57.               ? `>"${settings.text}"?\n\n ${pronounText[0].text} can't even do anything right.`
  58.              : `>"${isStatement}"?\n\n ${pronounText[0].text}'s amazing, are you kidding?`
  59.           })
  60.         })
  61.       })
  62.     } catch (subError) {
  63.       console.log("SUBREDDIT ERROR:", subError)
  64.     }
  65.   } catch (accError) {
  66.     console.log('ACCOUNT ERROR:', accError)
  67.   }
  68. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement