add fan page notify, add twitch route, todo: twitch webhook reg
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
const request = require('request')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
/**
|
||||
* @typedef lastPost
|
||||
* @prop {string} txt post body
|
||||
* @prop {string} id post id
|
||||
* @prop {string} link post link
|
||||
* @prop {string} time timestamp
|
||||
*/
|
||||
/**
|
||||
* get facebook fan page last post
|
||||
* @param {string} pageid facebook fan page id
|
||||
* @return {Promise<lastPost>}
|
||||
*/
|
||||
const getLastPost = async (pageid = '') => {
|
||||
if (typeof pageid !== 'string' || pageid.trim().length === 0) return null
|
||||
pageid = pageid.trim()
|
||||
@@ -38,10 +50,23 @@ const getLastPost = async (pageid = '') => {
|
||||
let timeEl = t('abbr')
|
||||
let time = timeEl.attr('data-utime')
|
||||
let link = timeEl.parent().attr('href')
|
||||
let p = t('div.userContent div.text_exposed_root')
|
||||
let txt = p.text()
|
||||
let id = p.attr('id')
|
||||
if (!time || !link || !txt || !id) return
|
||||
let p = t('div.userContent')
|
||||
let txt = p.first().text()
|
||||
let id = p.first().attr('id')
|
||||
if (!id) {
|
||||
if (/[\?|&]id\=(\d+)/.test(link)) { // eslint-disable-line
|
||||
let m = link.match(/[\?|&]story_fbid\=(\d+)/) // eslint-disable-line
|
||||
if (m !== null && m.length > 1) {
|
||||
id = m[1]
|
||||
}
|
||||
} else if (/\/posts\/(\d+)/.test(link)) {
|
||||
let m = link.match(/\/posts\/(\d+)/)
|
||||
if (m !== null && m.length > 1) {
|
||||
id = m[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!time || !link || !txt || !id) return null
|
||||
let tmp = {
|
||||
txt,
|
||||
id,
|
||||
@@ -49,9 +74,11 @@ const getLastPost = async (pageid = '') => {
|
||||
time
|
||||
}
|
||||
posts.push(tmp)
|
||||
el = null
|
||||
t = null
|
||||
})
|
||||
|
||||
if (posts.length === 0) return
|
||||
$ = null
|
||||
if (posts.length === 0) return null
|
||||
posts.sort((a, b) => {
|
||||
return b.time - a.time
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user