Follow users in whole network instance of pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. 'use strict'
  2. const requestsync = require('sync-request'),
  3. user = process.argv[2] || 'user',
  4. pass = process.argv[3] || 'pass',
  5. site = process.argv[4] || 'https://social.hatthieves.es',
  6. url = site.split('://')[0] + '://' + user + ':' + pass + '@' + site.split('://')[1]
  7. try {
  8. let actors,
  9. followed = [],
  10. count = 100,
  11. account = JSON.parse(requestsync('GET', url + '/api/v1/accounts/' + user).getBody()).id
  12. do {
  13. let id = actors && actors.length > 0 ? actors[actors.length - 1].id : '',
  14. body = requestsync('GET', url + '/api/v1/accounts/' + account + '/following?max_id=' + id + '&limit=' + count)
  15. try {
  16. actors = JSON.parse(body.getBody())
  17. if (actors && actors.length > 0) {
  18. for (let a of actors) {
  19. if (a && a.id && !followed.some(f => f === a.id)) {
  20. followed.push(a.id)
  21. }
  22. }
  23. }
  24. } catch (e) {
  25. console.log(e)
  26. }
  27. console.log('Loading users: ' + followed.length)
  28. } while (actors && actors.length >= count)
  29. actors = []
  30. do {
  31. let id = actors && actors.length > 0 ? actors[actors.length - 1].id : '',
  32. body = requestsync('GET', url + '/api/statuses/networkpublic_timeline?max_id=' + id + '&only_media=false&count=20&with_muted=true')
  33. try {
  34. actors = JSON.parse(body.getBody())
  35. if (actors && actors.length > 0) {
  36. for (let a of actors) {
  37. if (a && a.user && a.user.id && !followed.some(f => f === a.user.id)) {
  38. requestsync('POST', url + '/api/v1/accounts/' + a.user.id + '/follow')
  39. if (a.in_reply_to_user_id && !followed.some(f => f === a.in_reply_to_user_id)) {
  40. requestsync('POST', url + '/api/v1/accounts/' + a.in_reply_to_user_id + '/follow')
  41. followed.push(a.in_reply_to_user_id)
  42. console.log('Following: ' + a.in_reply_to_user_id)
  43. }
  44. followed.push(a.user.id)
  45. console.log('Following: ' + a.user.screen_name)
  46. }
  47. }
  48. }
  49. } catch (e) {
  50. console.log(e)
  51. }
  52. console.log('Following: ' + followed.length + ' accounts')
  53. } while (actors && actors.length >= 20)
  54. } catch (e) {
  55. console.log(e)
  56. }