Skip to content

Instantly share code, notes, and snippets.

@xreiju
Last active May 5, 2021 12:21
Show Gist options
  • Save xreiju/f1725fd3bf62bc89cc506c4a6cc1b9ef to your computer and use it in GitHub Desktop.
Save xreiju/f1725fd3bf62bc89cc506c4a6cc1b9ef to your computer and use it in GitHub Desktop.
Show the reactions for the specified noteId #misskey
// Requirement: node-fetch
// How it works:
// $ node misskey_reaction.js xxxxxxxxxxxxxxxxx(noteId)
// $ node misskey_reaction.js https://${host}/notes/xxxxxxxxxxxx(noteId)
// You need to put your token here to get it working.
const i = '!YOUPUTYOURTOKENHERETOGETTHISPROGRAMTOWORK'
//
const fetch = require('node-fetch')
const moment = require('moment')
const host = 'https://misskey.xyz'
const APIURL = `${host}/api`
let reactionCount = {}
let reactionBy = {}
function getAPIURL(endpoint) {
return `${APIURL}/${endpoint}`
}
let debug = false
async function main() {
if(process.argv[3] === 'DEBUG') debug = true
const regexres = process.argv[2].match(/\/notes\/(.+)/)
var noteId
// console.log(regexres)
if(regexres) {
noteId = regexres[1]
} else noteId = process.argv[2]
const body = {
i: i,
noteId: noteId,
limit: 100
}
let reactionres = await fetch(getAPIURL('notes/reactions'), {
method: 'POST',
body: JSON.stringify(body)
})
let reactionjson = await reactionres.json()
let postres = await fetch(getAPIURL('notes/show'), {
method: 'POST',
body: JSON.stringify({
noteId: noteId
})
})
let postjson = await postres.json()
if(debug) console.log(postjson)
console.log(`Post by ${postjson.user.name}(@${postjson.user.username})`)
console.log(`Posted at ${moment(postjson.createdAt)}`)
console.log(`Content:\n${postjson.text}`)
var countSum = 0
reactionjson.forEach(elem => {
if(!reactionCount[elem.reaction]) reactionCount[elem.reaction] = 0
reactionCount[elem.reaction]++;
if(!reactionBy[elem.reaction]) reactionBy[elem.reaction] = []
reactionBy[elem.reaction].push(`${elem.user.name}(@${elem.user.username})`)
})
Object.keys(reactionCount).forEach(elem => {
if(reactionCount[elem] != 0) {
countSum += reactionCount[elem]
console.log(`${elem}: ${reactionCount[elem]} by ${reactionBy[elem]}`)
}
})
if(countSum) console.log(`${countSum} reactions`)
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment